Skip to content

Commit

Permalink
fix: add *.vue to external files
Browse files Browse the repository at this point in the history
close #2271
  • Loading branch information
johnsoncodehk committed Jan 3, 2023
1 parent c97ef7c commit 1f09d1d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion vue-language-tools/typescript-vue-plugin/src/index.ts
Expand Up @@ -5,6 +5,7 @@ import * as tsFaster from '@volar/typescript-faster';

const init: ts.server.PluginModuleFactory = (modules) => {
const { typescript: ts } = modules;
const externalFiles = new Map<ts.server.Project, string[]>();
const pluginModule: ts.server.PluginModule = {
create(info) {

Expand All @@ -21,11 +22,14 @@ const init: ts.server.PluginModuleFactory = (modules) => {
scriptKind: ts.ScriptKind.Deferred,
}];
const parsed = vue.createParsedCommandLine(ts, ts.sys, projectName, extraFileExtensions);
if (!parsed.fileNames.some(fileName => fileName.endsWith('.vue'))) {
const vueFileNames = parsed.fileNames.filter(fileName => fileName.endsWith('.vue'));
if (!vueFileNames.length) {
// no vue file
return info.languageService;
}

externalFiles.set(info.project, vueFileNames);

// fix: https://github.com/johnsoncodehk/volar/issues/205
// @ts-expect-error
info.project.__vue_getScriptKind = info.project.getScriptKind;
Expand Down Expand Up @@ -87,6 +91,9 @@ const init: ts.server.PluginModuleFactory = (modules) => {
},
});
},
getExternalFiles(project) {
return externalFiles.get(project) ?? [];
},
};
return pluginModule;
};
Expand Down

0 comments on commit 1f09d1d

Please sign in to comment.