@@ -53,6 +53,7 @@ import {
53
53
isClassStaticBlockDeclaration ,
54
54
isConstructorDeclaration ,
55
55
isDeclarationFileName ,
56
+ isDefaultClause ,
56
57
isExternalModuleNameRelative ,
57
58
isFunctionLike ,
58
59
isFunctionLikeDeclaration ,
@@ -69,6 +70,7 @@ import {
69
70
isPropertyName ,
70
71
isRightSideOfPropertyAccess ,
71
72
isStaticModifier ,
73
+ isSwitchStatement ,
72
74
isTypeAliasDeclaration ,
73
75
isTypeReferenceNode ,
74
76
isVariableDeclaration ,
@@ -91,6 +93,7 @@ import {
91
93
skipTrivia ,
92
94
some ,
93
95
SourceFile ,
96
+ SwitchStatement ,
94
97
Symbol ,
95
98
SymbolDisplay ,
96
99
SymbolFlags ,
@@ -105,6 +108,9 @@ import {
105
108
TypeReference ,
106
109
unescapeLeadingUnderscores ,
107
110
} from "./_namespaces/ts" ;
111
+ import {
112
+ isContextWithStartAndEndNode ,
113
+ } from "./_namespaces/ts.FindAllReferences" ;
108
114
109
115
/** @internal */
110
116
export function getDefinitionAtPosition ( program : Program , sourceFile : SourceFile , position : number , searchOtherFilesOnly ?: boolean , stopAtAlias ?: boolean ) : readonly DefinitionInfo [ ] | undefined {
@@ -133,9 +139,26 @@ export function getDefinitionAtPosition(program: Program, sourceFile: SourceFile
133
139
return label ? [ createDefinitionInfoFromName ( typeChecker , label , ScriptElementKind . label , node . text , /*containerName*/ undefined ! ) ] : undefined ; // TODO: GH#18217
134
140
}
135
141
136
- if ( node . kind === SyntaxKind . ReturnKeyword ) {
137
- const functionDeclaration = findAncestor ( node . parent , n => isClassStaticBlockDeclaration ( n ) ? "quit" : isFunctionLikeDeclaration ( n ) ) as FunctionLikeDeclaration | undefined ;
138
- return functionDeclaration ? [ createDefinitionFromSignatureDeclaration ( typeChecker , functionDeclaration ) ] : undefined ;
142
+ switch ( node . kind ) {
143
+ case SyntaxKind . ReturnKeyword :
144
+ const functionDeclaration = findAncestor ( node . parent , n =>
145
+ isClassStaticBlockDeclaration ( n )
146
+ ? "quit"
147
+ : isFunctionLikeDeclaration ( n ) ) as FunctionLikeDeclaration | undefined ;
148
+ return functionDeclaration
149
+ ? [ createDefinitionFromSignatureDeclaration ( typeChecker , functionDeclaration ) ]
150
+ : undefined ;
151
+ case SyntaxKind . DefaultKeyword :
152
+ if ( ! isDefaultClause ( node . parent ) ) {
153
+ break ;
154
+ }
155
+ // falls through
156
+ case SyntaxKind . CaseKeyword :
157
+ const switchStatement = findAncestor ( node . parent , isSwitchStatement ) ;
158
+ if ( switchStatement ) {
159
+ return [ createDefinitionInfoFromSwitch ( switchStatement , sourceFile ) ] ;
160
+ }
161
+ break ;
139
162
}
140
163
141
164
if ( node . kind === SyntaxKind . AwaitKeyword ) {
@@ -634,6 +657,24 @@ function createDefinitionInfoFromName(checker: TypeChecker, declaration: Declara
634
657
} ;
635
658
}
636
659
660
+ function createDefinitionInfoFromSwitch ( statement : SwitchStatement , sourceFile : SourceFile ) : DefinitionInfo {
661
+ const keyword = FindAllReferences . getContextNode ( statement ) ! ;
662
+ const textSpan = createTextSpanFromNode ( isContextWithStartAndEndNode ( keyword ) ? keyword . start : keyword , sourceFile ) ;
663
+ return {
664
+ fileName : sourceFile . fileName ,
665
+ textSpan,
666
+ kind : ScriptElementKind . keyword ,
667
+ name : "switch" ,
668
+ containerKind : undefined ! ,
669
+ containerName : "" ,
670
+ ...FindAllReferences . toContextSpan ( textSpan , sourceFile , keyword ) ,
671
+ isLocal : true ,
672
+ isAmbient : false ,
673
+ unverified : false ,
674
+ failedAliasResolution : undefined ,
675
+ } ;
676
+ }
677
+
637
678
function isDefinitionVisible ( checker : TypeChecker , declaration : Declaration ) : boolean {
638
679
if ( checker . isDeclarationVisible ( declaration ) ) return true ;
639
680
if ( ! declaration . parent ) return false ;
0 commit comments