Skip to content

Commit

Permalink
fix: cannot watch external file change
Browse files Browse the repository at this point in the history
close #1343
  • Loading branch information
johnsoncodehk committed May 28, 2022
1 parent 43c681c commit 841562c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/vue-language-server/src/project.ts
Expand Up @@ -60,6 +60,7 @@ export async function createProject(

const scripts = shared.createPathMap<{
version: number,
fileName: string,
snapshot: ts.IScriptSnapshot | undefined,
snapshotVersion: number | undefined,
}>();
Expand Down Expand Up @@ -135,7 +136,7 @@ export async function createProject(

const script = scripts.uriGet(change.uri);

if (script && change.type === vscode.FileChangeType.Changed) {
if (script && (change.type === vscode.FileChangeType.Changed || change.type === vscode.FileChangeType.Created)) {
if (script.version >= 0) {
script.version = -1;
}
Expand Down Expand Up @@ -188,7 +189,13 @@ export async function createProject(
getDefaultLibFileName: options => ts.getDefaultLibFilePath(options), // TODO: vscode option for ts lib
getProjectVersion: () => projectVersion.toString(),
getTypeRootsVersion: () => typeRootVersion,
getScriptFileNames: () => parsedCommandLine.fileNames,
getScriptFileNames: () => {
const fileNames = new Set([...parsedCommandLine.fileNames]);
for (const script of scripts.values()) {
fileNames.add(script.fileName);
}
return [...fileNames];
},
getCompilationSettings: () => parsedCommandLine.options,
getVueCompilationSettings: () => parsedCommandLine.vueOptions,
getScriptVersion,
Expand All @@ -202,8 +209,7 @@ export async function createProject(
return host;

function getScriptVersion(fileName: string) {
return scripts.fsPathGet(fileName)?.version.toString()
?? '';
return scripts.fsPathGet(fileName)?.version.toString() ?? '';
}
function getScriptSnapshot(fileName: string) {
const script = scripts.fsPathGet(fileName);
Expand All @@ -220,6 +226,7 @@ export async function createProject(
else {
scripts.fsPathSet(fileName, {
version: -1,
fileName: fileName,
snapshot: snapshot,
snapshotVersion: -1,
});
Expand Down

0 comments on commit 841562c

Please sign in to comment.