1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -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:
Nayeem Rahman 2023-09-18 19:55:24 +01:00 committed by GitHub
parent d72f5d573a
commit f7ba701304
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 11 deletions

View file

@ -2817,10 +2817,10 @@ impl CompletionEntry {
let mut kind: Option<lsp::CompletionItemKind> =
Some(self.kind.clone().into());
let sort_text = if self.source.is_some() {
Some(format!("\u{ffff}{}", self.sort_text))
let mut sort_text = if self.source.is_some() {
format!("\u{ffff}{}", self.sort_text)
} else {
Some(self.sort_text.clone())
self.sort_text.clone()
};
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
.get_or_insert_with(Default::default)
.description = Some(source);
@ -2919,7 +2926,7 @@ impl CompletionEntry {
label,
label_details,
kind,
sort_text,
sort_text: Some(sort_text),
preselect,
text_edit,
filter_text,

View file

@ -5308,7 +5308,7 @@ fn lsp_completions_auto_import() {
"description": "./b.ts",
},
"kind": 6,
"sortText": "￿16",
"sortText": "￿16_0",
"commitCharacters": [
".",
",",
@ -5347,7 +5347,7 @@ fn lsp_completions_auto_import() {
"kind": "markdown",
"value": ""
},
"sortText": "￿16",
"sortText": "￿16_0",
"additionalTextEdits": [
{
"range": {
@ -5430,7 +5430,7 @@ fn lsp_npm_completions_auto_import_and_quick_fix_no_import_map() {
"kind": "markdown",
"value": ""
},
"sortText": "￿16",
"sortText": "￿16_1",
"additionalTextEdits": [
{
"range": {
@ -5540,7 +5540,7 @@ fn lsp_npm_completions_auto_import_and_quick_fix_no_import_map() {
"description": "npm:chalk@5.0",
},
"kind": 6,
"sortText": "￿16",
"sortText": "￿16_1",
"additionalTextEdits": [
{
"range": {
@ -5748,7 +5748,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() {
"kind": "markdown",
"value": ""
},
"sortText": "￿16",
"sortText": "￿16_0",
"additionalTextEdits": [
{
"range": {
@ -5858,7 +5858,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() {
"description": "chalk",
},
"kind": 6,
"sortText": "￿16",
"sortText": "￿16_0",
"additionalTextEdits": [
{
"range": {
@ -5968,7 +5968,7 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() {
"description": "print_hello",
},
"kind": 3,
"sortText": "￿16",
"sortText": "￿16_0",
"additionalTextEdits": [
{
"range": {