Skip to content

Commit

Permalink
support quickinfo and go-to-definition on typeof this (#47085)
Browse files Browse the repository at this point in the history
* support quickinfo and go-to-definition on `typeof this`

* update baseline

* move code to checkIdentifier
  • Loading branch information
Zzzen authored Feb 2, 2022
1 parent 7cc0f75 commit 880e2c0
Show file tree
Hide file tree
Showing 11 changed files with 536 additions and 25 deletions.
9 changes: 8 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25107,6 +25107,10 @@ namespace ts {
}

function checkIdentifier(node: Identifier, checkMode: CheckMode | undefined): Type {
if (isThisInTypeQuery(node)) {
return checkThisExpression(node);
}

const symbol = getResolvedSymbol(node);
if (symbol === unknownSymbol) {
return errorType;
Expand Down Expand Up @@ -41245,7 +41249,10 @@ namespace ts {
case SyntaxKind.PrivateIdentifier:
case SyntaxKind.PropertyAccessExpression:
case SyntaxKind.QualifiedName:
return getSymbolOfNameOrPropertyAccessExpression(node as EntityName | PrivateIdentifier | PropertyAccessExpression);
if (!isThisInTypeQuery(node)) {
return getSymbolOfNameOrPropertyAccessExpression(node as EntityName | PrivateIdentifier | PropertyAccessExpression);
}
// falls through

case SyntaxKind.ThisKeyword:
const container = getThisContainer(node, /*includeArrowFunctions*/ false);
Expand Down
4 changes: 2 additions & 2 deletions src/services/symbolDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace ts.SymbolDisplay {
if (typeChecker.isArgumentsSymbol(symbol)) {
return ScriptElementKind.localVariableElement;
}
if (location.kind === SyntaxKind.ThisKeyword && isExpression(location)) {
if (location.kind === SyntaxKind.ThisKeyword && isExpression(location) || isThisInTypeQuery(location)) {
return ScriptElementKind.parameterElement;
}
const flags = getCombinedLocalAndExportSymbolFlags(symbol);
Expand Down Expand Up @@ -143,7 +143,7 @@ namespace ts.SymbolDisplay {
const symbolFlags = getCombinedLocalAndExportSymbolFlags(symbol);
let symbolKind = semanticMeaning & SemanticMeaning.Value ? getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker, symbol, location) : ScriptElementKind.unknown;
let hasAddedSymbolInfo = false;
const isThisExpression = location.kind === SyntaxKind.ThisKeyword && isInExpressionContext(location);
const isThisExpression = location.kind === SyntaxKind.ThisKeyword && isInExpressionContext(location) || isThisInTypeQuery(location);
let type: Type | undefined;
let printer: Printer;
let documentationFromAlias: SymbolDisplayPart[] | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class C {

d: typeof this.z; // error
>d : Symbol(C.d, Decl(initializerReferencingConstructorLocals.ts, 5, 15))
>this : Symbol(C, Decl(initializerReferencingConstructorLocals.ts, 0, 0))

constructor(x) {
>x : Symbol(x, Decl(initializerReferencingConstructorLocals.ts, 7, 16))
Expand All @@ -40,6 +41,7 @@ class D<T> {

d: typeof this.z; // error
>d : Symbol(D.d, Decl(initializerReferencingConstructorLocals.ts, 15, 15))
>this : Symbol(D, Decl(initializerReferencingConstructorLocals.ts, 10, 1))

constructor(x: T) {
>x : Symbol(x, Decl(initializerReferencingConstructorLocals.ts, 17, 16))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class C {
d: typeof this.z; // error
>d : any
>this.z : any
>this : any
>this : this
>z : any

constructor(x) {
Expand Down Expand Up @@ -54,7 +54,7 @@ class D<T> {
d: typeof this.z; // error
>d : any
>this.z : any
>this : any
>this : this
>z : any

constructor(x: T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class E {
b: typeof this.x; // ok
>b : Symbol(E.b, Decl(initializerReferencingConstructorParameters.ts, 15, 15))
>this.x : Symbol(E.x, Decl(initializerReferencingConstructorParameters.ts, 17, 16))
>this : Symbol(E, Decl(initializerReferencingConstructorParameters.ts, 12, 1))
>x : Symbol(E.x, Decl(initializerReferencingConstructorParameters.ts, 17, 16))

constructor(public x) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class E {
b: typeof this.x; // ok
>b : any
>this.x : any
>this : any
>this : this
>x : any

constructor(public x) { }
Expand Down
Loading

0 comments on commit 880e2c0

Please sign in to comment.