@@ -64,7 +64,9 @@ import {
6464 isJSDocOverrideTag ,
6565 isJsxOpeningLikeElement ,
6666 isJumpStatementTarget ,
67+ isModifier ,
6768 isModuleSpecifierLike ,
69+ isNamedDeclaration ,
6870 isNameOfFunctionDeclaration ,
6971 isNewExpressionTarget ,
7072 isObjectBindingPattern ,
@@ -128,7 +130,10 @@ export function getDefinitionAtPosition(program: Program, sourceFile: SourceFile
128130 const typeChecker = program . getTypeChecker ( ) ;
129131
130132 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+ }
132137 }
133138
134139 // Labels
@@ -137,15 +142,8 @@ export function getDefinitionAtPosition(program: Program, sourceFile: SourceFile
137142 return label ? [ createDefinitionInfoFromName ( typeChecker , label , ScriptElementKind . label , node . text , /*containerName*/ undefined ! ) ] : undefined ; // TODO: GH#18217
138143 }
139144
145+ // for switch statments
140146 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 ;
149147 case SyntaxKind . DefaultKeyword :
150148 if ( ! isDefaultClause ( node . parent ) ) {
151149 break ;
@@ -159,16 +157,15 @@ export function getDefinitionAtPosition(program: Program, sourceFile: SourceFile
159157 break ;
160158 }
161159
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 ;
172169 }
173170
174171 if ( isStaticModifier ( node ) && isClassStaticBlockDeclaration ( node . parent ) ) {
@@ -217,6 +214,10 @@ export function getDefinitionAtPosition(program: Program, sourceFile: SourceFile
217214 }
218215 }
219216
217+ if ( isModifier ( node ) && ( isClassElement ( parent ) || isNamedDeclaration ( parent ) ) ) {
218+ symbol = parent . symbol ;
219+ }
220+
220221 // Could not find a symbol e.g. node is string or number keyword,
221222 // or the symbol was an internal symbol and does not have a declaration e.g. undefined symbol
222223 if ( ! symbol ) {
@@ -457,7 +458,11 @@ export function getTypeDefinitionAtPosition(typeChecker: TypeChecker, sourceFile
457458 if ( isImportMeta ( node . parent ) && node . parent . name === node ) {
458459 return definitionFromType ( typeChecker . getTypeAtLocation ( node . parent ) , typeChecker , node . parent , /*failedAliasResolution*/ false ) ;
459460 }
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+ }
461466 if ( ! symbol ) return undefined ;
462467
463468 const typeAtLocation = typeChecker . getTypeOfSymbolAtLocation ( symbol , node ) ;
0 commit comments