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

Quick info on 'new' keyword should be the same as that of resolved expression #31262

Merged
merged 4 commits into from May 15, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 22 additions & 6 deletions src/services/services.ts
Expand Up @@ -1467,33 +1467,49 @@ namespace ts {
}

const typeChecker = program.getTypeChecker();
const symbol = getSymbolAtLocationForQuickInfo(node, typeChecker);
const nodeForQuickInfo = getNodeForQuickInfo(node, typeChecker);
const symbol = getSymbolAtLocationForQuickInfo(nodeForQuickInfo, typeChecker);

if (!symbol || typeChecker.isUnknownSymbol(symbol)) {
const type = shouldGetType(sourceFile, node, position) ? typeChecker.getTypeAtLocation(node) : undefined;
const type = shouldGetType(sourceFile, nodeForQuickInfo, position) ? typeChecker.getTypeAtLocation(nodeForQuickInfo) : undefined;
return type && {
kind: ScriptElementKind.unknown,
kindModifiers: ScriptElementKindModifier.none,
textSpan: createTextSpanFromNode(node, sourceFile),
displayParts: typeChecker.runWithCancellationToken(cancellationToken, typeChecker => typeToDisplayParts(typeChecker, type, getContainerNode(node))),
textSpan: createTextSpanFromNode(nodeForQuickInfo, sourceFile),
displayParts: typeChecker.runWithCancellationToken(cancellationToken, typeChecker => typeToDisplayParts(typeChecker, type, getContainerNode(nodeForQuickInfo))),
documentation: type.symbol ? type.symbol.getDocumentationComment(typeChecker) : undefined,
tags: type.symbol ? type.symbol.getJsDocTags() : undefined
};
}

const { symbolKind, displayParts, documentation, tags } = typeChecker.runWithCancellationToken(cancellationToken, typeChecker =>
SymbolDisplay.getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, getContainerNode(node), node)
SymbolDisplay.getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, getContainerNode(nodeForQuickInfo), nodeForQuickInfo)
);
return {
kind: symbolKind,
kindModifiers: SymbolDisplay.getSymbolModifiers(symbol),
textSpan: createTextSpanFromNode(node, sourceFile),
textSpan: createTextSpanFromNode(nodeForQuickInfo, sourceFile),
displayParts,
documentation,
tags,
};
}

function getNodeForQuickInfo(node: Node, typeChecker: TypeChecker): Node {
const firstParentNode = node.parent.getFirstToken();
rpgeeganage marked this conversation as resolved.
Show resolved Hide resolved
const firstNodeSyntaxKind = firstParentNode ? firstParentNode.kind : undefined;

if (node.kind === SyntaxKind.NewKeyword || firstNodeSyntaxKind === SyntaxKind.NewKeyword) {
rpgeeganage marked this conversation as resolved.
Show resolved Hide resolved
for (const singleNode of node.parent.getChildren()) {
const symbol = getSymbolAtLocationForQuickInfo(singleNode, typeChecker);
rpgeeganage marked this conversation as resolved.
Show resolved Hide resolved
if (symbol) {
return singleNode;
}
}
}
return node;
}

function shouldGetType(sourceFile: SourceFile, node: Node, position: number): boolean {
switch (node.kind) {
case SyntaxKind.Identifier:
Expand Down
70 changes: 70 additions & 0 deletions tests/baselines/reference/jsDocTags.baseline
Expand Up @@ -79,6 +79,76 @@
"marker": {
"fileName": "/tests/cases/fourslash/jsDocTags.ts",
"position": 981
},
"quickInfo": {
"kind": "constructor",
"kindModifiers": "",
"textSpan": {
"start": 977,
"length": 3
},
"displayParts": [
{
"text": "constructor",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "Foo",
"kind": "className"
},
{
"text": "(",
"kind": "punctuation"
},
{
"text": "value",
"kind": "parameterName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "number",
"kind": "keyword"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "Foo",
"kind": "className"
}
],
"documentation": [
{
"text": "This is the constructor.",
"kind": "text"
}
],
"tags": [
{
"name": "myjsdoctag",
"text": "this is a comment"
}
]
}
},
{
Expand Down
Expand Up @@ -2991,24 +2991,56 @@
"position": 337
},
"quickInfo": {
"kind": "var",
"kind": "constructor",
"kindModifiers": "",
"textSpan": {
"start": 337,
"length": 9
"start": 334,
"length": 2
},
"displayParts": [
{
"text": "var",
"text": "constructor",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "cInstance",
"kind": "localName"
"text": "c2",
"kind": "className"
},
{
"text": "<",
"kind": "punctuation"
},
{
"text": "c",
"kind": "className"
},
{
"text": "<",
"kind": "punctuation"
},
{
"text": "string",
"kind": "keyword"
},
{
"text": ">",
"kind": "punctuation"
},
{
"text": ">",
"kind": "punctuation"
},
{
"text": "(",
"kind": "punctuation"
},
{
"text": "a",
"kind": "parameterName"
},
{
"text": ":",
Expand All @@ -3030,6 +3062,46 @@
"text": "string",
"kind": "keyword"
},
{
"text": ">",
"kind": "punctuation"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "c2",
"kind": "className"
},
{
"text": "<",
"kind": "punctuation"
},
{
"text": "c",
"kind": "className"
},
{
"text": "<",
"kind": "punctuation"
},
{
"text": "string",
"kind": "keyword"
},
{
"text": ">",
"kind": "punctuation"
},
{
"text": ">",
"kind": "punctuation"
Expand Down