Skip to content
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

Add support for JSDoc @ignore to allow for hiding properties from completions #60895

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ import {
getJSDocDeprecatedTag,
getJSDocEnumTag,
getJSDocHost,
getJSDocIgnoreTag,
getJSDocOverloadTags,
getJSDocParameterTags,
getJSDocRoot,
Expand Down Expand Up @@ -34747,7 +34748,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
* @param property the accessed property's symbol.
*/
function isValidPropertyAccessForCompletions(node: PropertyAccessExpression | ImportTypeNode | QualifiedName, type: Type, property: Symbol): boolean {
return isPropertyAccessible(node, node.kind === SyntaxKind.PropertyAccessExpression && node.expression.kind === SyntaxKind.SuperKeyword, /*isWrite*/ false, type, property);
return isPropertyAccessible(node, node.kind === SyntaxKind.PropertyAccessExpression && node.expression.kind === SyntaxKind.SuperKeyword, /*isWrite*/ false, type, property)
&& (!property.declarations || some(property.declarations, decl => !getJSDocIgnoreTag(decl)));
// Previously we validated the 'this' type of methods but this adversely affected performance. See #31377 for more context.
}

Expand Down
1 change: 1 addition & 0 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1851,6 +1851,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
return emitJSDocHeritageTag(node as JSDocImplementsTag | JSDocAugmentsTag);
case SyntaxKind.JSDocAuthorTag:
case SyntaxKind.JSDocDeprecatedTag:
case SyntaxKind.JSDocIgnoreTag:
return;
// SyntaxKind.JSDocClassTag (see JSDocTag, above)
case SyntaxKind.JSDocPublicTag:
Expand Down
9 changes: 9 additions & 0 deletions src/compiler/factory/nodeFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ import {
JSDocDeprecatedTag,
JSDocEnumTag,
JSDocFunctionType,
JSDocIgnoreTag,
JSDocImplementsTag,
JSDocImportTag,
JSDocLink,
Expand Down Expand Up @@ -939,6 +940,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
get updateJSDocDeprecatedTag() {
return getJSDocSimpleTagUpdateFunction<JSDocDeprecatedTag>(SyntaxKind.JSDocDeprecatedTag);
},
get createJSDocIgnoreTag() {
return getJSDocSimpleTagCreateFunction<JSDocIgnoreTag>(SyntaxKind.JSDocIgnoreTag);
},
get updateJSDocIgnoreTag() {
return getJSDocSimpleTagUpdateFunction<JSDocIgnoreTag>(SyntaxKind.JSDocIgnoreTag);
},
get createJSDocThrowsTag() {
return getJSDocTypeLikeTagCreateFunction<JSDocThrowsTag>(SyntaxKind.JSDocThrowsTag);
},
Expand Down Expand Up @@ -5457,6 +5464,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
// createJSDocProtectedTag
// createJSDocReadonlyTag
// createJSDocDeprecatedTag
// createJSDocIgnoreTag
function createJSDocSimpleTagWorker<T extends JSDocTag>(kind: T["kind"], tagName: Identifier | undefined, comment?: string | NodeArray<JSDocComment>) {
const node = createBaseJSDocTag<T>(kind, tagName ?? createIdentifier(getDefaultTagNameForKind(kind)), comment);
return node;
Expand All @@ -5470,6 +5478,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
// updateJSDocProtectedTag
// updateJSDocReadonlyTag
// updateJSDocDeprecatedTag
// updateJSDocIgnoreTag
function updateJSDocSimpleTagWorker<T extends JSDocTag>(kind: T["kind"], node: T, tagName: Identifier = getDefaultTagName(node), comment: string | NodeArray<JSDocComment> | undefined) {
return node.tagName !== tagName
|| node.comment !== comment
Expand Down
5 changes: 5 additions & 0 deletions src/compiler/factory/nodeTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import {
JSDocDeprecatedTag,
JSDocEnumTag,
JSDocFunctionType,
JSDocIgnoreTag,
JSDocImplementsTag,
JSDocImportTag,
JSDocLink,
Expand Down Expand Up @@ -1137,6 +1138,10 @@ export function isJSDocDeprecatedTag(node: Node): node is JSDocDeprecatedTag {
return node.kind === SyntaxKind.JSDocDeprecatedTag;
}

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

export function isJSDocSeeTag(node: Node): node is JSDocSeeTag {
return node.kind === SyntaxKind.JSDocSeeTag;
}
Expand Down
7 changes: 6 additions & 1 deletion src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ import {
JSDocDeprecatedTag,
JSDocEnumTag,
JSDocFunctionType,
JSDocIgnoreTag,
JSDocImplementsTag,
JSDocImportTag,
JSDocLink,
Expand Down Expand Up @@ -1129,6 +1130,7 @@ const forEachChildTable: ForEachChildTable = {
[SyntaxKind.JSDocProtectedTag]: forEachChildInJSDocTag,
[SyntaxKind.JSDocReadonlyTag]: forEachChildInJSDocTag,
[SyntaxKind.JSDocDeprecatedTag]: forEachChildInJSDocTag,
[SyntaxKind.JSDocIgnoreTag]: forEachChildInJSDocTag,
[SyntaxKind.JSDocOverrideTag]: forEachChildInJSDocTag,
[SyntaxKind.JSDocImportTag]: forEachChildInJSDocImportTag,
[SyntaxKind.PartiallyEmittedExpression]: forEachChildInPartiallyEmittedExpression,
Expand Down Expand Up @@ -1215,7 +1217,7 @@ function forEachChildInJSDocLinkCodeOrPlain<T>(node: JSDocLink | JSDocLinkCode |
return visitNode(cbNode, node.name);
}

function forEachChildInJSDocTag<T>(node: JSDocUnknownTag | JSDocClassTag | JSDocPublicTag | JSDocPrivateTag | JSDocProtectedTag | JSDocReadonlyTag | JSDocDeprecatedTag | JSDocOverrideTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray<Node>) => T | undefined): T | undefined {
function forEachChildInJSDocTag<T>(node: JSDocUnknownTag | JSDocClassTag | JSDocPublicTag | JSDocPrivateTag | JSDocProtectedTag | JSDocReadonlyTag | JSDocDeprecatedTag | JSDocIgnoreTag | JSDocOverrideTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray<Node>) => T | undefined): T | undefined {
return visitNode(cbNode, node.tagName)
|| (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment));
}
Expand Down Expand Up @@ -9096,6 +9098,9 @@ namespace Parser {
hasDeprecatedTag = true;
tag = parseSimpleTag(start, factory.createJSDocDeprecatedTag, tagName, margin, indentText);
break;
case "ignore":
tag = parseSimpleTag(start, factory.createJSDocIgnoreTag, tagName, margin, indentText);
break;
case "this":
tag = parseThisTag(start, tagName, margin, indentText);
break;
Expand Down
8 changes: 8 additions & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ export const enum SyntaxKind {
JSDocImplementsTag,
JSDocAuthorTag,
JSDocDeprecatedTag,
JSDocIgnoreTag,
JSDocClassTag,
JSDocPublicTag,
JSDocPrivateTag,
Expand Down Expand Up @@ -1047,6 +1048,7 @@ export type ForEachChildNodes =
| JSDocProtectedTag
| JSDocReadonlyTag
| JSDocDeprecatedTag
| JSDocIgnoreTag
| JSDocThrowsTag
| JSDocOverrideTag
| JSDocSatisfiesTag
Expand Down Expand Up @@ -3999,6 +4001,10 @@ export interface JSDocDeprecatedTag extends JSDocTag {
kind: SyntaxKind.JSDocDeprecatedTag;
}

export interface JSDocIgnoreTag extends JSDocTag {
kind: SyntaxKind.JSDocIgnoreTag;
}

export interface JSDocClassTag extends JSDocTag {
readonly kind: SyntaxKind.JSDocClassTag;
}
Expand Down Expand Up @@ -9138,6 +9144,8 @@ export interface NodeFactory {
updateJSDocUnknownTag(node: JSDocUnknownTag, tagName: Identifier, comment: string | NodeArray<JSDocComment> | undefined): JSDocUnknownTag;
createJSDocDeprecatedTag(tagName: Identifier | undefined, comment?: string | NodeArray<JSDocComment>): JSDocDeprecatedTag;
updateJSDocDeprecatedTag(node: JSDocDeprecatedTag, tagName: Identifier | undefined, comment?: string | NodeArray<JSDocComment>): JSDocDeprecatedTag;
createJSDocIgnoreTag(tagName: Identifier | undefined, comment?: string | NodeArray<JSDocComment>): JSDocIgnoreTag;
updateJSDocIgnoreTag(node: JSDocIgnoreTag, tagName: Identifier | undefined, comment?: string | NodeArray<JSDocComment>): JSDocIgnoreTag;
createJSDocOverrideTag(tagName: Identifier | undefined, comment?: string | NodeArray<JSDocComment>): JSDocOverrideTag;
updateJSDocOverrideTag(node: JSDocOverrideTag, tagName: Identifier | undefined, comment?: string | NodeArray<JSDocComment>): JSDocOverrideTag;
createJSDocThrowsTag(tagName: Identifier, typeExpression: JSDocTypeExpression | undefined, comment?: string | NodeArray<JSDocComment>): JSDocThrowsTag;
Expand Down
7 changes: 7 additions & 0 deletions src/compiler/utilitiesPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ import {
isJSDocDeprecatedTag,
isJSDocEnumTag,
isJSDocFunctionType,
isJSDocIgnoreTag,
isJSDocImplementsTag,
isJSDocOverloadTag,
isJSDocOverrideTag,
Expand Down Expand Up @@ -183,6 +184,7 @@ import {
JSDocContainer,
JSDocDeprecatedTag,
JSDocEnumTag,
JSDocIgnoreTag,
JSDocImplementsTag,
JSDocLink,
JSDocLinkCode,
Expand Down Expand Up @@ -1174,6 +1176,11 @@ export function getJSDocDeprecatedTagNoCache(node: Node): JSDocDeprecatedTag | u
return getFirstJSDocTag(node, isJSDocDeprecatedTag, /*noCache*/ true);
}

/** Gets the JSDoc ignore tag for the node if present */
export function getJSDocIgnoreTag(node: Node): JSDocIgnoreTag | undefined {
return getFirstJSDocTag(node, isJSDocIgnoreTag);
}

/** Gets the JSDoc enum tag for the node if present */
export function getJSDocEnumTag(node: Node): JSDocEnumTag | undefined {
return getFirstJSDocTag(node, isJSDocEnumTag);
Expand Down
67 changes: 38 additions & 29 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4008,33 +4008,34 @@ declare namespace ts {
JSDocImplementsTag = 329,
JSDocAuthorTag = 330,
JSDocDeprecatedTag = 331,
JSDocClassTag = 332,
JSDocPublicTag = 333,
JSDocPrivateTag = 334,
JSDocProtectedTag = 335,
JSDocReadonlyTag = 336,
JSDocOverrideTag = 337,
JSDocCallbackTag = 338,
JSDocOverloadTag = 339,
JSDocEnumTag = 340,
JSDocParameterTag = 341,
JSDocReturnTag = 342,
JSDocThisTag = 343,
JSDocTypeTag = 344,
JSDocTemplateTag = 345,
JSDocTypedefTag = 346,
JSDocSeeTag = 347,
JSDocPropertyTag = 348,
JSDocThrowsTag = 349,
JSDocSatisfiesTag = 350,
JSDocImportTag = 351,
SyntaxList = 352,
NotEmittedStatement = 353,
NotEmittedTypeElement = 354,
PartiallyEmittedExpression = 355,
CommaListExpression = 356,
SyntheticReferenceExpression = 357,
Count = 358,
JSDocIgnoreTag = 332,
JSDocClassTag = 333,
JSDocPublicTag = 334,
JSDocPrivateTag = 335,
JSDocProtectedTag = 336,
JSDocReadonlyTag = 337,
JSDocOverrideTag = 338,
JSDocCallbackTag = 339,
JSDocOverloadTag = 340,
JSDocEnumTag = 341,
JSDocParameterTag = 342,
JSDocReturnTag = 343,
JSDocThisTag = 344,
JSDocTypeTag = 345,
JSDocTemplateTag = 346,
JSDocTypedefTag = 347,
JSDocSeeTag = 348,
JSDocPropertyTag = 349,
JSDocThrowsTag = 350,
JSDocSatisfiesTag = 351,
JSDocImportTag = 352,
SyntaxList = 353,
NotEmittedStatement = 354,
NotEmittedTypeElement = 355,
PartiallyEmittedExpression = 356,
CommaListExpression = 357,
SyntheticReferenceExpression = 358,
Count = 359,
FirstAssignment = 64,
LastAssignment = 79,
FirstCompoundAssignment = 65,
Expand Down Expand Up @@ -4063,9 +4064,9 @@ declare namespace ts {
LastStatement = 259,
FirstNode = 166,
FirstJSDocNode = 309,
LastJSDocNode = 351,
LastJSDocNode = 352,
FirstJSDocTagNode = 327,
LastJSDocTagNode = 351,
LastJSDocTagNode = 352,
}
type TriviaSyntaxKind = SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia | SyntaxKind.NewLineTrivia | SyntaxKind.WhitespaceTrivia | SyntaxKind.ShebangTrivia | SyntaxKind.ConflictMarkerTrivia;
type LiteralSyntaxKind = SyntaxKind.NumericLiteral | SyntaxKind.BigIntLiteral | SyntaxKind.StringLiteral | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.RegularExpressionLiteral | SyntaxKind.NoSubstitutionTemplateLiteral;
Expand Down Expand Up @@ -5774,6 +5775,9 @@ declare namespace ts {
interface JSDocDeprecatedTag extends JSDocTag {
kind: SyntaxKind.JSDocDeprecatedTag;
}
interface JSDocIgnoreTag extends JSDocTag {
kind: SyntaxKind.JSDocIgnoreTag;
}
interface JSDocClassTag extends JSDocTag {
readonly kind: SyntaxKind.JSDocClassTag;
}
Expand Down Expand Up @@ -7815,6 +7819,8 @@ declare namespace ts {
updateJSDocUnknownTag(node: JSDocUnknownTag, tagName: Identifier, comment: string | NodeArray<JSDocComment> | undefined): JSDocUnknownTag;
createJSDocDeprecatedTag(tagName: Identifier | undefined, comment?: string | NodeArray<JSDocComment>): JSDocDeprecatedTag;
updateJSDocDeprecatedTag(node: JSDocDeprecatedTag, tagName: Identifier | undefined, comment?: string | NodeArray<JSDocComment>): JSDocDeprecatedTag;
createJSDocIgnoreTag(tagName: Identifier | undefined, comment?: string | NodeArray<JSDocComment>): JSDocIgnoreTag;
updateJSDocIgnoreTag(node: JSDocIgnoreTag, tagName: Identifier | undefined, comment?: string | NodeArray<JSDocComment>): JSDocIgnoreTag;
createJSDocOverrideTag(tagName: Identifier | undefined, comment?: string | NodeArray<JSDocComment>): JSDocOverrideTag;
updateJSDocOverrideTag(node: JSDocOverrideTag, tagName: Identifier | undefined, comment?: string | NodeArray<JSDocComment>): JSDocOverrideTag;
createJSDocThrowsTag(tagName: Identifier, typeExpression: JSDocTypeExpression | undefined, comment?: string | NodeArray<JSDocComment>): JSDocThrowsTag;
Expand Down Expand Up @@ -8670,6 +8676,8 @@ declare namespace ts {
function getJSDocOverrideTagNoCache(node: Node): JSDocOverrideTag | undefined;
/** Gets the JSDoc deprecated tag for the node if present */
function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined;
/** Gets the JSDoc ignore tag for the node if present */
function getJSDocIgnoreTag(node: Node): JSDocIgnoreTag | undefined;
/** Gets the JSDoc enum tag for the node if present */
function getJSDocEnumTag(node: Node): JSDocEnumTag | undefined;
/** Gets the JSDoc this tag for the node if present */
Expand Down Expand Up @@ -9116,6 +9124,7 @@ declare namespace ts {
function isJSDocOverrideTag(node: Node): node is JSDocOverrideTag;
function isJSDocOverloadTag(node: Node): node is JSDocOverloadTag;
function isJSDocDeprecatedTag(node: Node): node is JSDocDeprecatedTag;
function isJSDocIgnoreTag(node: Node): node is JSDocIgnoreTag;
function isJSDocSeeTag(node: Node): node is JSDocSeeTag;
function isJSDocEnumTag(node: Node): node is JSDocEnumTag;
function isJSDocParameterTag(node: Node): node is JSDocParameterTag;
Expand Down
16 changes: 16 additions & 0 deletions tests/cases/fourslash/completionsIgnoreTagOnProperty1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// <reference path="fourslash.ts" />

//// type Foo = {
//// /** @ignore */
//// a: string;
//// b: number;
//// };
////
//// declare const foo: Foo;
//// foo./**/

verify.completions({
marker: "",
exact: "b",
isNewIdentifierLocation: false,
});
Loading