Skip to content
4 changes: 4 additions & 0 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3851,6 +3851,10 @@ function getCompletionData(
if (firstAccessibleSymbolId && addToSeen(seenPropertySymbols, firstAccessibleSymbolId)) {
const index = symbols.length;
symbols.push(firstAccessibleSymbol);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

// Symbol completions should have lower priority since they represent computed property access
symbolToSortTextMap[getSymbolId(firstAccessibleSymbol)] = SortText.GlobalsOrKeywords;

const moduleSymbol = firstAccessibleSymbol.parent;
if (
!moduleSymbol ||
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/completionsUniqueSymbol2.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"name": "a",
"kind": "const",
"kindModifiers": "",
"sortText": "11",
"sortText": "15",
"insertText": "[a]",
"replacementSpan": {
"start": 344,
Expand Down Expand Up @@ -210,7 +210,7 @@
"name": "b",
"kind": "const",
"kindModifiers": "",
"sortText": "11",
"sortText": "15",
"insertText": "[b]",
"replacementSpan": {
"start": 344,
Expand Down
14 changes: 7 additions & 7 deletions tests/cases/fourslash/completionForComputedStringProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
//// declare const a: A;
//// a[|./**/|]

verify.completions({
marker: "",
exact: [
{ name: "p1" },
{ name: "p2", insertText: '[p2]', replacementSpan: test.ranges()[0] },
],
preferences: { includeInsertTextCompletions: true },
verify.completions({
marker: "",
exact: [
{ name: "p1" },
{ name: "p2", insertText: '[p2]', sortText: completion.SortText.GlobalsOrKeywords, replacementSpan: test.ranges()[0] },
],
preferences: { includeInsertTextCompletions: true },
});
4 changes: 2 additions & 2 deletions tests/cases/fourslash/completionsSymbolMembers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
verify.completions(
{
marker: "i",
exact: { name: "s", insertText: "[s]", replacementSpan: test.ranges()[0] },
exact: { name: "s", insertText: "[s]", sortText: completion.SortText.GlobalsOrKeywords, replacementSpan: test.ranges()[0] },
preferences: { includeInsertTextCompletions: true },
},
{
marker: "j",
exact: { name: "N", insertText: "[N]", replacementSpan: test.ranges()[1] },
exact: { name: "N", insertText: "[N]", sortText: completion.SortText.GlobalsOrKeywords, replacementSpan: test.ranges()[1] },
preferences: { includeInsertTextCompletions: true },
}
);
2 changes: 1 addition & 1 deletion tests/cases/fourslash/completionsUniqueSymbol1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@

verify.completions({
marker: "",
exact: { name: "M", insertText: "[M]", replacementSpan: test.ranges()[0] },
exact: { name: "M", insertText: "[M]", sortText: completion.SortText.GlobalsOrKeywords, replacementSpan: test.ranges()[0] },
preferences: { includeInsertTextCompletions: true },
});
2 changes: 1 addition & 1 deletion tests/cases/fourslash/completionsUniqueSymbol_import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ verify.completions({
marker: "",
exact: [
"n",
{ name: "publicSym", source: "/a", insertText: "[publicSym]", replacementSpan: test.ranges()[0], hasAction: true },
{ name: "publicSym", source: "/a", insertText: "[publicSym]", sortText: completion.SortText.GlobalsOrKeywords, replacementSpan: test.ranges()[0], hasAction: true },
],
preferences: {
includeInsertTextCompletions: true,
Expand Down
20 changes: 20 additions & 0 deletions tests/cases/fourslash/symbolCompletionLowerPriority.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// <reference path="fourslash.ts" />

////declare const Symbol: (s: string) => symbol;
////const mySymbol = Symbol("test");
////interface TestInterface {
//// [mySymbol]: string;
//// normalProperty: number;
////}
////const obj: TestInterface = {} as any;
////obj./*completions*/

// Test new behavior: Symbol completions should have lower priority
verify.completions({
marker: "completions",
includes: [
{ name: "normalProperty", sortText: completion.SortText.LocationPriority },
{ name: "mySymbol", sortText: completion.SortText.GlobalsOrKeywords, insertText: "[mySymbol]" }
],
preferences: { includeInsertTextCompletions: true }
});