Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 1 addition & 62 deletions packages/typescript-plugin/lib/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function createVueLanguageServiceProxy<T>(
case 'getCodeFixesAtPosition':
return getCodeFixesAtPosition(target[p]);
case 'getDefinitionAndBoundSpan':
return getDefinitionAndBoundSpan(ts, language, asScriptId, languageService, vueOptions, target[p]);
return getDefinitionAndBoundSpan(language, asScriptId, target[p]);
}
};

Expand Down Expand Up @@ -190,11 +190,8 @@ function getCodeFixesAtPosition(
}

function getDefinitionAndBoundSpan<T>(
ts: typeof import('typescript'),
language: Language<T>,
asScriptId: (fileName: string) => T,
languageService: ts.LanguageService,
vueOptions: VueCompilerOptions,
getDefinitionAndBoundSpan: ts.LanguageService['getDefinitionAndBoundSpan'],
): ts.LanguageService['getDefinitionAndBoundSpan'] {
return (fileName, position) => {
Expand All @@ -203,7 +200,6 @@ function getDefinitionAndBoundSpan<T>(
return result;
}

const program = languageService.getProgram()!;
const sourceScript = language.scripts.get(asScriptId(fileName));
if (!sourceScript?.generated) {
return result;
Expand Down Expand Up @@ -237,19 +233,6 @@ function getDefinitionAndBoundSpan<T>(
}
}

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);
}
Expand All @@ -258,49 +241,5 @@ function getDefinitionAndBoundSpan<T>(
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);
}
}
};
}
Loading