Skip to content

Commit 706ec59

Browse files
committed
feat: cleanupVueComponentCompletions
1 parent 00a0e3f commit 706ec59

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/configurationType.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,19 @@ export type Configuration = {
334334
* @default true
335335
*/
336336
miscDefinitionImprovement: boolean
337+
// todo change setting format to: vue.*
337338
/**
338339
* Removes definiion suggestion from vue `components` options.
339340
* Might be useful with [Vetur-extended goToDefinition](https://github.com/zardoy/vetur-extended/blob/main/src/gotoDefinition.ts) for components as a replacement for (https://github.com/vuejs/language-tools/issues/1245)
340341
* @default false
341342
*/
342343
removeVueComponentsOptionDefinition: boolean
344+
/**
345+
* Use `filter-all` to also exclude auto-import completions (useful for Nuxt projects)
346+
* @recommended filter-non-vue
347+
* @default disable
348+
*/
349+
cleanupVueComponentCompletions: 'disable' | 'filter-non-vue' | 'filter-all'
343350
/**
344351
* Experimental, feedback welcome
345352
* If default, namespace import or import path click resolves to .d.ts file, try to resolve .js file instead with the same name

typescript/src/completionsAtPosition.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,9 @@ export const getCompletionsAtPosition = (
254254
prior.entries = arrayMethods(prior.entries, position, sourceFile, c) ?? prior.entries
255255
prior.entries = jsdocDefault(prior.entries, position, sourceFile, languageService) ?? prior.entries
256256

257+
const isVueFileName = (fileName: string | undefined) => fileName && (fileName.endsWith('.vue.ts') || fileName.endsWith('.vue.js'))
257258
// #region Vue (Volar) specific
258-
const isVueFile = fileName.endsWith('.vue.ts') || fileName.endsWith('.vue.js')
259+
const isVueFile = isVueFileName(fileName)
259260
if (isVueFile && exactNode) {
260261
let node = ts.isIdentifier(exactNode) ? exactNode.parent : exactNode
261262
if (ts.isPropertyAssignment(node)) node = node.parent
@@ -267,6 +268,17 @@ export const getCompletionsAtPosition = (
267268
) {
268269
prior.entries = prior.entries.filter(({ name, kind }) => kind === ts.ScriptElementKind.warning || !name.startsWith('__'))
269270
}
271+
// const afterComponentsMarker = sourceFile.getFullText().lastIndexOf('/* Components */') < position
272+
const { line: curLine } = ts.getLineAndCharacterOfPosition(sourceFile, position)
273+
const lines = sourceFile.getFullText().split('\n')
274+
if (ts.isArrayLiteralExpression(node) && lines[curLine - 1] === '// @ts-ignore' && lines[curLine - 2]?.startsWith('__VLS_components')) {
275+
if (c('cleanupVueComponentCompletions') === 'filter-all') {
276+
prior.entries = []
277+
}
278+
if (c('cleanupVueComponentCompletions') === 'filter-non-vue') {
279+
prior.entries = prior.entries.filter(entry => isVueFileName(entry.symbol?.declarations?.[0]?.getSourceFile().fileName))
280+
}
281+
}
270282
}
271283
// #endregion
272284

0 commit comments

Comments
 (0)