Skip to content

Commit b64a4f7

Browse files
authored
fix(vue support): restore broken definitions, use more precise way to filter out components definitions (#133)
1 parent 313dd26 commit b64a4f7

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

typescript/src/definitions.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,20 @@ export default (proxy: ts.LanguageService, languageService: ts.LanguageService,
164164
const lines = sourceFile.getFullText().split('\n')
165165
const { line: curLine } = ts.getLineAndCharacterOfPosition(sourceFile, position)
166166

167-
const VLS_COMPONENT_STRING = `__VLS_templateComponents`
168-
const isTemplateComponent = lines[curLine]?.startsWith(VLS_COMPONENT_STRING)
169-
if (!isTemplateComponent) return
167+
const VLS_COMPONENT_STRINGS = ['__VLS_templateComponents', '__VLS_components']
170168

169+
const isVLSComponent = VLS_COMPONENT_STRINGS.some(VLS_COMPONENT_STRING => lines[curLine]?.startsWith(VLS_COMPONENT_STRING))
171170
const componentName = lines[curLine]?.match(/\.(\w+);?/)?.[1]
172-
if (!componentName) return
173171

174-
prior.definitions = prior.definitions.filter(({ name }) => !(componentName === name && lines[curLine - 2] === '// @ts-ignore'))
172+
prior.definitions =
173+
!isVLSComponent || !componentName
174+
? prior.definitions
175+
: prior.definitions.filter(({ name, containerName }) => {
176+
const isDefinitionInComponentsProperty = componentName === name && lines[curLine - 2] === '// @ts-ignore'
177+
const isGlobalComponent = containerName === 'GlobalComponents'
178+
179+
return !isDefinitionInComponentsProperty || isGlobalComponent
180+
})
175181
}
176182

177183
return prior

0 commit comments

Comments
 (0)