Skip to content

Add see tag support #39760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4394731
Add see tag parser
Kingwl Jul 27, 2020
c89574c
add baseline
Kingwl Jul 27, 2020
5b49a14
fix symbol resolve
Kingwl Jul 27, 2020
d916393
add more case
Kingwl Jul 27, 2020
2611909
fix unittests
Kingwl Jul 28, 2020
3d47343
improve tests and parser
Kingwl Jul 28, 2020
bcef14f
accept baseline
Kingwl Jul 28, 2020
5442afd
Adopt package-lock.json and npm ci
amcasey Aug 19, 2020
5521ba5
Add a workflow to update package-lock.json daily
amcasey Aug 20, 2020
95462f5
Git ignore package-lock.json and forcibly update in workflow
amcasey Aug 20, 2020
7c667cb
Update bot email address
amcasey Aug 20, 2020
fd29771
Delete extra npm update
amcasey Aug 21, 2020
37700f5
Update package-lock.json
typescript-bot Aug 21, 2020
ef08789
Add compactDisplay and signDisplay to NumberFormatOptions (#40039)
wyze Aug 21, 2020
6a75377
Fix typo in (Readonly)Set.keys comment (fixes #40164) (#40176)
cherryblossom000 Aug 21, 2020
85501e6
fix(26325): use a unique name for reserved words in 'constructor like…
a-tarasyuk Aug 21, 2020
b4393fe
fix(25770): add diagnostic message for the possible mapped type used …
a-tarasyuk Aug 21, 2020
e6dabbe
fix(31046): add new diagnostic message for incompatible constructor s…
a-tarasyuk Aug 22, 2020
d0ae77e
Update package-lock.json
typescript-bot Aug 23, 2020
d187c63
Update package-lock.json
typescript-bot Aug 24, 2020
acbcd61
Merge branch 'master' of github.com:Kingwl/TypeScript
Kingwl Aug 25, 2020
e46ce36
Merge branch 'master' of github.com:microsoft/TypeScript
Kingwl Aug 25, 2020
a8abadb
Merge branch 'master' into see-tag
Kingwl Aug 25, 2020
bd12cd4
Merge branch 'master' into see-tag
Kingwl Aug 26, 2020
e2b6832
Add rename support
Kingwl Aug 26, 2020
50d25aa
Accpet baseline
Kingwl Aug 26, 2020
96ec48d
wip
Kingwl Sep 1, 2020
b3178d4
fix anders
egamma Sep 1, 2020
8cac241
Revert "fix anders"
egamma Sep 1, 2020
3b502f4
Fix call hierarchy item serialization and server tests (#40348)
andrewbranch Sep 1, 2020
eb9ad2a
Merge branch 'master' into see-tag
Kingwl Sep 2, 2020
6d90fb3
Avoid error
Kingwl Sep 2, 2020
51b67d7
accept baseline
Kingwl Sep 2, 2020
2c6f1bd
Add more tests
Kingwl Sep 4, 2020
1effe1b
Merge branch 'master' into see-tag
Kingwl Sep 9, 2020
6451424
Add signature name resolve
Kingwl Sep 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36425,6 +36425,17 @@ namespace ts {
return node.parent.kind === SyntaxKind.ExpressionWithTypeArguments;
}

function isJSDocEntryNameReference(node: Identifier | PrivateIdentifier | PropertyAccessExpression | QualifiedName): boolean {
while (node.parent.kind === SyntaxKind.QualifiedName) {
node = node.parent as QualifiedName;
}
while (node.parent.kind === SyntaxKind.PropertyAccessExpression) {
node = node.parent as PropertyAccessExpression;
}

return node.parent.kind === SyntaxKind.JSDocNameReference;
}

function forEachEnclosingClass<T>(node: Node, callback: (node: Node) => T | undefined): T | undefined {
let result: T | undefined;

Expand Down Expand Up @@ -36609,6 +36620,10 @@ namespace ts {
const meaning = name.parent.kind === SyntaxKind.TypeReference ? SymbolFlags.Type : SymbolFlags.Namespace;
return resolveEntityName(<EntityName>name, meaning, /*ignoreErrors*/ false, /*dontResolveAlias*/ true);
}
else if (isJSDocEntryNameReference(name)) {
const meaning = SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Value;
return resolveEntityName(<EntityName>name, meaning, /*ignoreErrors*/ false, /*dontResolveAlias*/ true, getHostSignatureFromJSDoc(name));
}

if (name.parent.kind === SyntaxKind.TypePredicate) {
return resolveEntityName(<Identifier>name, /*meaning*/ SymbolFlags.FunctionScopedVariable);
Expand Down
17 changes: 17 additions & 0 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,10 @@ namespace ts {
case SyntaxKind.JSDocClassTag:
case SyntaxKind.JSDocTag:
return emitJSDocSimpleTag(node as JSDocTag);
case SyntaxKind.JSDocSeeTag:
return emitJSDocSeeTag(node as JSDocSeeTag);
case SyntaxKind.JSDocNameReference:
return emitJSDocNameReference(node as JSDocNameReference);

case SyntaxKind.JSDocComment:
return emitJSDoc(node as JSDoc);
Expand Down Expand Up @@ -3503,6 +3507,19 @@ namespace ts {
emitJSDocComment(tag.comment);
}

function emitJSDocSeeTag(tag: JSDocSeeTag) {
emitJSDocTagName(tag.tagName);
emit(tag.name);
emitJSDocComment(tag.comment);
}

function emitJSDocNameReference(node: JSDocNameReference) {
writeSpace();
writePunctuation("{");
emit(node.name);
writePunctuation("}");
}

function emitJSDocHeritageTag(tag: JSDocImplementsTag | JSDocAugmentsTag) {
emitJSDocTagName(tag.tagName);
writeSpace();
Expand Down
34 changes: 34 additions & 0 deletions src/compiler/factory/nodeFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ namespace ts {
updateJSDocAugmentsTag,
createJSDocImplementsTag,
updateJSDocImplementsTag,
createJSDocSeeTag,
updateJSDocSeeTag,
createJSDocNameReference,
updateJSDocNameReference,
// lazily load factory members for JSDoc tags with similar structure
get createJSDocTypeTag() { return getJSDocTypeLikeTagCreateFunction<JSDocTypeTag>(SyntaxKind.JSDocTypeTag); },
get updateJSDocTypeTag() { return getJSDocTypeLikeTagUpdateFunction<JSDocTypeTag>(SyntaxKind.JSDocTypeTag); },
Expand Down Expand Up @@ -4259,6 +4263,36 @@ namespace ts {
return node;
}

// @api
function createJSDocSeeTag(tagName: Identifier | undefined, name: JSDocNameReference | undefined, comment?: string): JSDocSeeTag {
const node = createBaseJSDocTag<JSDocSeeTag>(SyntaxKind.JSDocSeeTag, tagName ?? createIdentifier("see"), comment);
node.name = name;
return node;
}

// @api
function updateJSDocSeeTag(node: JSDocSeeTag, tagName: Identifier | undefined, name: JSDocNameReference | undefined, comment?: string): JSDocSeeTag {
return node.tagName !== tagName
|| node.name !== name
|| node.comment !== comment
? update(createJSDocSeeTag(tagName, name, comment), node)
: node;
}

// @api
function createJSDocNameReference(name: EntityName): JSDocNameReference {
const node = createBaseNode<JSDocNameReference>(SyntaxKind.JSDocNameReference);
node.name = name;
return node;
}

// @api
function updateJSDocNameReference(node: JSDocNameReference, name: EntityName): JSDocNameReference {
return node.name !== name
? update(createJSDocNameReference(name), node)
: node;
}

// @api
function updateJSDocImplementsTag(node: JSDocImplementsTag, tagName: Identifier = getDefaultTagName(node), className: JSDocImplementsTag["class"], comment: string | undefined): JSDocImplementsTag {
return node.tagName !== tagName
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/factory/nodeTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,10 @@ namespace ts {
return node.kind === SyntaxKind.JSDocTypeExpression;
}

export function isJSDocNameReference(node: Node): node is JSDocNameReference {
return node.kind === SyntaxKind.JSDocNameReference;
}

export function isJSDocAllType(node: Node): node is JSDocAllType {
return node.kind === SyntaxKind.JSDocAllType;
}
Expand Down
28 changes: 28 additions & 0 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ namespace ts {
visitNode(cbNode, (<JSDocFunctionType>node).type);
case SyntaxKind.JSDocComment:
return visitNodes(cbNode, cbNodes, (<JSDoc>node).tags);
case SyntaxKind.JSDocSeeTag:
return visitNode(cbNode, (node as JSDocSeeTag).tagName) ||
visitNode(cbNode, (node as JSDocSeeTag).name);
case SyntaxKind.JSDocNameReference:
return visitNode(cbNode, (node as JSDocNameReference).name);
case SyntaxKind.JSDocParameterTag:
case SyntaxKind.JSDocPropertyTag:
return visitNode(cbNode, (node as JSDocTag).tagName) ||
Expand Down Expand Up @@ -7150,6 +7155,19 @@ namespace ts {
return finishNode(result, pos);
}

export function parseJSDocNameReference(): JSDocNameReference {
const pos = getNodePos();
const hasBrace = parseOptional(SyntaxKind.OpenBraceToken);
const entityName = parseEntityName(/* allowReservedWords*/ false);
if (hasBrace) {
parseExpectedJSDoc(SyntaxKind.CloseBraceToken);
}

const result = factory.createJSDocNameReference(entityName);
fixupParentReferences(result);
return finishNode(result, pos);
}

export function parseIsolatedJSDocComment(content: string, start: number | undefined, length: number | undefined): { jsDoc: JSDoc, diagnostics: Diagnostic[] } | undefined {
initializeState("", content, ScriptTarget.Latest, /*_syntaxCursor:*/ undefined, ScriptKind.JS);
const jsDoc = doInsideOfContext(NodeFlags.JSDoc, () => parseJSDocCommentWorker(start, length));
Expand Down Expand Up @@ -7431,6 +7449,9 @@ namespace ts {
case "callback":
tag = parseCallbackTag(start, tagName, margin, indentText);
break;
case "see":
tag = parseSeeTag(start, tagName, margin, indentText);
break;
default:
tag = parseUnknownTag(start, tagName, margin, indentText);
break;
Expand Down Expand Up @@ -7661,6 +7682,13 @@ namespace ts {
return finishNode(factory.createJSDocTypeTag(tagName, typeExpression, comments), start, end);
}

function parseSeeTag(start: number, tagName: Identifier, indent?: number, indentText?: string): JSDocSeeTag {
const nameExpression = parseJSDocNameReference();
const end = getNodePos();
const comments = indent !== undefined && indentText !== undefined ? parseTrailingTagComments(start, end, indent, indentText) : undefined;
return finishNode(factory.createJSDocSeeTag(tagName, nameExpression, comments), start, end);
}

function parseAuthorTag(start: number, tagName: Identifier, indent: number, indentText: string): JSDocAuthorTag {
const authorInfoWithEmail = tryParse(() => tryParseAuthorNameAndEmail());
if (!authorInfoWithEmail) {
Expand Down
16 changes: 16 additions & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ namespace ts {

// JSDoc nodes
JSDocTypeExpression,
JSDocNameReference,
// The * type
JSDocAllType,
// The ? type
Expand Down Expand Up @@ -389,6 +390,7 @@ namespace ts {
JSDocTypeTag,
JSDocTemplateTag,
JSDocTypedefTag,
JSDocSeeTag,
JSDocPropertyTag,

// Synthesized list
Expand Down Expand Up @@ -3055,6 +3057,11 @@ namespace ts {
readonly type: TypeNode;
}

export interface JSDocNameReference extends Node {
readonly kind: SyntaxKind.JSDocNameReference;
readonly name: EntityName;
}

export interface JSDocType extends TypeNode {
_jsDocTypeBrand: any;
}
Expand Down Expand Up @@ -3179,6 +3186,11 @@ namespace ts {
readonly typeParameters: NodeArray<TypeParameterDeclaration>;
}

export interface JSDocSeeTag extends JSDocTag {
readonly kind: SyntaxKind.JSDocSeeTag;
readonly name?: JSDocNameReference;
}

export interface JSDocReturnTag extends JSDocTag {
readonly kind: SyntaxKind.JSDocReturnTag;
readonly typeExpression?: JSDocTypeExpression;
Expand Down Expand Up @@ -6965,6 +6977,8 @@ namespace ts {
updateJSDocNamepathType(node: JSDocNamepathType, type: TypeNode): JSDocNamepathType;
createJSDocTypeExpression(type: TypeNode): JSDocTypeExpression;
updateJSDocTypeExpression(node: JSDocTypeExpression, type: TypeNode): JSDocTypeExpression;
createJSDocNameReference(name: EntityName): JSDocNameReference;
updateJSDocNameReference(node: JSDocNameReference, name: EntityName): JSDocNameReference;
createJSDocTypeLiteral(jsDocPropertyTags?: readonly JSDocPropertyLikeTag[], isArrayType?: boolean): JSDocTypeLiteral;
updateJSDocTypeLiteral(node: JSDocTypeLiteral, jsDocPropertyTags: readonly JSDocPropertyLikeTag[] | undefined, isArrayType: boolean | undefined): JSDocTypeLiteral;
createJSDocSignature(typeParameters: readonly JSDocTemplateTag[] | undefined, parameters: readonly JSDocParameterTag[], type?: JSDocReturnTag): JSDocSignature;
Expand All @@ -6979,6 +6993,8 @@ namespace ts {
updateJSDocPropertyTag(node: JSDocPropertyTag, tagName: Identifier | undefined, name: EntityName, isBracketed: boolean, typeExpression: JSDocTypeExpression | undefined, isNameFirst: boolean, comment: string | undefined): JSDocPropertyTag;
createJSDocTypeTag(tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment?: string): JSDocTypeTag;
updateJSDocTypeTag(node: JSDocTypeTag, tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment: string | undefined): JSDocTypeTag;
createJSDocSeeTag(tagName: Identifier | undefined, nameExpression: JSDocNameReference | undefined, comment?: string): JSDocSeeTag;
updateJSDocSeeTag(node: JSDocSeeTag, tagName: Identifier | undefined, nameExpression: JSDocNameReference | undefined, comment?: string): JSDocSeeTag;
createJSDocReturnTag(tagName: Identifier | undefined, typeExpression?: JSDocTypeExpression, comment?: string): JSDocReturnTag;
updateJSDocReturnTag(node: JSDocReturnTag, tagName: Identifier | undefined, typeExpression: JSDocTypeExpression | undefined, comment: string | undefined): JSDocReturnTag;
createJSDocThisTag(tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment?: string): JSDocThisTag;
Expand Down
3 changes: 3 additions & 0 deletions src/services/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ namespace ts {
else if (isDeclarationName(node)) {
return getMeaningFromDeclaration(node.parent);
}
else if (isEntityName(node) && isJSDocNameReference(node.parent)) {
return SemanticMeaning.All;
}
else if (isTypeReference(node)) {
return SemanticMeaning.Type;
}
Expand Down
1 change: 0 additions & 1 deletion src/testRunner/unittests/jsDocParsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ namespace ts {
`/**
* {@link first link}
* Inside {@link link text} thing
* @see {@link second link text} and {@link Foo|a foo} as well.
*/`);
parsesCorrectly("authorTag",
`/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
{
"kind": "JSDocComment",
"pos": 0,
"end": 127,
"end": 63,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"comment": "{@link first link}\nInside {@link link text} thing",
"tags": {
"0": {
"kind": "JSDocTag",
"pos": 63,
"end": 68,
"modifierFlagsCache": 0,
"transformFlags": 0,
"tagName": {
"kind": "Identifier",
"pos": 64,
"end": 67,
"modifierFlagsCache": 0,
"transformFlags": 0,
"escapedText": "see"
},
"comment": "{@link second link text} and {@link Foo|a foo} as well."
},
"length": 1,
"pos": 63,
"end": 68,
"hasTrailingComma": false,
"transformFlags": 0
}
"comment": "{@link first link}\nInside {@link link text} thing"
}
Loading