mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 01:49:57 -05:00
feat(14751): show static members at the top of the list for a class like completion (#40428)
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
/* @internal */
|
||||
namespace ts.Completions {
|
||||
export enum SortText {
|
||||
LocationPriority = "0",
|
||||
OptionalMember = "1",
|
||||
MemberDeclaredBySpreadAssignment = "2",
|
||||
SuggestedClassMembers = "3",
|
||||
GlobalsOrKeywords = "4",
|
||||
AutoImportSuggestions = "5",
|
||||
JavascriptIdentifiers = "6"
|
||||
LocalDeclarationPriority = "0",
|
||||
LocationPriority = "1",
|
||||
OptionalMember = "2",
|
||||
MemberDeclaredBySpreadAssignment = "3",
|
||||
SuggestedClassMembers = "4",
|
||||
GlobalsOrKeywords = "5",
|
||||
AutoImportSuggestions = "6",
|
||||
JavascriptIdentifiers = "7"
|
||||
}
|
||||
export type Log = (message: string) => void;
|
||||
|
||||
@@ -1270,7 +1271,7 @@ namespace ts.Completions {
|
||||
else {
|
||||
for (const symbol of type.getApparentProperties()) {
|
||||
if (typeChecker.isValidPropertyAccessForCompletions(propertyAccess, type, symbol)) {
|
||||
addPropertySymbol(symbol, /*insertAwait*/ false, insertQuestionDot);
|
||||
addPropertySymbol(symbol, /* insertAwait */ false, insertQuestionDot);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1307,14 +1308,22 @@ namespace ts.Completions {
|
||||
}
|
||||
else if (preferences.includeCompletionsWithInsertText) {
|
||||
addSymbolOriginInfo(symbol);
|
||||
addSymbolSortInfo(symbol);
|
||||
symbols.push(symbol);
|
||||
}
|
||||
}
|
||||
else {
|
||||
addSymbolOriginInfo(symbol);
|
||||
addSymbolSortInfo(symbol);
|
||||
symbols.push(symbol);
|
||||
}
|
||||
|
||||
function addSymbolSortInfo(symbol: Symbol) {
|
||||
if (isStaticProperty(symbol)) {
|
||||
symbolToSortTextMap[getSymbolId(symbol)] = SortText.LocalDeclarationPriority;
|
||||
}
|
||||
}
|
||||
|
||||
function addSymbolOriginInfo(symbol: Symbol) {
|
||||
if (preferences.includeCompletionsWithInsertText) {
|
||||
if (insertAwait && !symbolToOriginInfoMap[getSymbolId(symbol)]) {
|
||||
@@ -2817,4 +2826,8 @@ namespace ts.Completions {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isStaticProperty(symbol: Symbol) {
|
||||
return !!(symbol.valueDeclaration && getEffectiveModifierFlags(symbol.valueDeclaration) & ModifierFlags.Static && isClassLike(symbol.valueDeclaration.parent));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ namespace ts.JsDoc {
|
||||
name: tagName,
|
||||
kind: ScriptElementKind.keyword,
|
||||
kindModifiers: "",
|
||||
sortText: "0",
|
||||
sortText: Completions.SortText.LocationPriority,
|
||||
};
|
||||
}));
|
||||
}
|
||||
@@ -177,7 +177,7 @@ namespace ts.JsDoc {
|
||||
name: `@${tagName}`,
|
||||
kind: ScriptElementKind.keyword,
|
||||
kindModifiers: "",
|
||||
sortText: "0"
|
||||
sortText: Completions.SortText.LocationPriority
|
||||
};
|
||||
}));
|
||||
}
|
||||
@@ -212,7 +212,7 @@ namespace ts.JsDoc {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return { name, kind: ScriptElementKind.parameterElement, kindModifiers: "", sortText: "0" };
|
||||
return { name, kind: ScriptElementKind.parameterElement, kindModifiers: "", sortText: Completions.SortText.LocationPriority };
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace ts.Completions.StringCompletions {
|
||||
name: type.value,
|
||||
kindModifiers: ScriptElementKindModifier.none,
|
||||
kind: ScriptElementKind.string,
|
||||
sortText: "0",
|
||||
sortText: SortText.LocationPriority,
|
||||
replacementSpan: getReplacementSpanForContextToken(contextToken)
|
||||
}));
|
||||
return { isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: completion.isNewIdentifier, optionalReplacementSpan, entries };
|
||||
|
||||
@@ -55,8 +55,8 @@ namespace ts.projectSystem {
|
||||
offset: aTs.content.indexOf("this.") + 1 + "this.".length
|
||||
};
|
||||
const expectedCompletionEntries: readonly protocol.CompletionEntry[] = [
|
||||
{ name: "foo", kind: ScriptElementKind.memberFunctionElement, kindModifiers: "", sortText: "0" },
|
||||
{ name: "prop", kind: ScriptElementKind.memberVariableElement, kindModifiers: "", sortText: "0" }
|
||||
{ name: "foo", kind: ScriptElementKind.memberFunctionElement, kindModifiers: "", sortText: Completions.SortText.LocationPriority },
|
||||
{ name: "prop", kind: ScriptElementKind.memberVariableElement, kindModifiers: "", sortText: Completions.SortText.LocationPriority }
|
||||
];
|
||||
|
||||
it("can pass through metadata when the command returns array", () => {
|
||||
|
||||
Reference in New Issue
Block a user