diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index 7442f8a1eb..2c63131b6a 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -2817,10 +2817,10 @@ impl CompletionEntry { let mut kind: Option = 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, diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs index 5499c8a6ee..de96266200 100644 --- a/cli/tests/integration/lsp_tests.rs +++ b/cli/tests/integration/lsp_tests.rs @@ -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": {