diff --git a/src/services/completions.ts b/src/services/completions.ts index 188f45f29ac45..2792c51301031 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -818,7 +818,7 @@ export function getCompletionsAtPosition( function compareCompletionEntries(entryInArray: CompletionEntry, entryToInsert: CompletionEntry): Comparison { let result = compareStringsCaseSensitiveUI(entryInArray.sortText, entryToInsert.sortText); if (result === Comparison.EqualTo) { - result = compareStringsCaseSensitiveUI(entryInArray.name, entryToInsert.name); + result = compareStringsCaseSensitiveUI(entryToInsert.name, entryInArray.name); } if (result === Comparison.EqualTo && entryInArray.data?.moduleSpecifier && entryToInsert.data?.moduleSpecifier) { // Sort same-named auto-imports by module specifier diff --git a/tests/baselines/reference/completionsCommitCharactersAfterDot.baseline b/tests/baselines/reference/completionsCommitCharactersAfterDot.baseline index 7ef62c786df3e..1d877c3de71f3 100644 --- a/tests/baselines/reference/completionsCommitCharactersAfterDot.baseline +++ b/tests/baselines/reference/completionsCommitCharactersAfterDot.baseline @@ -26,27 +26,27 @@ // const w = obj4?. // ^ // | ---------------------------------------------------------------------- -// | (method) Function.apply(this: Function, thisArg: any, argArray?: any): any -// | (property) Function.arguments: any -// | (method) Function.bind(this: Function, thisArg: any, ...argArray: any[]): any -// | (method) Function.call(this: Function, thisArg: any, ...argArray: any[]): any -// | (property) Function.caller: Function -// | (property) Function.length: number -// | (property) Function.prototype: any // | (method) Function.toString(): string +// | (property) Function.prototype: any +// | (property) Function.length: number +// | (property) Function.caller: Function +// | (method) Function.call(this: Function, thisArg: any, ...argArray: any[]): any +// | (method) Function.bind(this: Function, thisArg: any, ...argArray: any[]): any +// | (property) Function.arguments: any +// | (method) Function.apply(this: Function, thisArg: any, argArray?: any): any // | ---------------------------------------------------------------------- // declare const obj5: { (): string } | undefined; // const a = obj5?. // ^ // | ---------------------------------------------------------------------- -// | (method) Function.apply(this: Function, thisArg: any, argArray?: any): any -// | (property) Function.arguments: any -// | (method) Function.bind(this: Function, thisArg: any, ...argArray: any[]): any -// | (method) Function.call(this: Function, thisArg: any, ...argArray: any[]): any -// | (property) Function.caller: Function -// | (property) Function.length: number -// | (property) Function.prototype: any // | (method) Function.toString(): string +// | (property) Function.prototype: any +// | (property) Function.length: number +// | (property) Function.caller: Function +// | (method) Function.call(this: Function, thisArg: any, ...argArray: any[]): any +// | (method) Function.bind(this: Function, thisArg: any, ...argArray: any[]): any +// | (property) Function.arguments: any +// | (method) Function.apply(this: Function, thisArg: any, argArray?: any): any // | ---------------------------------------------------------------------- [ @@ -257,7 +257,7 @@ "isNewIdentifierLocation": true, "entries": [ { - "name": "apply", + "name": "toString", "kind": "method", "kindModifiers": "declare", "sortText": "11", @@ -287,7 +287,7 @@ "kind": "punctuation" }, { - "text": "apply", + "text": "toString", "kind": "methodName" }, { @@ -295,8 +295,8 @@ "kind": "punctuation" }, { - "text": "this", - "kind": "parameterName" + "text": ")", + "kind": "punctuation" }, { "text": ":", @@ -307,11 +307,33 @@ "kind": "space" }, { - "text": "Function", - "kind": "localName" + "text": "string", + "kind": "keyword" + } + ], + "documentation": [ + { + "text": "Returns a string representation of a function.", + "kind": "text" + } + ] + }, + { + "name": "prototype", + "kind": "property", + "kindModifiers": "declare", + "sortText": "11", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" }, { - "text": ",", + "text": "property", + "kind": "text" + }, + { + "text": ")", "kind": "punctuation" }, { @@ -319,23 +341,19 @@ "kind": "space" }, { - "text": "thisArg", - "kind": "parameterName" + "text": "Function", + "kind": "localName" }, { - "text": ":", + "text": ".", "kind": "punctuation" }, { - "text": " ", - "kind": "space" - }, - { - "text": "any", - "kind": "keyword" + "text": "prototype", + "kind": "propertyName" }, { - "text": ",", + "text": ":", "kind": "punctuation" }, { @@ -343,15 +361,28 @@ "kind": "space" }, { - "text": "argArray", - "kind": "parameterName" - }, + "text": "any", + "kind": "keyword" + } + ], + "documentation": [] + }, + { + "name": "length", + "kind": "property", + "kindModifiers": "declare", + "sortText": "11", + "displayParts": [ { - "text": "?", + "text": "(", "kind": "punctuation" }, { - "text": ":", + "text": "property", + "kind": "text" + }, + { + "text": ")", "kind": "punctuation" }, { @@ -359,13 +390,17 @@ "kind": "space" }, { - "text": "any", - "kind": "keyword" + "text": "Function", + "kind": "localName" }, { - "text": ")", + "text": ".", "kind": "punctuation" }, + { + "text": "length", + "kind": "propertyName" + }, { "text": ":", "kind": "punctuation" @@ -375,55 +410,14 @@ "kind": "space" }, { - "text": "any", + "text": "number", "kind": "keyword" } ], - "documentation": [ - { - "text": "Calls the function, substituting the specified object for the this value of the function, and the specified array for the arguments of the function.", - "kind": "text" - } - ], - "tags": [ - { - "name": "param", - "text": [ - { - "text": "thisArg", - "kind": "parameterName" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "The object to be used as the this object.", - "kind": "text" - } - ] - }, - { - "name": "param", - "text": [ - { - "text": "argArray", - "kind": "parameterName" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "A set of arguments to be passed to the function.", - "kind": "text" - } - ] - } - ] + "documentation": [] }, { - "name": "arguments", + "name": "caller", "kind": "property", "kindModifiers": "declare", "sortText": "11", @@ -453,7 +447,7 @@ "kind": "punctuation" }, { - "text": "arguments", + "text": "caller", "kind": "propertyName" }, { @@ -465,14 +459,14 @@ "kind": "space" }, { - "text": "any", - "kind": "keyword" + "text": "Function", + "kind": "localName" } ], "documentation": [] }, { - "name": "bind", + "name": "call", "kind": "method", "kindModifiers": "declare", "sortText": "11", @@ -502,7 +496,7 @@ "kind": "punctuation" }, { - "text": "bind", + "text": "call", "kind": "methodName" }, { @@ -604,7 +598,7 @@ ], "documentation": [ { - "text": "For a given function, creates a bound function that has the same body as the original function.\nThe this object of the bound function is associated with the specified object, and has the specified initial parameters.", + "text": "Calls a method of an object, substituting another object for the current object.", "kind": "text" } ], @@ -621,7 +615,7 @@ "kind": "space" }, { - "text": "An object to which the this keyword can refer inside the new function.", + "text": "The object to be used as the current object.", "kind": "text" } ] @@ -638,7 +632,7 @@ "kind": "space" }, { - "text": "A list of arguments to be passed to the new function.", + "text": "A list of arguments to be passed to the method.", "kind": "text" } ] @@ -646,7 +640,7 @@ ] }, { - "name": "call", + "name": "bind", "kind": "method", "kindModifiers": "declare", "sortText": "11", @@ -676,7 +670,7 @@ "kind": "punctuation" }, { - "text": "call", + "text": "bind", "kind": "methodName" }, { @@ -778,7 +772,7 @@ ], "documentation": [ { - "text": "Calls a method of an object, substituting another object for the current object.", + "text": "For a given function, creates a bound function that has the same body as the original function.\nThe this object of the bound function is associated with the specified object, and has the specified initial parameters.", "kind": "text" } ], @@ -795,7 +789,7 @@ "kind": "space" }, { - "text": "The object to be used as the current object.", + "text": "An object to which the this keyword can refer inside the new function.", "kind": "text" } ] @@ -812,7 +806,7 @@ "kind": "space" }, { - "text": "A list of arguments to be passed to the method.", + "text": "A list of arguments to be passed to the new function.", "kind": "text" } ] @@ -820,7 +814,7 @@ ] }, { - "name": "caller", + "name": "arguments", "kind": "property", "kindModifiers": "declare", "sortText": "11", @@ -850,7 +844,7 @@ "kind": "punctuation" }, { - "text": "caller", + "text": "arguments", "kind": "propertyName" }, { @@ -862,15 +856,15 @@ "kind": "space" }, { - "text": "Function", - "kind": "localName" + "text": "any", + "kind": "keyword" } ], "documentation": [] }, { - "name": "length", - "kind": "property", + "name": "apply", + "kind": "method", "kindModifiers": "declare", "sortText": "11", "displayParts": [ @@ -879,7 +873,7 @@ "kind": "punctuation" }, { - "text": "property", + "text": "method", "kind": "text" }, { @@ -899,40 +893,19 @@ "kind": "punctuation" }, { - "text": "length", - "kind": "propertyName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" + "text": "apply", + "kind": "methodName" }, - { - "text": "number", - "kind": "keyword" - } - ], - "documentation": [] - }, - { - "name": "prototype", - "kind": "property", - "kindModifiers": "declare", - "sortText": "11", - "displayParts": [ { "text": "(", "kind": "punctuation" }, { - "text": "property", - "kind": "text" + "text": "this", + "kind": "parameterName" }, { - "text": ")", + "text": ":", "kind": "punctuation" }, { @@ -944,12 +917,16 @@ "kind": "localName" }, { - "text": ".", + "text": ",", "kind": "punctuation" }, { - "text": "prototype", - "kind": "propertyName" + "text": " ", + "kind": "space" + }, + { + "text": "thisArg", + "kind": "parameterName" }, { "text": ":", @@ -962,26 +939,9 @@ { "text": "any", "kind": "keyword" - } - ], - "documentation": [] - }, - { - "name": "toString", - "kind": "method", - "kindModifiers": "declare", - "sortText": "11", - "displayParts": [ + }, { - "text": "(", - "kind": "punctuation" - }, - { - "text": "method", - "kind": "text" - }, - { - "text": ")", + "text": ",", "kind": "punctuation" }, { @@ -989,20 +949,24 @@ "kind": "space" }, { - "text": "Function", - "kind": "localName" + "text": "argArray", + "kind": "parameterName" }, { - "text": ".", + "text": "?", "kind": "punctuation" }, { - "text": "toString", - "kind": "methodName" + "text": ":", + "kind": "punctuation" }, { - "text": "(", - "kind": "punctuation" + "text": " ", + "kind": "space" + }, + { + "text": "any", + "kind": "keyword" }, { "text": ")", @@ -1017,15 +981,51 @@ "kind": "space" }, { - "text": "string", + "text": "any", "kind": "keyword" } ], "documentation": [ { - "text": "Returns a string representation of a function.", + "text": "Calls the function, substituting the specified object for the this value of the function, and the specified array for the arguments of the function.", "kind": "text" } + ], + "tags": [ + { + "name": "param", + "text": [ + { + "text": "thisArg", + "kind": "parameterName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "The object to be used as the this object.", + "kind": "text" + } + ] + }, + { + "name": "param", + "text": [ + { + "text": "argArray", + "kind": "parameterName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "A set of arguments to be passed to the function.", + "kind": "text" + } + ] + } ] } ], @@ -1045,7 +1045,7 @@ "isNewIdentifierLocation": true, "entries": [ { - "name": "apply", + "name": "toString", "kind": "method", "kindModifiers": "declare", "sortText": "11", @@ -1075,7 +1075,7 @@ "kind": "punctuation" }, { - "text": "apply", + "text": "toString", "kind": "methodName" }, { @@ -1083,8 +1083,8 @@ "kind": "punctuation" }, { - "text": "this", - "kind": "parameterName" + "text": ")", + "kind": "punctuation" }, { "text": ":", @@ -1095,11 +1095,33 @@ "kind": "space" }, { - "text": "Function", - "kind": "localName" + "text": "string", + "kind": "keyword" + } + ], + "documentation": [ + { + "text": "Returns a string representation of a function.", + "kind": "text" + } + ] + }, + { + "name": "prototype", + "kind": "property", + "kindModifiers": "declare", + "sortText": "11", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" }, { - "text": ",", + "text": "property", + "kind": "text" + }, + { + "text": ")", "kind": "punctuation" }, { @@ -1107,23 +1129,19 @@ "kind": "space" }, { - "text": "thisArg", - "kind": "parameterName" + "text": "Function", + "kind": "localName" }, { - "text": ":", + "text": ".", "kind": "punctuation" }, { - "text": " ", - "kind": "space" - }, - { - "text": "any", - "kind": "keyword" + "text": "prototype", + "kind": "propertyName" }, { - "text": ",", + "text": ":", "kind": "punctuation" }, { @@ -1131,15 +1149,28 @@ "kind": "space" }, { - "text": "argArray", - "kind": "parameterName" - }, + "text": "any", + "kind": "keyword" + } + ], + "documentation": [] + }, + { + "name": "length", + "kind": "property", + "kindModifiers": "declare", + "sortText": "11", + "displayParts": [ { - "text": "?", + "text": "(", "kind": "punctuation" }, { - "text": ":", + "text": "property", + "kind": "text" + }, + { + "text": ")", "kind": "punctuation" }, { @@ -1147,13 +1178,17 @@ "kind": "space" }, { - "text": "any", - "kind": "keyword" + "text": "Function", + "kind": "localName" }, { - "text": ")", + "text": ".", "kind": "punctuation" }, + { + "text": "length", + "kind": "propertyName" + }, { "text": ":", "kind": "punctuation" @@ -1163,55 +1198,14 @@ "kind": "space" }, { - "text": "any", + "text": "number", "kind": "keyword" } ], - "documentation": [ - { - "text": "Calls the function, substituting the specified object for the this value of the function, and the specified array for the arguments of the function.", - "kind": "text" - } - ], - "tags": [ - { - "name": "param", - "text": [ - { - "text": "thisArg", - "kind": "parameterName" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "The object to be used as the this object.", - "kind": "text" - } - ] - }, - { - "name": "param", - "text": [ - { - "text": "argArray", - "kind": "parameterName" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "A set of arguments to be passed to the function.", - "kind": "text" - } - ] - } - ] + "documentation": [] }, { - "name": "arguments", + "name": "caller", "kind": "property", "kindModifiers": "declare", "sortText": "11", @@ -1241,7 +1235,7 @@ "kind": "punctuation" }, { - "text": "arguments", + "text": "caller", "kind": "propertyName" }, { @@ -1253,14 +1247,14 @@ "kind": "space" }, { - "text": "any", - "kind": "keyword" + "text": "Function", + "kind": "localName" } ], "documentation": [] }, { - "name": "bind", + "name": "call", "kind": "method", "kindModifiers": "declare", "sortText": "11", @@ -1290,7 +1284,7 @@ "kind": "punctuation" }, { - "text": "bind", + "text": "call", "kind": "methodName" }, { @@ -1392,7 +1386,7 @@ ], "documentation": [ { - "text": "For a given function, creates a bound function that has the same body as the original function.\nThe this object of the bound function is associated with the specified object, and has the specified initial parameters.", + "text": "Calls a method of an object, substituting another object for the current object.", "kind": "text" } ], @@ -1409,7 +1403,7 @@ "kind": "space" }, { - "text": "An object to which the this keyword can refer inside the new function.", + "text": "The object to be used as the current object.", "kind": "text" } ] @@ -1426,7 +1420,7 @@ "kind": "space" }, { - "text": "A list of arguments to be passed to the new function.", + "text": "A list of arguments to be passed to the method.", "kind": "text" } ] @@ -1434,7 +1428,7 @@ ] }, { - "name": "call", + "name": "bind", "kind": "method", "kindModifiers": "declare", "sortText": "11", @@ -1464,7 +1458,7 @@ "kind": "punctuation" }, { - "text": "call", + "text": "bind", "kind": "methodName" }, { @@ -1566,7 +1560,7 @@ ], "documentation": [ { - "text": "Calls a method of an object, substituting another object for the current object.", + "text": "For a given function, creates a bound function that has the same body as the original function.\nThe this object of the bound function is associated with the specified object, and has the specified initial parameters.", "kind": "text" } ], @@ -1583,7 +1577,7 @@ "kind": "space" }, { - "text": "The object to be used as the current object.", + "text": "An object to which the this keyword can refer inside the new function.", "kind": "text" } ] @@ -1600,7 +1594,7 @@ "kind": "space" }, { - "text": "A list of arguments to be passed to the method.", + "text": "A list of arguments to be passed to the new function.", "kind": "text" } ] @@ -1608,7 +1602,7 @@ ] }, { - "name": "caller", + "name": "arguments", "kind": "property", "kindModifiers": "declare", "sortText": "11", @@ -1638,7 +1632,7 @@ "kind": "punctuation" }, { - "text": "caller", + "text": "arguments", "kind": "propertyName" }, { @@ -1650,15 +1644,15 @@ "kind": "space" }, { - "text": "Function", - "kind": "localName" + "text": "any", + "kind": "keyword" } ], "documentation": [] }, { - "name": "length", - "kind": "property", + "name": "apply", + "kind": "method", "kindModifiers": "declare", "sortText": "11", "displayParts": [ @@ -1667,7 +1661,7 @@ "kind": "punctuation" }, { - "text": "property", + "text": "method", "kind": "text" }, { @@ -1687,40 +1681,19 @@ "kind": "punctuation" }, { - "text": "length", - "kind": "propertyName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" + "text": "apply", + "kind": "methodName" }, - { - "text": "number", - "kind": "keyword" - } - ], - "documentation": [] - }, - { - "name": "prototype", - "kind": "property", - "kindModifiers": "declare", - "sortText": "11", - "displayParts": [ { "text": "(", "kind": "punctuation" }, { - "text": "property", - "kind": "text" + "text": "this", + "kind": "parameterName" }, { - "text": ")", + "text": ":", "kind": "punctuation" }, { @@ -1732,12 +1705,16 @@ "kind": "localName" }, { - "text": ".", + "text": ",", "kind": "punctuation" }, { - "text": "prototype", - "kind": "propertyName" + "text": " ", + "kind": "space" + }, + { + "text": "thisArg", + "kind": "parameterName" }, { "text": ":", @@ -1750,26 +1727,9 @@ { "text": "any", "kind": "keyword" - } - ], - "documentation": [] - }, - { - "name": "toString", - "kind": "method", - "kindModifiers": "declare", - "sortText": "11", - "displayParts": [ - { - "text": "(", - "kind": "punctuation" - }, - { - "text": "method", - "kind": "text" }, { - "text": ")", + "text": ",", "kind": "punctuation" }, { @@ -1777,20 +1737,24 @@ "kind": "space" }, { - "text": "Function", - "kind": "localName" + "text": "argArray", + "kind": "parameterName" }, { - "text": ".", + "text": "?", "kind": "punctuation" }, { - "text": "toString", - "kind": "methodName" + "text": ":", + "kind": "punctuation" }, { - "text": "(", - "kind": "punctuation" + "text": " ", + "kind": "space" + }, + { + "text": "any", + "kind": "keyword" }, { "text": ")", @@ -1805,15 +1769,51 @@ "kind": "space" }, { - "text": "string", + "text": "any", "kind": "keyword" } ], "documentation": [ { - "text": "Returns a string representation of a function.", + "text": "Calls the function, substituting the specified object for the this value of the function, and the specified array for the arguments of the function.", "kind": "text" } + ], + "tags": [ + { + "name": "param", + "text": [ + { + "text": "thisArg", + "kind": "parameterName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "The object to be used as the this object.", + "kind": "text" + } + ] + }, + { + "name": "param", + "text": [ + { + "text": "argArray", + "kind": "parameterName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "A set of arguments to be passed to the function.", + "kind": "text" + } + ] + } ] } ], diff --git a/tests/cases/fourslash/completionReverseAlphabetical.ts b/tests/cases/fourslash/completionReverseAlphabetical.ts new file mode 100644 index 0000000000000..5e8f2dba0fbed --- /dev/null +++ b/tests/cases/fourslash/completionReverseAlphabetical.ts @@ -0,0 +1,23 @@ +/// + +////interface TestInterface { +//// zebra: string; +//// apple: string; +//// banana: string; +//// cherry: string; +////} +//// +////function test(obj: TestInterface) { +//// obj./*completion*/ +////} + +// Test that completions are sorted in reverse alphabetical order (Z-A) +verify.completions({ + marker: "completion", + exact: [ + { name: "zebra", sortText: "11" }, + { name: "cherry", sortText: "11" }, + { name: "banana", sortText: "11" }, + { name: "apple", sortText: "11" } + ] +}); \ No newline at end of file