1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-03 04:48:52 -05:00

feat(lsp): include source in auto import completion label (#20523)

This commit is contained in:
Nayeem Rahman 2023-09-16 15:51:35 +01:00 committed by GitHub
parent 430b63c2c4
commit d13e6e6db8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 0 deletions

View file

@ -2440,6 +2440,7 @@ impl Inner {
&self.config.workspace_settings().suggest, &self.config.workspace_settings().suggest,
&specifier, &specifier,
position, position,
self,
); );
Some(results) Some(results)
} else { } else {

View file

@ -2603,6 +2603,7 @@ impl CompletionInfo {
settings: &config::CompletionSettings, settings: &config::CompletionSettings,
specifier: &ModuleSpecifier, specifier: &ModuleSpecifier,
position: u32, position: u32,
language_server: &language_server::Inner,
) -> lsp::CompletionResponse { ) -> lsp::CompletionResponse {
let items = self let items = self
.entries .entries
@ -2614,6 +2615,7 @@ impl CompletionInfo {
settings, settings,
specifier, specifier,
position, position,
language_server,
) )
}) })
.collect(); .collect();
@ -2808,8 +2810,10 @@ impl CompletionEntry {
settings: &config::CompletionSettings, settings: &config::CompletionSettings,
specifier: &ModuleSpecifier, specifier: &ModuleSpecifier,
position: u32, position: u32,
language_server: &language_server::Inner,
) -> lsp::CompletionItem { ) -> lsp::CompletionItem {
let mut label = self.name.clone(); let mut label = self.name.clone();
let mut label_details: Option<lsp::CompletionItemLabelDetails> = None;
let mut kind: Option<lsp::CompletionItemKind> = let mut kind: Option<lsp::CompletionItemKind> =
Some(self.kind.clone().into()); 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::<CompletionEntryDataImport>(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 = let text_edit =
if let (Some(text_span), Some(new_text)) = (range, &insert_text) { if let (Some(text_span), Some(new_text)) = (range, &insert_text) {
let range = text_span.to_range(line_index); let range = text_span.to_range(line_index);
@ -2889,6 +2917,7 @@ impl CompletionEntry {
lsp::CompletionItem { lsp::CompletionItem {
label, label,
label_details,
kind, kind,
sort_text, sort_text,
preselect, preselect,

View file

@ -5212,6 +5212,9 @@ fn lsp_completions_auto_import() {
let req = json!({ let req = json!({
"label": "foo", "label": "foo",
"labelDetails": {
"description": "./b.ts",
},
"kind": 6, "kind": 6,
"sortText": "￿16", "sortText": "￿16",
"commitCharacters": [ "commitCharacters": [
@ -5243,6 +5246,9 @@ fn lsp_completions_auto_import() {
res, res,
json!({ json!({
"label": "foo", "label": "foo",
"labelDetails": {
"description": "./b.ts",
},
"kind": 6, "kind": 6,
"detail": "const foo: \"foo\"", "detail": "const foo: \"foo\"",
"documentation": { "documentation": {
@ -5323,6 +5329,9 @@ fn lsp_npm_completions_auto_import_and_quick_fix_no_import_map() {
res, res,
json!({ json!({
"label": "getClient", "label": "getClient",
"labelDetails": {
"description": "npm:@denotest/types-exports-subpaths@1/client",
},
"kind": 3, "kind": 3,
"detail": "function getClient(): 5", "detail": "function getClient(): 5",
"documentation": { "documentation": {
@ -5435,6 +5444,9 @@ fn lsp_npm_completions_auto_import_and_quick_fix_no_import_map() {
res, res,
json!({ json!({
"label": "chalk", "label": "chalk",
"labelDetails": {
"description": "npm:chalk@5.0",
},
"kind": 6, "kind": 6,
"sortText": "￿16", "sortText": "￿16",
"additionalTextEdits": [ "additionalTextEdits": [
@ -5635,6 +5647,9 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() {
res, res,
json!({ json!({
"label": "getClient", "label": "getClient",
"labelDetails": {
"description": "types-exports-subpaths/client",
},
"kind": 3, "kind": 3,
"detail": "function getClient(): 5", "detail": "function getClient(): 5",
"documentation": { "documentation": {
@ -5747,6 +5762,9 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() {
res, res,
json!({ json!({
"label": "chalk", "label": "chalk",
"labelDetails": {
"description": "chalk",
},
"kind": 6, "kind": 6,
"sortText": "￿16", "sortText": "￿16",
"additionalTextEdits": [ "additionalTextEdits": [
@ -5854,6 +5872,9 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() {
res, res,
json!({ json!({
"label": "printHello", "label": "printHello",
"labelDetails": {
"description": "print_hello",
},
"kind": 3, "kind": 3,
"sortText": "￿16", "sortText": "￿16",
"additionalTextEdits": [ "additionalTextEdits": [