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

+4
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

+3
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

+5
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

+9
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

+1
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

+1
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

+1
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

+9
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

+2-1
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

+1
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
}

src/services/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,7 @@ namespace ts {
802802
textSpan: TextSpan;
803803
containerName: string;
804804
containerKind: ScriptElementKind;
805+
isDeprecated: boolean
805806
}
806807

807808
export enum IndentStyle {

src/testRunner/unittests/tsserver/declarationFileMaps.ts

+7
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ namespace ts.projectSystem {
296296
isCaseSensitive: true,
297297
kind: ScriptElementKind.functionElement,
298298
kindModifiers: "export,declare",
299+
tags: undefined
299300
},
300301
{
301302
...protocolFileSpanFromSubstring({
@@ -307,6 +308,7 @@ namespace ts.projectSystem {
307308
isCaseSensitive: true,
308309
kind: ScriptElementKind.functionElement,
309310
kindModifiers: "export",
311+
tags: undefined
310312
},
311313
{
312314
...protocolFileSpanFromSubstring({
@@ -318,6 +320,7 @@ namespace ts.projectSystem {
318320
isCaseSensitive: true,
319321
kind: ScriptElementKind.functionElement,
320322
kindModifiers: "export",
323+
tags: undefined
321324
},
322325
]);
323326

@@ -338,6 +341,7 @@ namespace ts.projectSystem {
338341
isCaseSensitive: true,
339342
kind: ScriptElementKind.functionElement,
340343
kindModifiers: "export",
344+
tags: undefined
341345
},
342346
{
343347
...protocolFileSpanFromSubstring({
@@ -349,6 +353,7 @@ namespace ts.projectSystem {
349353
isCaseSensitive: true,
350354
kind: ScriptElementKind.functionElement,
351355
kindModifiers: "export",
356+
tags: undefined
352357
},
353358
{
354359
...protocolFileSpanFromSubstring({
@@ -360,6 +365,7 @@ namespace ts.projectSystem {
360365
isCaseSensitive: true,
361366
kind: ScriptElementKind.functionElement,
362367
kindModifiers: "export",
368+
tags: undefined
363369
}
364370
]);
365371
});
@@ -378,6 +384,7 @@ namespace ts.projectSystem {
378384
isCaseSensitive: true,
379385
kind: ScriptElementKind.functionElement,
380386
kindModifiers: "export",
387+
tags: undefined
381388
}
382389
]);
383390
});

src/testRunner/unittests/tsserver/navTo.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
namespace ts.projectSystem {
22
describe("unittests:: tsserver:: navigate-to for javascript project", () => {
3+
function findNavToItem(items: protocol.NavtoItem[], itemName: string, itemKind: string) {
4+
return find(items, item => item.name === itemName && item.kind === itemKind);
5+
}
6+
37
function containsNavToItem(items: protocol.NavtoItem[], itemName: string, itemKind: string) {
4-
return find(items, item => item.name === itemName && item.kind === itemKind) !== undefined;
8+
return findNavToItem(items, itemName, itemKind) !== undefined;
59
}
610

711
it("should not include type symbols", () => {
@@ -67,5 +71,26 @@ export const ghijkl = a.abcdef;`
6771
assert.strictEqual(item.name, "abcdef");
6872
assert.strictEqual(item.file, file1.path);
6973
});
74+
75+
it("should work with Deprecated", () => {
76+
const file1: File = {
77+
path: "/a/b/file1.js",
78+
content: "/** @deprecated */\nfunction foo () {}"
79+
};
80+
const configFile: File = {
81+
path: "/a/b/jsconfig.json",
82+
content: "{}"
83+
};
84+
const host = createServerHost([file1, configFile, libFile]);
85+
const session = createSession(host);
86+
openFilesForSession([file1], session);
87+
88+
// Try to find some interface type defined in lib.d.ts
89+
const libTypeNavToRequest = makeSessionRequest<protocol.NavtoRequestArgs>(CommandNames.Navto, { searchValue: "foo", file: file1.path, projectFileName: configFile.path });
90+
const items = session.executeCommand(libTypeNavToRequest).response as protocol.NavtoItem[];
91+
const fooItem = findNavToItem(items, "foo", "function");
92+
assert.isNotNull(fooItem, `Cannot find function symbol "foo".`);
93+
assert.isTrue(fooItem!.tags?.some(x => x === protocol.SymbolTag.Deprecated), "Cannot find deprecated tag");
94+
});
7095
});
7196
}

tests/baselines/reference/api/tsserverlibrary.d.ts

+40-24
Original file line numberDiff line numberDiff line change
@@ -385,28 +385,29 @@ declare namespace ts {
385385
JSDocAugmentsTag = 307,
386386
JSDocImplementsTag = 308,
387387
JSDocAuthorTag = 309,
388-
JSDocClassTag = 310,
389-
JSDocPublicTag = 311,
390-
JSDocPrivateTag = 312,
391-
JSDocProtectedTag = 313,
392-
JSDocReadonlyTag = 314,
393-
JSDocCallbackTag = 315,
394-
JSDocEnumTag = 316,
395-
JSDocParameterTag = 317,
396-
JSDocReturnTag = 318,
397-
JSDocThisTag = 319,
398-
JSDocTypeTag = 320,
399-
JSDocTemplateTag = 321,
400-
JSDocTypedefTag = 322,
401-
JSDocPropertyTag = 323,
402-
SyntaxList = 324,
403-
NotEmittedStatement = 325,
404-
PartiallyEmittedExpression = 326,
405-
CommaListExpression = 327,
406-
MergeDeclarationMarker = 328,
407-
EndOfDeclarationMarker = 329,
408-
SyntheticReferenceExpression = 330,
409-
Count = 331,
388+
JSDocDeprecatedTag = 310,
389+
JSDocClassTag = 311,
390+
JSDocPublicTag = 312,
391+
JSDocPrivateTag = 313,
392+
JSDocProtectedTag = 314,
393+
JSDocReadonlyTag = 315,
394+
JSDocCallbackTag = 316,
395+
JSDocEnumTag = 317,
396+
JSDocParameterTag = 318,
397+
JSDocReturnTag = 319,
398+
JSDocThisTag = 320,
399+
JSDocTypeTag = 321,
400+
JSDocTemplateTag = 322,
401+
JSDocTypedefTag = 323,
402+
JSDocPropertyTag = 324,
403+
SyntaxList = 325,
404+
NotEmittedStatement = 326,
405+
PartiallyEmittedExpression = 327,
406+
CommaListExpression = 328,
407+
MergeDeclarationMarker = 329,
408+
EndOfDeclarationMarker = 330,
409+
SyntheticReferenceExpression = 331,
410+
Count = 332,
410411
FirstAssignment = 62,
411412
LastAssignment = 74,
412413
FirstCompoundAssignment = 63,
@@ -435,9 +436,9 @@ declare namespace ts {
435436
LastStatement = 241,
436437
FirstNode = 153,
437438
FirstJSDocNode = 294,
438-
LastJSDocNode = 323,
439+
LastJSDocNode = 324,
439440
FirstJSDocTagNode = 306,
440-
LastJSDocTagNode = 323,
441+
LastJSDocTagNode = 324,
441442
}
442443
export enum NodeFlags {
443444
None = 0,
@@ -1649,6 +1650,9 @@ declare namespace ts {
16491650
export interface JSDocAuthorTag extends JSDocTag {
16501651
kind: SyntaxKind.JSDocAuthorTag;
16511652
}
1653+
export interface JSDocDeprecatedTag extends JSDocTag {
1654+
kind: SyntaxKind.JSDocDeprecatedTag;
1655+
}
16521656
export interface JSDocClassTag extends JSDocTag {
16531657
kind: SyntaxKind.JSDocClassTag;
16541658
}
@@ -3546,6 +3550,8 @@ declare namespace ts {
35463550
function getJSDocReturnTag(node: Node): JSDocReturnTag | undefined;
35473551
/** Gets the JSDoc template tag for the node if present */
35483552
function getJSDocTemplateTag(node: Node): JSDocTemplateTag | undefined;
3553+
/** Gets the JSDoc deprecated tag for the node if present */
3554+
function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined;
35493555
/** Gets the JSDoc type tag for the node if present and valid */
35503556
function getJSDocTypeTag(node: Node): JSDocTypeTag | undefined;
35513557
/**
@@ -3760,6 +3766,7 @@ declare namespace ts {
37603766
function isJSDocReturnTag(node: Node): node is JSDocReturnTag;
37613767
function isJSDocTypeTag(node: Node): node is JSDocTypeTag;
37623768
function isJSDocTemplateTag(node: Node): node is JSDocTemplateTag;
3769+
function isJSDocDeprecatedTag(node: Node): node is JSDocDeprecatedTag;
37633770
function isJSDocTypedefTag(node: Node): node is JSDocTypedefTag;
37643771
function isJSDocPropertyTag(node: Node): node is JSDocPropertyTag;
37653772
function isJSDocPropertyLikeTag(node: Node): node is JSDocPropertyLikeTag;
@@ -4270,6 +4277,7 @@ declare namespace ts {
42704277
function createJSDocTypeLiteral(jsDocPropertyTags?: readonly JSDocPropertyLikeTag[], isArrayType?: boolean): JSDocTypeLiteral;
42714278
function createJSDocImplementsTag(classExpression: JSDocImplementsTag["class"], comment?: string): JSDocImplementsTag;
42724279
function createJSDocAuthorTag(comment?: string): JSDocTag;
4280+
function createJSDocDeprecatedTag(comment?: string): JSDocTag;
42734281
function createJSDocPublicTag(): JSDocTag;
42744282
function createJSDocPrivateTag(): JSDocTag;
42754283
function createJSDocProtectedTag(): JSDocTag;
@@ -5585,6 +5593,7 @@ declare namespace ts {
55855593
textSpan: TextSpan;
55865594
containerName: string;
55875595
containerKind: ScriptElementKind;
5596+
isDeprecated: boolean;
55885597
}
55895598
enum IndentStyle {
55905599
None = 0,
@@ -8380,6 +8389,9 @@ declare namespace ts.server.protocol {
83808389
command: CommandTypes.Navto;
83818390
arguments: NavtoRequestArgs;
83828391
}
8392+
enum SymbolTag {
8393+
Deprecated = 1
8394+
}
83838395
/**
83848396
* An item found in a navto response.
83858397
*/
@@ -8413,6 +8425,10 @@ declare namespace ts.server.protocol {
84138425
* Kind of symbol's container symbol (if any).
84148426
*/
84158427
containerKind?: ScriptElementKind;
8428+
/**
8429+
* The symbol's tag.
8430+
*/
8431+
tags?: SymbolTag[];
84168432
}
84178433
/**
84188434
* Navto response message. Body is an array of navto items. Each

0 commit comments

Comments
 (0)