@@ -64,7 +64,9 @@ import {
64
64
isJSDocOverrideTag ,
65
65
isJsxOpeningLikeElement ,
66
66
isJumpStatementTarget ,
67
+ isModifier ,
67
68
isModuleSpecifierLike ,
69
+ isNamedDeclaration ,
68
70
isNameOfFunctionDeclaration ,
69
71
isNewExpressionTarget ,
70
72
isObjectBindingPattern ,
@@ -128,7 +130,10 @@ export function getDefinitionAtPosition(program: Program, sourceFile: SourceFile
128
130
const typeChecker = program . getTypeChecker ( ) ;
129
131
130
132
if ( node . kind === SyntaxKind . OverrideKeyword || ( isIdentifier ( node ) && isJSDocOverrideTag ( parent ) && parent . tagName === node ) ) {
131
- return getDefinitionFromOverriddenMember ( typeChecker , node ) || emptyArray ;
133
+ const def = getDefinitionFromOverriddenMember ( typeChecker , node ) ;
134
+ if ( def !== undefined || node . kind !== SyntaxKind . OverrideKeyword ) {
135
+ return def || emptyArray ;
136
+ }
132
137
}
133
138
134
139
// Labels
@@ -137,15 +142,8 @@ export function getDefinitionAtPosition(program: Program, sourceFile: SourceFile
137
142
return label ? [ createDefinitionInfoFromName ( typeChecker , label , ScriptElementKind . label , node . text , /*containerName*/ undefined ! ) ] : undefined ; // TODO: GH#18217
138
143
}
139
144
145
+ // for switch statments
140
146
switch ( node . kind ) {
141
- case SyntaxKind . ReturnKeyword :
142
- const functionDeclaration = findAncestor ( node . parent , n =>
143
- isClassStaticBlockDeclaration ( n )
144
- ? "quit"
145
- : isFunctionLikeDeclaration ( n ) ) as FunctionLikeDeclaration | undefined ;
146
- return functionDeclaration
147
- ? [ createDefinitionFromSignatureDeclaration ( typeChecker , functionDeclaration ) ]
148
- : undefined ;
149
147
case SyntaxKind . DefaultKeyword :
150
148
if ( ! isDefaultClause ( node . parent ) ) {
151
149
break ;
@@ -159,16 +157,15 @@ export function getDefinitionAtPosition(program: Program, sourceFile: SourceFile
159
157
break ;
160
158
}
161
159
162
- if ( node . kind === SyntaxKind . AwaitKeyword ) {
163
- const functionDeclaration = findAncestor ( node , n => isFunctionLikeDeclaration ( n ) ) ;
164
- const isAsyncFunction = functionDeclaration && some ( functionDeclaration . modifiers , node => node . kind === SyntaxKind . AsyncKeyword ) ;
165
- return isAsyncFunction ? [ createDefinitionFromSignatureDeclaration ( typeChecker , functionDeclaration ) ] : undefined ;
166
- }
167
-
168
- if ( node . kind === SyntaxKind . YieldKeyword ) {
169
- const functionDeclaration = findAncestor ( node , n => isFunctionLikeDeclaration ( n ) ) ;
170
- const isGeneratorFunction = functionDeclaration && functionDeclaration . asteriskToken ;
171
- return isGeneratorFunction ? [ createDefinitionFromSignatureDeclaration ( typeChecker , functionDeclaration ) ] : undefined ;
160
+ // for keywords related to function or method definitions
161
+ let findFunctionDecl : ( ( n : Node ) => boolean | "quit" ) | undefined ;
162
+ switch ( node . kind ) {
163
+ case SyntaxKind . ReturnKeyword :
164
+ case SyntaxKind . AwaitKeyword :
165
+ case SyntaxKind . YieldKeyword :
166
+ findFunctionDecl = isFunctionLikeDeclaration ;
167
+ const functionDeclaration = findAncestor ( node , findFunctionDecl ) as FunctionLikeDeclaration | undefined ;
168
+ return functionDeclaration ? [ createDefinitionFromSignatureDeclaration ( typeChecker , functionDeclaration ) ] : undefined ;
172
169
}
173
170
174
171
if ( isStaticModifier ( node ) && isClassStaticBlockDeclaration ( node . parent ) ) {
@@ -217,6 +214,10 @@ export function getDefinitionAtPosition(program: Program, sourceFile: SourceFile
217
214
}
218
215
}
219
216
217
+ if ( isModifier ( node ) && ( isClassElement ( parent ) || isNamedDeclaration ( parent ) ) ) {
218
+ symbol = parent . symbol ;
219
+ }
220
+
220
221
// Could not find a symbol e.g. node is string or number keyword,
221
222
// or the symbol was an internal symbol and does not have a declaration e.g. undefined symbol
222
223
if ( ! symbol ) {
@@ -457,7 +458,11 @@ export function getTypeDefinitionAtPosition(typeChecker: TypeChecker, sourceFile
457
458
if ( isImportMeta ( node . parent ) && node . parent . name === node ) {
458
459
return definitionFromType ( typeChecker . getTypeAtLocation ( node . parent ) , typeChecker , node . parent , /*failedAliasResolution*/ false ) ;
459
460
}
460
- const { symbol, failedAliasResolution } = getSymbol ( node , typeChecker , /*stopAtAlias*/ false ) ;
461
+ let { symbol, failedAliasResolution } = getSymbol ( node , typeChecker , /*stopAtAlias*/ false ) ;
462
+ if ( isModifier ( node ) && ( isClassElement ( node . parent ) || isNamedDeclaration ( node . parent ) ) ) {
463
+ symbol = node . parent . symbol ;
464
+ failedAliasResolution = false ;
465
+ }
461
466
if ( ! symbol ) return undefined ;
462
467
463
468
const typeAtLocation = typeChecker . getTypeOfSymbolAtLocation ( symbol , node ) ;
0 commit comments