@@ -5,7 +5,23 @@ import { findChildContainingExactPosition } from './utils'
5
5
export default ( proxy : ts . LanguageService , languageService : ts . LanguageService , languageServiceHost : ts . LanguageServiceHost , c : GetConfig ) => {
6
6
proxy . getDefinitionAndBoundSpan = ( fileName , position ) => {
7
7
const prior = languageService . getDefinitionAndBoundSpan ( fileName , position )
8
- if ( ! prior ) {
8
+
9
+ if ( c ( 'removeModuleFileDefinitions' ) ) {
10
+ prior . definitions = prior . definitions ?. filter ( def => {
11
+ if (
12
+ def . kind === ts . ScriptElementKind . moduleElement &&
13
+ def . name . slice ( 1 , - 1 ) . startsWith ( '*.' ) &&
14
+ def . containerKind === undefined &&
15
+ ( def as import ( 'typescript-full' ) . DefinitionInfo ) . isAmbient
16
+ ) {
17
+ return false
18
+ }
19
+ return true
20
+ } )
21
+ }
22
+
23
+ // Definition fallbacks
24
+ if ( ! prior || prior . definitions . length === 0 ) {
9
25
const program = languageService . getProgram ( ) !
10
26
const sourceFile = program . getSourceFile ( fileName ) !
11
27
const node = findChildContainingExactPosition ( sourceFile , position )
@@ -144,20 +160,6 @@ export default (proxy: ts.LanguageService, languageService: ts.LanguageService,
144
160
prior . definitions = prior . definitions . filter ( definition => definition . containerName !== '__VLS_componentsOption' )
145
161
}
146
162
147
- if ( c ( 'removeModuleFileDefinitions' ) ) {
148
- prior . definitions = prior . definitions ?. filter ( def => {
149
- if (
150
- def . kind === ts . ScriptElementKind . moduleElement &&
151
- def . name . slice ( 1 , - 1 ) . startsWith ( '*.' ) &&
152
- def . containerKind === undefined &&
153
- def [ 'isAmbient' ]
154
- ) {
155
- return false
156
- }
157
- return true
158
- } )
159
- }
160
-
161
163
return prior
162
164
}
163
165
}
0 commit comments