From e103692f32361de4082577f2a05be0ea98560a3f Mon Sep 17 00:00:00 2001 From: Andy Date: Fri, 20 Jul 2018 11:49:21 -0700 Subject: [PATCH] Don't report quickInfo inside a comment in a PropertyAccessExpression (#25813) --- src/services/services.ts | 52 +++++++++---------- .../fourslash/quickInfo_notInsideComment.ts | 6 +++ 2 files changed, 32 insertions(+), 26 deletions(-) create mode 100644 tests/cases/fourslash/quickInfo_notInsideComment.ts diff --git a/src/services/services.ts b/src/services/services.ts index eb7b9edefcd..ad39eb84a34 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1448,32 +1448,15 @@ namespace ts { const symbol = getSymbolAtLocationForQuickInfo(node, typeChecker); if (!symbol || typeChecker.isUnknownSymbol(symbol)) { - // Try getting just type at this position and show - switch (node.kind) { - case SyntaxKind.Identifier: - if (isLabelName(node)) { - // Type here will be 'any', avoid displaying this. - return undefined; - } - // falls through - case SyntaxKind.PropertyAccessExpression: - case SyntaxKind.QualifiedName: - case SyntaxKind.ThisKeyword: - case SyntaxKind.ThisType: - case SyntaxKind.SuperKeyword: - // For the identifiers/this/super etc get the type at position - const type = typeChecker.getTypeAtLocation(node); - return type && { - kind: ScriptElementKind.unknown, - kindModifiers: ScriptElementKindModifier.none, - textSpan: createTextSpanFromNode(node, sourceFile), - displayParts: typeChecker.runWithCancellationToken(cancellationToken, typeChecker => typeToDisplayParts(typeChecker, type, getContainerNode(node))), - documentation: type.symbol ? type.symbol.getDocumentationComment(typeChecker) : undefined, - tags: type.symbol ? type.symbol.getJsDocTags() : undefined - }; - } - - return undefined; + const type = shouldGetType(sourceFile, node, position) ? typeChecker.getTypeAtLocation(node) : undefined; + return type && { + kind: ScriptElementKind.unknown, + kindModifiers: ScriptElementKindModifier.none, + textSpan: createTextSpanFromNode(node, sourceFile), + displayParts: typeChecker.runWithCancellationToken(cancellationToken, typeChecker => typeToDisplayParts(typeChecker, type, getContainerNode(node))), + documentation: type.symbol ? type.symbol.getDocumentationComment(typeChecker) : undefined, + tags: type.symbol ? type.symbol.getJsDocTags() : undefined + }; } const { symbolKind, displayParts, documentation, tags } = typeChecker.runWithCancellationToken(cancellationToken, typeChecker => @@ -1489,6 +1472,23 @@ namespace ts { }; } + function shouldGetType(sourceFile: SourceFile, node: Node, position: number): boolean { + switch (node.kind) { + case SyntaxKind.Identifier: + return !isLabelName(node); + case SyntaxKind.PropertyAccessExpression: + case SyntaxKind.QualifiedName: + // Don't return quickInfo if inside the comment in `a/**/.b` + return !isInComment(sourceFile, position); + case SyntaxKind.ThisKeyword: + case SyntaxKind.ThisType: + case SyntaxKind.SuperKeyword: + return true; + default: + return false; + } + } + function getSymbolAtLocationForQuickInfo(node: Node, checker: TypeChecker): Symbol | undefined { if ((isIdentifier(node) || isStringLiteral(node)) && isPropertyAssignment(node.parent) diff --git a/tests/cases/fourslash/quickInfo_notInsideComment.ts b/tests/cases/fourslash/quickInfo_notInsideComment.ts new file mode 100644 index 00000000000..2d228479c3e --- /dev/null +++ b/tests/cases/fourslash/quickInfo_notInsideComment.ts @@ -0,0 +1,6 @@ +/// + +////a/* /**/ */.b + +goTo.marker(""); +verify.not.quickInfoExists();