Skip to content

Commit 71115fb

Browse files
authored
refactor(typescript-plugin): remove go to definition trick for auto imported components (#5733)
1 parent 50a00f6 commit 71115fb

File tree

1 file changed

+1
-62
lines changed

1 file changed

+1
-62
lines changed

packages/typescript-plugin/lib/common.ts

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function createVueLanguageServiceProxy<T>(
2121
case 'getCodeFixesAtPosition':
2222
return getCodeFixesAtPosition(target[p]);
2323
case 'getDefinitionAndBoundSpan':
24-
return getDefinitionAndBoundSpan(ts, language, asScriptId, languageService, vueOptions, target[p]);
24+
return getDefinitionAndBoundSpan(language, asScriptId, target[p]);
2525
}
2626
};
2727

@@ -190,11 +190,8 @@ function getCodeFixesAtPosition(
190190
}
191191

192192
function getDefinitionAndBoundSpan<T>(
193-
ts: typeof import('typescript'),
194193
language: Language<T>,
195194
asScriptId: (fileName: string) => T,
196-
languageService: ts.LanguageService,
197-
vueOptions: VueCompilerOptions,
198195
getDefinitionAndBoundSpan: ts.LanguageService['getDefinitionAndBoundSpan'],
199196
): ts.LanguageService['getDefinitionAndBoundSpan'] {
200197
return (fileName, position) => {
@@ -203,7 +200,6 @@ function getDefinitionAndBoundSpan<T>(
203200
return result;
204201
}
205202

206-
const program = languageService.getProgram()!;
207203
const sourceScript = language.scripts.get(asScriptId(fileName));
208204
if (!sourceScript?.generated) {
209205
return result;
@@ -237,19 +233,6 @@ function getDefinitionAndBoundSpan<T>(
237233
}
238234
}
239235

240-
for (const definition of result.definitions) {
241-
if (vueOptions.extensions.some(ext => definition.fileName.endsWith(ext))) {
242-
continue;
243-
}
244-
245-
const sourceFile = program.getSourceFile(definition.fileName);
246-
if (!sourceFile) {
247-
continue;
248-
}
249-
250-
visit(sourceFile, definition, sourceFile);
251-
}
252-
253236
for (const definition of skippedDefinitions) {
254237
definitions.delete(definition);
255238
}
@@ -258,49 +241,5 @@ function getDefinitionAndBoundSpan<T>(
258241
definitions: [...definitions],
259242
textSpan: result.textSpan,
260243
};
261-
262-
function visit(
263-
node: ts.Node,
264-
definition: ts.DefinitionInfo,
265-
sourceFile: ts.SourceFile,
266-
) {
267-
if (ts.isPropertySignature(node) && node.type) {
268-
proxy(node.name, node.type, definition, sourceFile);
269-
}
270-
else if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.type && !node.initializer) {
271-
proxy(node.name, node.type, definition, sourceFile);
272-
}
273-
else {
274-
ts.forEachChild(node, child => visit(child, definition, sourceFile));
275-
}
276-
}
277-
278-
function proxy(
279-
name: ts.PropertyName,
280-
type: ts.TypeNode,
281-
definition: ts.DefinitionInfo,
282-
sourceFile: ts.SourceFile,
283-
) {
284-
const { textSpan, fileName } = definition;
285-
const start = name.getStart(sourceFile);
286-
const end = name.getEnd();
287-
288-
if (start !== textSpan.start || end - start !== textSpan.length) {
289-
return;
290-
}
291-
292-
if (!ts.isIndexedAccessTypeNode(type)) {
293-
return;
294-
}
295-
296-
const pos = type.indexType.getStart(sourceFile);
297-
const res = getDefinitionAndBoundSpan(fileName, pos);
298-
if (res?.definitions?.length) {
299-
for (const definition of res.definitions) {
300-
definitions.add(definition);
301-
}
302-
skippedDefinitions.push(definition);
303-
}
304-
}
305244
};
306245
}

0 commit comments

Comments
 (0)