diff --git a/packages/typescript-plugin/lib/common.ts b/packages/typescript-plugin/lib/common.ts index 796996f7d2..fe3ad86c39 100644 --- a/packages/typescript-plugin/lib/common.ts +++ b/packages/typescript-plugin/lib/common.ts @@ -21,7 +21,7 @@ export function createVueLanguageServiceProxy( case 'getCodeFixesAtPosition': return getCodeFixesAtPosition(target[p]); case 'getDefinitionAndBoundSpan': - return getDefinitionAndBoundSpan(ts, language, asScriptId, languageService, vueOptions, target[p]); + return getDefinitionAndBoundSpan(language, asScriptId, target[p]); } }; @@ -190,11 +190,8 @@ function getCodeFixesAtPosition( } function getDefinitionAndBoundSpan( - ts: typeof import('typescript'), language: Language, asScriptId: (fileName: string) => T, - languageService: ts.LanguageService, - vueOptions: VueCompilerOptions, getDefinitionAndBoundSpan: ts.LanguageService['getDefinitionAndBoundSpan'], ): ts.LanguageService['getDefinitionAndBoundSpan'] { return (fileName, position) => { @@ -203,7 +200,6 @@ function getDefinitionAndBoundSpan( return result; } - const program = languageService.getProgram()!; const sourceScript = language.scripts.get(asScriptId(fileName)); if (!sourceScript?.generated) { return result; @@ -237,19 +233,6 @@ function getDefinitionAndBoundSpan( } } - for (const definition of result.definitions) { - if (vueOptions.extensions.some(ext => definition.fileName.endsWith(ext))) { - continue; - } - - const sourceFile = program.getSourceFile(definition.fileName); - if (!sourceFile) { - continue; - } - - visit(sourceFile, definition, sourceFile); - } - for (const definition of skippedDefinitions) { definitions.delete(definition); } @@ -258,49 +241,5 @@ function getDefinitionAndBoundSpan( definitions: [...definitions], textSpan: result.textSpan, }; - - function visit( - node: ts.Node, - definition: ts.DefinitionInfo, - sourceFile: ts.SourceFile, - ) { - if (ts.isPropertySignature(node) && node.type) { - proxy(node.name, node.type, definition, sourceFile); - } - else if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.type && !node.initializer) { - proxy(node.name, node.type, definition, sourceFile); - } - else { - ts.forEachChild(node, child => visit(child, definition, sourceFile)); - } - } - - function proxy( - name: ts.PropertyName, - type: ts.TypeNode, - definition: ts.DefinitionInfo, - sourceFile: ts.SourceFile, - ) { - const { textSpan, fileName } = definition; - const start = name.getStart(sourceFile); - const end = name.getEnd(); - - if (start !== textSpan.start || end - start !== textSpan.length) { - return; - } - - if (!ts.isIndexedAccessTypeNode(type)) { - return; - } - - const pos = type.indexType.getStart(sourceFile); - const res = getDefinitionAndBoundSpan(fileName, pos); - if (res?.definitions?.length) { - for (const definition of res.definitions) { - definitions.add(definition); - } - skippedDefinitions.push(definition); - } - } }; }