Skip to content

Commit d484163

Browse files
Merge pull request #31262 from rpgeeganage/new_keyword_consistent_resolve
Quick info on 'new' keyword should be the same as that of resolved expression
2 parents 9221868 + 8f209be commit d484163

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

src/services/services.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,33 +1467,41 @@ namespace ts {
14671467
}
14681468

14691469
const typeChecker = program.getTypeChecker();
1470-
const symbol = getSymbolAtLocationForQuickInfo(node, typeChecker);
1470+
const nodeForQuickInfo = getNodeForQuickInfo(node);
1471+
const symbol = getSymbolAtLocationForQuickInfo(nodeForQuickInfo, typeChecker);
14711472

14721473
if (!symbol || typeChecker.isUnknownSymbol(symbol)) {
1473-
const type = shouldGetType(sourceFile, node, position) ? typeChecker.getTypeAtLocation(node) : undefined;
1474+
const type = shouldGetType(sourceFile, nodeForQuickInfo, position) ? typeChecker.getTypeAtLocation(nodeForQuickInfo) : undefined;
14741475
return type && {
14751476
kind: ScriptElementKind.unknown,
14761477
kindModifiers: ScriptElementKindModifier.none,
1477-
textSpan: createTextSpanFromNode(node, sourceFile),
1478-
displayParts: typeChecker.runWithCancellationToken(cancellationToken, typeChecker => typeToDisplayParts(typeChecker, type, getContainerNode(node))),
1478+
textSpan: createTextSpanFromNode(nodeForQuickInfo, sourceFile),
1479+
displayParts: typeChecker.runWithCancellationToken(cancellationToken, typeChecker => typeToDisplayParts(typeChecker, type, getContainerNode(nodeForQuickInfo))),
14791480
documentation: type.symbol ? type.symbol.getDocumentationComment(typeChecker) : undefined,
14801481
tags: type.symbol ? type.symbol.getJsDocTags() : undefined
14811482
};
14821483
}
14831484

14841485
const { symbolKind, displayParts, documentation, tags } = typeChecker.runWithCancellationToken(cancellationToken, typeChecker =>
1485-
SymbolDisplay.getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, getContainerNode(node), node)
1486+
SymbolDisplay.getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, getContainerNode(nodeForQuickInfo), nodeForQuickInfo)
14861487
);
14871488
return {
14881489
kind: symbolKind,
14891490
kindModifiers: SymbolDisplay.getSymbolModifiers(symbol),
1490-
textSpan: createTextSpanFromNode(node, sourceFile),
1491+
textSpan: createTextSpanFromNode(nodeForQuickInfo, sourceFile),
14911492
displayParts,
14921493
documentation,
14931494
tags,
14941495
};
14951496
}
14961497

1498+
function getNodeForQuickInfo(node: Node): Node {
1499+
if (isNewExpression(node.parent) && node.pos === node.parent.pos) {
1500+
return node.parent.expression;
1501+
}
1502+
return node;
1503+
}
1504+
14971505
function shouldGetType(sourceFile: SourceFile, node: Node, position: number): boolean {
14981506
switch (node.kind) {
14991507
case SyntaxKind.Identifier:
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////class Cat {
4+
//// /**
5+
//// * NOTE: this constructor is private! Please use the factory function
6+
//// */
7+
//// private constructor() { }
8+
////
9+
//// static makeCat() { new Cat(); }
10+
////}
11+
////
12+
////ne/*1*/w Ca/*2*/t();
13+
14+
verify.quickInfoAt('1', 'constructor Cat(): Cat',
15+
'NOTE: this constructor is private! Please use the factory function');
16+
17+
verify.quickInfoAt('2', 'constructor Cat(): Cat',
18+
'NOTE: this constructor is private! Please use the factory function');

0 commit comments

Comments
 (0)