Get quickInfo from a contextual type if possible (#18119)

This commit is contained in:
Andy
2017-09-07 07:22:39 -07:00
committed by GitHub
parent 8c714c3651
commit 0434fe797a
6 changed files with 56 additions and 28 deletions

View File

@@ -744,6 +744,7 @@ namespace ts {
;
export interface PropertyAssignment extends ObjectLiteralElement {
parent: ObjectLiteralExpression;
kind: SyntaxKind.PropertyAssignment;
name: PropertyName;
questionToken?: QuestionToken;
@@ -751,6 +752,7 @@ namespace ts {
}
export interface ShorthandPropertyAssignment extends ObjectLiteralElement {
parent: ObjectLiteralExpression;
kind: SyntaxKind.ShorthandPropertyAssignment;
name: Identifier;
questionToken?: QuestionToken;
@@ -761,6 +763,7 @@ namespace ts {
}
export interface SpreadAssignment extends ObjectLiteralElement {
parent: ObjectLiteralExpression;
kind: SyntaxKind.SpreadAssignment;
expression: Expression;
}

View File

@@ -1398,7 +1398,7 @@ namespace ts {
}
const typeChecker = program.getTypeChecker();
const symbol = typeChecker.getSymbolAtLocation(node);
const symbol = getSymbolAtLocationForQuickInfo(node, typeChecker);
if (!symbol || typeChecker.isUnknownSymbol(symbol)) {
// Try getting just type at this position and show
@@ -1437,6 +1437,21 @@ namespace ts {
};
}
function getSymbolAtLocationForQuickInfo(node: Node, checker: TypeChecker): Symbol | undefined {
if ((isIdentifier(node) || isStringLiteral(node))
&& isPropertyAssignment(node.parent)
&& node.parent.name === node) {
const type = checker.getContextualType(node.parent.parent);
if (type) {
const property = checker.getPropertyOfType(type, getTextOfIdentifierOrLiteral(node));
if (property) {
return property;
}
}
}
return checker.getSymbolAtLocation(node);
}
/// Goto definition
function getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[] {
synchronizeHostData();