Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(compiler): improve performance for language service with project version #1461

Merged
merged 1 commit into from
Mar 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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