mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
fix(41867): completions - omit the deprecated flag if some declarations are not deprecated (#41941)
This commit is contained in:
@@ -100,31 +100,42 @@ namespace ts.SymbolDisplay {
|
||||
return ScriptElementKind.unknown;
|
||||
}
|
||||
|
||||
function isDeprecatedDeclaration(decl: Declaration) {
|
||||
return !!(getCombinedNodeFlagsAlwaysIncludeJSDoc(decl) & ModifierFlags.Deprecated);
|
||||
}
|
||||
|
||||
function getNormalizedSymbolModifiers(symbol: Symbol) {
|
||||
if (symbol.declarations && symbol.declarations.length) {
|
||||
const [declaration, ...declarations] = symbol.declarations;
|
||||
// omit deprecated flag if some declarations are not deprecated
|
||||
const excludeFlags = length(declarations) && isDeprecatedDeclaration(declaration) && some(declarations, d => !isDeprecatedDeclaration(d))
|
||||
? ModifierFlags.Deprecated
|
||||
: ModifierFlags.None;
|
||||
const modifiers = getNodeModifiers(declaration, excludeFlags);
|
||||
if (modifiers) {
|
||||
return modifiers.split(",");
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
export function getSymbolModifiers(typeChecker: TypeChecker, symbol: Symbol): string {
|
||||
if (!symbol) {
|
||||
return ScriptElementKindModifier.none;
|
||||
}
|
||||
|
||||
const modifiers = new Set<string>();
|
||||
if (symbol.declarations && symbol.declarations.length > 0) {
|
||||
const kindModifiers = getNodeModifiers(symbol.declarations[0]);
|
||||
if (kindModifiers !== ScriptElementKindModifier.none) {
|
||||
kindModifiers.split(",").forEach(m => modifiers.add(m));
|
||||
}
|
||||
}
|
||||
const modifiers = new Set(getNormalizedSymbolModifiers(symbol));
|
||||
if (symbol.flags & SymbolFlags.Alias) {
|
||||
const resolvedSymbol = typeChecker.getAliasedSymbol(symbol);
|
||||
if (resolvedSymbol !== symbol && resolvedSymbol.declarations && resolvedSymbol.declarations.length > 0) {
|
||||
const kindModifiers = getNodeModifiers(resolvedSymbol.declarations[0]);
|
||||
if (kindModifiers !== ScriptElementKindModifier.none) {
|
||||
kindModifiers.split(",").forEach(m => modifiers.add(m));
|
||||
}
|
||||
if (resolvedSymbol !== symbol) {
|
||||
forEach(getNormalizedSymbolModifiers(resolvedSymbol), modifier => {
|
||||
modifiers.add(modifier);
|
||||
});
|
||||
}
|
||||
}
|
||||
if (symbol.flags & SymbolFlags.Optional) {
|
||||
modifiers.add(ScriptElementKindModifier.optionalModifier);
|
||||
}
|
||||
|
||||
return modifiers.size > 0 ? arrayFrom(modifiers.values()).join(",") : ScriptElementKindModifier.none;
|
||||
}
|
||||
|
||||
|
||||
@@ -1588,9 +1588,11 @@ namespace ts {
|
||||
return n.kind === SyntaxKind.EndOfFileToken ? !!(n as EndOfFileToken).jsDoc : n.getWidth(sourceFile) !== 0;
|
||||
}
|
||||
|
||||
export function getNodeModifiers(node: Node): string {
|
||||
const flags = isDeclaration(node) ? getCombinedNodeFlagsAlwaysIncludeJSDoc(node) : ModifierFlags.None;
|
||||
export function getNodeModifiers(node: Node, excludeFlags = ModifierFlags.None): string {
|
||||
const result: string[] = [];
|
||||
const flags = isDeclaration(node)
|
||||
? getCombinedNodeFlagsAlwaysIncludeJSDoc(node) & ~excludeFlags
|
||||
: ModifierFlags.None;
|
||||
|
||||
if (flags & ModifierFlags.Private) result.push(ScriptElementKindModifier.privateMemberModifier);
|
||||
if (flags & ModifierFlags.Protected) result.push(ScriptElementKindModifier.protectedMemberModifier);
|
||||
|
||||
15
tests/cases/fourslash/completionsWithDeprecatedTag2.ts
Normal file
15
tests/cases/fourslash/completionsWithDeprecatedTag2.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
/////** @deprecated foo */
|
||||
////declare function foo<T>();
|
||||
/////** @deprecated foo<T> */
|
||||
////declare function foo<T>(x);
|
||||
////
|
||||
////foo/**/
|
||||
|
||||
verify.completions({
|
||||
marker: "",
|
||||
includes: [
|
||||
{ name: "foo", kind: "function", kindModifiers: "deprecated,declare" }
|
||||
]
|
||||
});
|
||||
15
tests/cases/fourslash/completionsWithDeprecatedTag3.ts
Normal file
15
tests/cases/fourslash/completionsWithDeprecatedTag3.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
/////** @deprecated foo */
|
||||
////declare function foo<T>();
|
||||
/////** ok */
|
||||
////declare function foo<T>(x);
|
||||
////
|
||||
////foo/**/
|
||||
|
||||
verify.completions({
|
||||
marker: "",
|
||||
includes: [
|
||||
{ name: "foo", kind: "function", kindModifiers: "declare" }
|
||||
]
|
||||
});
|
||||
Reference in New Issue
Block a user