Skip to content

Commit

Permalink
fix(typescript-plugin): custom extensions do not work
Browse files Browse the repository at this point in the history
close #3977
  • Loading branch information
johnsoncodehk committed Mar 5, 2024
1 parent f060765 commit 408c4de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 8 additions & 2 deletions packages/component-meta/lib/base.ts
Expand Up @@ -71,6 +71,7 @@ function createCheckerWorker(
let projectVersion = 0;

const scriptSnapshots = new Map<string, ts.IScriptSnapshot>();
const resolvedVueOptions = vue.resolveVueCompilerOptions(parsedCommandLine.vueOptions);
const _host: vue.TypeScriptProjectHost = {
getCurrentDirectory: () => rootPath,
getProjectVersion: () => projectVersion.toString(),
Expand All @@ -86,11 +87,16 @@ function createCheckerWorker(
}
return scriptSnapshots.get(fileName);
},
getLanguageId: vue.resolveCommonLanguageId,
getLanguageId: fileName => {
if (resolvedVueOptions.extensions.some(ext => fileName.endsWith(ext))) {
return 'vue';
}
return vue.resolveCommonLanguageId(fileName);
},
};

return {
...baseCreate(ts, configFileName, _host, vue.resolveVueCompilerOptions(parsedCommandLine.vueOptions), checkerOptions, globalComponentName),
...baseCreate(ts, configFileName, _host, resolvedVueOptions, checkerOptions, globalComponentName),
updateFile(fileName: string, text: string) {
fileName = fileName.replace(windowsPathReg, '/');
scriptSnapshots.set(fileName, ts.ScriptSnapshot.fromString(text));
Expand Down
10 changes: 9 additions & 1 deletion packages/typescript-plugin/index.ts
Expand Up @@ -57,7 +57,11 @@ function createLanguageServicePlugin(): ts.server.PluginModuleFactory {
fileName => {
const snapshot = getScriptSnapshot(fileName);
if (snapshot) {
files.set(fileName, resolveCommonLanguageId(fileName), snapshot);
let languageId = resolveCommonLanguageId(fileName);
if (extensions.some(ext => fileName.endsWith(ext))) {
languageId = 'vue';
}
files.set(fileName, languageId, snapshot);
}
else {
files.delete(fileName);
Expand Down Expand Up @@ -219,6 +223,10 @@ function createLanguageServicePlugin(): ts.server.PluginModuleFactory {
) {
const oldFiles = externalFiles.get(project);
const newFiles = new Set(searchExternalFiles(ts, project, projectExternalFileExtensions.get(project)!));
console.log('volar-search vue files');
for (const file of newFiles) {
console.log(file);
}
externalFiles.set(project, newFiles);
if (oldFiles && !twoSetsEqual(oldFiles, newFiles)) {
for (const oldFile of oldFiles) {
Expand Down

0 comments on commit 408c4de

Please sign in to comment.