Skip to content

Commit

Permalink
Add getProjectVersion in ts service host
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyo930021 committed Oct 7, 2020
1 parent 8ee5f21 commit 25be23d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server/src/services/typescriptService/serviceHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export function getServiceHost(

let currentScriptDoc: TextDocument;

let projectVersion = 1;
const versions = new Map<string, number>();
const localScriptRegionDocuments = new Map<string, TextDocument>();
const nodeModuleSnapshots = new Map<string, ts.IScriptSnapshot>();
Expand Down Expand Up @@ -157,6 +158,7 @@ export function getServiceHost(
allChildComponentsInfo.set(filePath, childComponents);
}
versions.set(fileFsPath, (versions.get(fileFsPath) || 0) + 1);
projectVersion++;
}

return {
Expand Down Expand Up @@ -186,6 +188,7 @@ export function getServiceHost(
localScriptRegionDocuments.set(fileFsPath, currentScriptDoc);
scriptFileNameSet.add(filePath);
versions.set(fileFsPath, (versions.get(fileFsPath) || 0) + 1);
projectVersion++;
}
return {
service: jsLanguageService,
Expand All @@ -197,6 +200,7 @@ export function getServiceHost(
function updateExternalDocument(fileFsPath: string) {
const ver = versions.get(fileFsPath) || 0;
versions.set(fileFsPath, ver + 1);
projectVersion++;

// Clear cache so we read the js/ts file from file system again
if (projectFileSnapshots.has(fileFsPath)) {
Expand All @@ -206,6 +210,7 @@ export function getServiceHost(

function createLanguageServiceHost(options: ts.CompilerOptions): ts.LanguageServiceHost {
return {
getProjectVersion: () => projectVersion.toString(),
getCompilationSettings: () => options,
getScriptFileNames: () => Array.from(scriptFileNameSet),
getScriptVersion(fileName) {
Expand Down

0 comments on commit 25be23d

Please sign in to comment.