mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 00:29:09 -05:00
fix(lsp): prefer local auto-import specifiers (#20539)
Give auto-import completion entries a sort-text suffix depending on if the specifier parses as a URL. This will favour relative and bare (likely import-mapped) specifiers.
This commit is contained in:
parent
d72f5d573a
commit
f7ba701304
2 changed files with 18 additions and 11 deletions
|
@ -2817,10 +2817,10 @@ impl CompletionEntry {
|
||||||
let mut kind: Option<lsp::CompletionItemKind> =
|
let mut kind: Option<lsp::CompletionItemKind> =
|
||||||
Some(self.kind.clone().into());
|
Some(self.kind.clone().into());
|
||||||
|
|
||||||
let sort_text = if self.source.is_some() {
|
let mut sort_text = if self.source.is_some() {
|
||||||
Some(format!("\u{ffff}{}", self.sort_text))
|
format!("\u{ffff}{}", self.sort_text)
|
||||||
} else {
|
} else {
|
||||||
Some(self.sort_text.clone())
|
self.sort_text.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
let preselect = self.is_recommended;
|
let preselect = self.is_recommended;
|
||||||
|
@ -2888,6 +2888,13 @@ impl CompletionEntry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// We want relative or bare (import-mapped or otherwise) specifiers to
|
||||||
|
// appear at the top.
|
||||||
|
if resolve_url(&source).is_err() {
|
||||||
|
sort_text += "_0";
|
||||||
|
} else {
|
||||||
|
sort_text += "_1";
|
||||||
|
}
|
||||||
label_details
|
label_details
|
||||||
.get_or_insert_with(Default::default)
|
.get_or_insert_with(Default::default)
|
||||||
.description = Some(source);
|
.description = Some(source);
|
||||||
|
@ -2919,7 +2926,7 @@ impl CompletionEntry {
|
||||||
label,
|
label,
|
||||||
label_details,
|
label_details,
|
||||||
kind,
|
kind,
|
||||||
sort_text,
|
sort_text: Some(sort_text),
|
||||||
preselect,
|
preselect,
|
||||||
text_edit,
|
text_edit,
|
||||||
filter_text,
|
filter_text,
|
||||||
|
|
|
@ -5308,7 +5308,7 @@ fn lsp_completions_auto_import() {
|
||||||
"description": "./b.ts",
|
"description": "./b.ts",
|
||||||
},
|
},
|
||||||
"kind": 6,
|
"kind": 6,
|
||||||
"sortText": "16",
|
"sortText": "16_0",
|
||||||
"commitCharacters": [
|
"commitCharacters": [
|
||||||
".",
|
".",
|
||||||
",",
|
",",
|
||||||
|
@ -5347,7 +5347,7 @@ fn lsp_completions_auto_import() {
|
||||||
"kind": "markdown",
|
"kind": "markdown",
|
||||||
"value": ""
|
"value": ""
|
||||||
},
|
},
|
||||||
"sortText": "16",
|
"sortText": "16_0",
|
||||||
"additionalTextEdits": [
|
"additionalTextEdits": [
|
||||||
{
|
{
|
||||||
"range": {
|
"range": {
|
||||||
|
@ -5430,7 +5430,7 @@ fn lsp_npm_completions_auto_import_and_quick_fix_no_import_map() {
|
||||||
"kind": "markdown",
|
"kind": "markdown",
|
||||||
"value": ""
|
"value": ""
|
||||||
},
|
},
|
||||||
"sortText": "16",
|
"sortText": "16_1",
|
||||||
"additionalTextEdits": [
|
"additionalTextEdits": [
|
||||||
{
|
{
|
||||||
"range": {
|
"range": {
|
||||||
|
@ -5540,7 +5540,7 @@ fn lsp_npm_completions_auto_import_and_quick_fix_no_import_map() {
|
||||||
"description": "npm:chalk@5.0",
|
"description": "npm:chalk@5.0",
|
||||||
},
|
},
|
||||||
"kind": 6,
|
"kind": 6,
|
||||||
"sortText": "16",
|
"sortText": "16_1",
|
||||||
"additionalTextEdits": [
|
"additionalTextEdits": [
|
||||||
{
|
{
|
||||||
"range": {
|
"range": {
|
||||||
|
@ -5748,7 +5748,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() {
|
||||||
"kind": "markdown",
|
"kind": "markdown",
|
||||||
"value": ""
|
"value": ""
|
||||||
},
|
},
|
||||||
"sortText": "16",
|
"sortText": "16_0",
|
||||||
"additionalTextEdits": [
|
"additionalTextEdits": [
|
||||||
{
|
{
|
||||||
"range": {
|
"range": {
|
||||||
|
@ -5858,7 +5858,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() {
|
||||||
"description": "chalk",
|
"description": "chalk",
|
||||||
},
|
},
|
||||||
"kind": 6,
|
"kind": 6,
|
||||||
"sortText": "16",
|
"sortText": "16_0",
|
||||||
"additionalTextEdits": [
|
"additionalTextEdits": [
|
||||||
{
|
{
|
||||||
"range": {
|
"range": {
|
||||||
|
@ -5968,7 +5968,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() {
|
||||||
"description": "print_hello",
|
"description": "print_hello",
|
||||||
},
|
},
|
||||||
"kind": 3,
|
"kind": 3,
|
||||||
"sortText": "16",
|
"sortText": "16_0",
|
||||||
"additionalTextEdits": [
|
"additionalTextEdits": [
|
||||||
{
|
{
|
||||||
"range": {
|
"range": {
|
||||||
|
|
Loading…
Reference in a new issue