Skip to content

Commit 9185734

Browse files
committed
Add deprecated related feature
1 parent 5ef2228 commit 9185734

File tree

15 files changed

+143
-50
lines changed

15 files changed

+143
-50
lines changed

src/compiler/factoryPublic.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2595,6 +2595,10 @@ namespace ts {
25952595
return createJSDocTag(SyntaxKind.JSDocAuthorTag, "author", comment);
25962596
}
25972597

2598+
export function createJSDocDeprecatedTag(comment?: string) {
2599+
return createJSDocTag(SyntaxKind.JSDocDeprecatedTag, "deprecated", comment);
2600+
}
2601+
25982602
export function createJSDocPublicTag() {
25992603
return createJSDocTag(SyntaxKind.JSDocPublicTag, "public");
26002604
}

src/compiler/parser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7065,6 +7065,9 @@ namespace ts {
70657065
case "readonly":
70667066
tag = parseSimpleTag(start, SyntaxKind.JSDocReadonlyTag, tagName);
70677067
break;
7068+
case "deprecated":
7069+
tag = parseSimpleTag(start, SyntaxKind.JSDocDeprecatedTag, tagName);
7070+
break;
70687071
case "this":
70697072
tag = parseThisTag(start, tagName);
70707073
break;

src/compiler/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ namespace ts {
473473
JSDocAugmentsTag,
474474
JSDocImplementsTag,
475475
JSDocAuthorTag,
476+
JSDocDeprecatedTag,
476477
JSDocClassTag,
477478
JSDocPublicTag,
478479
JSDocPrivateTag,
@@ -2676,6 +2677,10 @@ namespace ts {
26762677
kind: SyntaxKind.JSDocAuthorTag;
26772678
}
26782679

2680+
export interface JSDocDeprecatedTag extends JSDocTag {
2681+
kind: SyntaxKind.JSDocDeprecatedTag;
2682+
}
2683+
26792684
export interface JSDocClassTag extends JSDocTag {
26802685
kind: SyntaxKind.JSDocClassTag;
26812686
}

src/compiler/utilitiesPublic.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,11 @@ namespace ts {
759759
return getFirstJSDocTag(node, isJSDocTemplateTag);
760760
}
761761

762+
/** Gets the JSDoc deprecated tag for the node if present */
763+
export function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined {
764+
return getFirstJSDocTag(node, isJSDocDeprecatedTag);
765+
}
766+
762767
/** Gets the JSDoc type tag for the node if present and valid */
763768
export function getJSDocTypeTag(node: Node): JSDocTypeTag | undefined {
764769
// We should have already issued an error if there were multiple type jsdocs, so just use the first one.
@@ -1692,6 +1697,10 @@ namespace ts {
16921697
return node.kind === SyntaxKind.JSDocTemplateTag;
16931698
}
16941699

1700+
export function isJSDocDeprecatedTag(node: Node): node is JSDocDeprecatedTag {
1701+
return node.kind === SyntaxKind.JSDocDeprecatedTag;
1702+
}
1703+
16951704
export function isJSDocTypedefTag(node: Node): node is JSDocTypedefTag {
16961705
return node.kind === SyntaxKind.JSDocTypedefTag;
16971706
}

src/harness/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ namespace ts.server {
242242
isCaseSensitive: entry.isCaseSensitive,
243243
fileName: entry.file,
244244
textSpan: this.decodeSpan(entry),
245+
isDeprecated: !!entry.tags?.includes(protocol.SymbolTag.Deprecated)
245246
}));
246247
}
247248

src/harness/fourslashImpl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2982,6 +2982,7 @@ namespace FourSlash {
29822982
textSpan: ts.createTextSpanFromRange(e.range),
29832983
containerName: e.containerName || "",
29842984
containerKind: e.containerKind || ts.ScriptElementKind.unknown,
2985+
isDeprecated: !!e.isDeprecated
29852986
})));
29862987
}
29872988
}

src/harness/fourslashInterfaceImpl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,7 @@ namespace FourSlashInterface {
15411541
readonly range: FourSlash.Range;
15421542
readonly containerName?: string;
15431543
readonly containerKind?: ts.ScriptElementKind;
1544+
readonly isDeprecated?: boolean
15441545
}
15451546

15461547
export type ArrayOrSingle<T> = T | readonly T[];

src/server/protocol.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,6 +2818,10 @@ namespace ts.server.protocol {
28182818
arguments: NavtoRequestArgs;
28192819
}
28202820

2821+
export enum SymbolTag {
2822+
Deprecated = 1
2823+
}
2824+
28212825
/**
28222826
* An item found in a navto response.
28232827
*/
@@ -2857,6 +2861,11 @@ namespace ts.server.protocol {
28572861
* Kind of symbol's container symbol (if any).
28582862
*/
28592863
containerKind?: ScriptElementKind;
2864+
2865+
/**
2866+
* The symbol's tag.
2867+
*/
2868+
tags?: SymbolTag[]
28602869
}
28612870

28622871
/**

src/server/session.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,8 @@ namespace ts.server {
18861886
matchKind: navItem.matchKind,
18871887
file: navItem.fileName,
18881888
start: scriptInfo.positionToLineOffset(navItem.textSpan.start),
1889-
end: scriptInfo.positionToLineOffset(textSpanEnd(navItem.textSpan))
1889+
end: scriptInfo.positionToLineOffset(textSpanEnd(navItem.textSpan)),
1890+
tags: navItem.isDeprecated ? [protocol.SymbolTag.Deprecated] : undefined
18901891
};
18911892
if (navItem.kindModifiers && (navItem.kindModifiers !== "")) {
18921893
bakedItem.kindModifiers = navItem.kindModifiers;

src/services/navigateTo.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ namespace ts.NavigateTo {
131131
// TODO(jfreeman): What should be the containerName when the container has a computed name?
132132
containerName: containerName ? (<Identifier>containerName).text : "",
133133
containerKind: containerName ? getNodeKind(container!) : ScriptElementKind.unknown, // TODO: GH#18217 Just use `container ? ...`
134+
isDeprecated: !!getJSDocDeprecatedTag(rawItem.declaration)
134135
};
135136
}
136137
}

0 commit comments

Comments
 (0)