Skip to content

Commit b18bad2

Browse files
committed
fix(43796): sort deprecated completions lower than others
1 parent 5e4fcfb commit b18bad2

10 files changed

+9049
-46
lines changed

src/services/completions.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ namespace ts.Completions {
88
SuggestedClassMembers = "4",
99
GlobalsOrKeywords = "5",
1010
AutoImportSuggestions = "6",
11-
JavascriptIdentifiers = "7"
11+
JavascriptIdentifiers = "7",
12+
Deprecated = "8"
1213
}
1314
export type Log = (message: string) => void;
1415

@@ -585,9 +586,11 @@ namespace ts.Completions {
585586
}
586587

587588
const { name, needsConvertPropertyAccess } = info;
589+
const sortText = isDeprecatedSymbol(symbol, typeChecker) ? SortText.Deprecated :
590+
symbolToSortTextMap && symbolToSortTextMap[getSymbolId(symbol)] || SortText.LocationPriority;
588591
const entry = createCompletionEntry(
589592
symbol,
590-
symbolToSortTextMap && symbolToSortTextMap[getSymbolId(symbol)] || SortText.LocationPriority,
593+
sortText,
591594
contextToken,
592595
location,
593596
sourceFile,
@@ -3051,4 +3054,9 @@ namespace ts.Completions {
30513054
addToSeen(seenModules, getSymbolId(sym)) &&
30523055
checker.getExportsOfModule(sym).some(e => symbolCanBeReferencedAtTypeLocation(e, checker, seenModules));
30533056
}
3057+
3058+
function isDeprecatedSymbol(symbol: Symbol, checker: TypeChecker) {
3059+
const declarations = skipAlias(symbol, checker).declarations;
3060+
return !!length(declarations) && every(declarations, isDeprecatedDeclaration);
3061+
}
30543062
}

src/services/symbolDisplay.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ namespace ts.SymbolDisplay {
100100
return ScriptElementKind.unknown;
101101
}
102102

103-
function isDeprecatedDeclaration(decl: Declaration) {
104-
return !!(getCombinedNodeFlagsAlwaysIncludeJSDoc(decl) & ModifierFlags.Deprecated);
105-
}
106-
107103
function getNormalizedSymbolModifiers(symbol: Symbol) {
108104
if (symbol.declarations && symbol.declarations.length) {
109105
const [declaration, ...declarations] = symbol.declarations;

src/services/utilities.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3352,5 +3352,9 @@ namespace ts {
33523352
|| (!!globalCachePath && startsWith(getCanonicalFileName(globalCachePath), toNodeModulesParent));
33533353
}
33543354

3355+
export function isDeprecatedDeclaration(decl: Declaration) {
3356+
return !!(getCombinedNodeFlagsAlwaysIncludeJSDoc(decl) & ModifierFlags.Deprecated);
3357+
}
3358+
33553359
// #endregion
33563360
}

0 commit comments

Comments
 (0)