Skip to content

Commit e103692

Browse files
author
Andy
authored
Don't report quickInfo inside a comment in a PropertyAccessExpression (#25813)
1 parent bcd5652 commit e103692

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

src/services/services.ts

+26-26
Original file line numberDiff line numberDiff line change
@@ -1448,32 +1448,15 @@ namespace ts {
14481448
const symbol = getSymbolAtLocationForQuickInfo(node, typeChecker);
14491449

14501450
if (!symbol || typeChecker.isUnknownSymbol(symbol)) {
1451-
// Try getting just type at this position and show
1452-
switch (node.kind) {
1453-
case SyntaxKind.Identifier:
1454-
if (isLabelName(node)) {
1455-
// Type here will be 'any', avoid displaying this.
1456-
return undefined;
1457-
}
1458-
// falls through
1459-
case SyntaxKind.PropertyAccessExpression:
1460-
case SyntaxKind.QualifiedName:
1461-
case SyntaxKind.ThisKeyword:
1462-
case SyntaxKind.ThisType:
1463-
case SyntaxKind.SuperKeyword:
1464-
// For the identifiers/this/super etc get the type at position
1465-
const type = typeChecker.getTypeAtLocation(node);
1466-
return type && {
1467-
kind: ScriptElementKind.unknown,
1468-
kindModifiers: ScriptElementKindModifier.none,
1469-
textSpan: createTextSpanFromNode(node, sourceFile),
1470-
displayParts: typeChecker.runWithCancellationToken(cancellationToken, typeChecker => typeToDisplayParts(typeChecker, type, getContainerNode(node))),
1471-
documentation: type.symbol ? type.symbol.getDocumentationComment(typeChecker) : undefined,
1472-
tags: type.symbol ? type.symbol.getJsDocTags() : undefined
1473-
};
1474-
}
1475-
1476-
return undefined;
1451+
const type = shouldGetType(sourceFile, node, position) ? typeChecker.getTypeAtLocation(node) : undefined;
1452+
return type && {
1453+
kind: ScriptElementKind.unknown,
1454+
kindModifiers: ScriptElementKindModifier.none,
1455+
textSpan: createTextSpanFromNode(node, sourceFile),
1456+
displayParts: typeChecker.runWithCancellationToken(cancellationToken, typeChecker => typeToDisplayParts(typeChecker, type, getContainerNode(node))),
1457+
documentation: type.symbol ? type.symbol.getDocumentationComment(typeChecker) : undefined,
1458+
tags: type.symbol ? type.symbol.getJsDocTags() : undefined
1459+
};
14771460
}
14781461

14791462
const { symbolKind, displayParts, documentation, tags } = typeChecker.runWithCancellationToken(cancellationToken, typeChecker =>
@@ -1489,6 +1472,23 @@ namespace ts {
14891472
};
14901473
}
14911474

1475+
function shouldGetType(sourceFile: SourceFile, node: Node, position: number): boolean {
1476+
switch (node.kind) {
1477+
case SyntaxKind.Identifier:
1478+
return !isLabelName(node);
1479+
case SyntaxKind.PropertyAccessExpression:
1480+
case SyntaxKind.QualifiedName:
1481+
// Don't return quickInfo if inside the comment in `a/**/.b`
1482+
return !isInComment(sourceFile, position);
1483+
case SyntaxKind.ThisKeyword:
1484+
case SyntaxKind.ThisType:
1485+
case SyntaxKind.SuperKeyword:
1486+
return true;
1487+
default:
1488+
return false;
1489+
}
1490+
}
1491+
14921492
function getSymbolAtLocationForQuickInfo(node: Node, checker: TypeChecker): Symbol | undefined {
14931493
if ((isIdentifier(node) || isStringLiteral(node))
14941494
&& isPropertyAssignment(node.parent)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////a/* /**/ */.b
4+
5+
goTo.marker("");
6+
verify.not.quickInfoExists();

0 commit comments

Comments
 (0)