diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 385de0ba1a..df5552764f 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -2440,6 +2440,7 @@ impl Inner { &self.config.workspace_settings().suggest, &specifier, position, + self, ); Some(results) } else { diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index 278a1b5d3b..7442f8a1eb 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -2603,6 +2603,7 @@ impl CompletionInfo { settings: &config::CompletionSettings, specifier: &ModuleSpecifier, position: u32, + language_server: &language_server::Inner, ) -> lsp::CompletionResponse { let items = self .entries @@ -2614,6 +2615,7 @@ impl CompletionInfo { settings, specifier, position, + language_server, ) }) .collect(); @@ -2808,8 +2810,10 @@ impl CompletionEntry { settings: &config::CompletionSettings, specifier: &ModuleSpecifier, position: u32, + language_server: &language_server::Inner, ) -> lsp::CompletionItem { let mut label = self.name.clone(); + let mut label_details: Option = None; let mut kind: Option = Some(self.kind.clone().into()); @@ -2865,6 +2869,30 @@ impl CompletionEntry { } } + if let Some(source) = &self.source { + let mut source = source.clone(); + if let Some(data) = &self.data { + if let Ok(import_data) = + serde_json::from_value::(data.clone()) + { + if let Ok(import_specifier) = + normalize_specifier(import_data.file_name) + { + if let Some(new_module_specifier) = language_server + .get_ts_response_import_mapper() + .check_specifier(&import_specifier, specifier) + .or_else(|| relative_specifier(specifier, &import_specifier)) + { + source = new_module_specifier; + } + } + } + } + label_details + .get_or_insert_with(Default::default) + .description = Some(source); + } + let text_edit = if let (Some(text_span), Some(new_text)) = (range, &insert_text) { let range = text_span.to_range(line_index); @@ -2889,6 +2917,7 @@ impl CompletionEntry { lsp::CompletionItem { label, + label_details, kind, sort_text, preselect, diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs index 6363a08f63..f95e94182a 100644 --- a/cli/tests/integration/lsp_tests.rs +++ b/cli/tests/integration/lsp_tests.rs @@ -5212,6 +5212,9 @@ fn lsp_completions_auto_import() { let req = json!({ "label": "foo", + "labelDetails": { + "description": "./b.ts", + }, "kind": 6, "sortText": "￿16", "commitCharacters": [ @@ -5243,6 +5246,9 @@ fn lsp_completions_auto_import() { res, json!({ "label": "foo", + "labelDetails": { + "description": "./b.ts", + }, "kind": 6, "detail": "const foo: \"foo\"", "documentation": { @@ -5323,6 +5329,9 @@ fn lsp_npm_completions_auto_import_and_quick_fix_no_import_map() { res, json!({ "label": "getClient", + "labelDetails": { + "description": "npm:@denotest/types-exports-subpaths@1/client", + }, "kind": 3, "detail": "function getClient(): 5", "documentation": { @@ -5435,6 +5444,9 @@ fn lsp_npm_completions_auto_import_and_quick_fix_no_import_map() { res, json!({ "label": "chalk", + "labelDetails": { + "description": "npm:chalk@5.0", + }, "kind": 6, "sortText": "￿16", "additionalTextEdits": [ @@ -5635,6 +5647,9 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { res, json!({ "label": "getClient", + "labelDetails": { + "description": "types-exports-subpaths/client", + }, "kind": 3, "detail": "function getClient(): 5", "documentation": { @@ -5747,6 +5762,9 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { res, json!({ "label": "chalk", + "labelDetails": { + "description": "chalk", + }, "kind": 6, "sortText": "￿16", "additionalTextEdits": [ @@ -5854,6 +5872,9 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { res, json!({ "label": "printHello", + "labelDetails": { + "description": "print_hello", + }, "kind": 3, "sortText": "￿16", "additionalTextEdits": [