Skip to content

Commit

Permalink
chore(compiler): improve performance for language service (#1461)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnpnl authored Mar 29, 2020
1 parent 455ee5b commit c10ad4a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/compiler/language-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const compileUsingLanguageService = (
call: null,
[LogContexts.logLevel]: LogLevels.trace,
}
let projectVersion = 1
// Set the file contents into cache.
const updateMemoryCache = (code: string, fileName: string) => {
logger.debug({ fileName }, `updateMemoryCache(): update memory cache for language service`)
Expand All @@ -38,10 +39,13 @@ export const compileUsingLanguageService = (
}
if (memoryCache.contents[fileName] !== code) {
memoryCache.contents[fileName] = code
memoryCache.versions[fileName] = (memoryCache.versions[fileName] || 0) + 1
memoryCache.versions[fileName] = fileVersion + 1
// Increment project version for every file change.
projectVersion++
}
}
const serviceHost: _ts.LanguageServiceHost = {
getProjectVersion: () => String(projectVersion),
getScriptFileNames: () => Object.keys(memoryCache.versions),
getScriptVersion: (fileName: string) => {
const normalizedFileName = normalize(fileName),
Expand Down

0 comments on commit c10ad4a

Please sign in to comment.