@@ -6,7 +6,7 @@ export default (proxy: ts.LanguageService, languageService: ts.LanguageService,
6
6
proxy . getDefinitionAndBoundSpan = ( fileName , position ) => {
7
7
const prior = languageService . getDefinitionAndBoundSpan ( fileName , position )
8
8
9
- if ( c ( 'removeModuleFileDefinitions' ) ) {
9
+ if ( c ( 'removeModuleFileDefinitions' ) && prior ) {
10
10
prior . definitions = prior . definitions ?. filter ( def => {
11
11
if (
12
12
def . kind === ts . ScriptElementKind . moduleElement &&
@@ -21,7 +21,7 @@ export default (proxy: ts.LanguageService, languageService: ts.LanguageService,
21
21
}
22
22
23
23
// Definition fallbacks
24
- if ( ! prior || prior . definitions . length === 0 ) {
24
+ if ( ! prior || prior . definitions ? .length === 0 ) {
25
25
const program = languageService . getProgram ( ) !
26
26
const sourceFile = program . getSourceFile ( fileName ) !
27
27
const node = findChildContainingExactPosition ( sourceFile , position )
@@ -156,8 +156,22 @@ export default (proxy: ts.LanguageService, languageService: ts.LanguageService,
156
156
return true
157
157
} )
158
158
}
159
+
159
160
if ( c ( 'removeVueComponentsOptionDefinition' ) && prior . definitions ) {
160
- prior . definitions = prior . definitions . filter ( definition => definition . containerName !== '__VLS_componentsOption' )
161
+ const program = languageService . getProgram ( ) !
162
+ const sourceFile = program . getSourceFile ( fileName ) !
163
+
164
+ const lines = sourceFile . getFullText ( ) . split ( '\n' )
165
+ const { line : curLine } = ts . getLineAndCharacterOfPosition ( sourceFile , position )
166
+
167
+ const VLS_COMPONENT_STRING = `__VLS_templateComponents`
168
+ const isTemplateComponent = lines [ curLine ] ?. startsWith ( VLS_COMPONENT_STRING )
169
+ if ( ! isTemplateComponent ) return
170
+
171
+ const componentName = lines [ curLine ] ?. match ( / \. ( \w + ) ; ? / ) ?. [ 1 ]
172
+ if ( ! componentName ) return
173
+
174
+ prior . definitions = prior . definitions . filter ( ( { name } ) => ! ( componentName === name && lines [ curLine - 2 ] === '// @ts-ignore' ) )
161
175
}
162
176
163
177
return prior
0 commit comments