1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -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,
&specifier,
position,
self,
);
Some(results)
} else {

View file

@ -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<lsp::CompletionItemLabelDetails> = None;
let mut kind: Option<lsp::CompletionItemKind> =
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 =
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,

View file

@ -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": [