From f34ba2df0bdd08f4994eddd593500124768be8a6 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 17 Jun 2016 16:22:03 -0700 Subject: [PATCH] added cleanup message --- src/compiler/program.ts | 7 ++++++- src/compiler/types.ts | 1 + src/server/session.ts | 27 +++++++++++++++++++++++++++ src/services/services.ts | 1 + 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 15afbe18265..47993d14c24 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1151,7 +1151,8 @@ namespace ts { getSymbolCount: () => getDiagnosticsProducingTypeChecker().getSymbolCount(), getTypeCount: () => getDiagnosticsProducingTypeChecker().getTypeCount(), getFileProcessingDiagnostics: () => fileProcessingDiagnostics, - getResolvedTypeReferenceDirectives: () => resolvedTypeReferenceDirectives + getResolvedTypeReferenceDirectives: () => resolvedTypeReferenceDirectives, + dropDiagnosticsProducingTypeChecker }; verifyCompilerOptions(); @@ -1345,6 +1346,10 @@ namespace ts { return diagnosticsProducingTypeChecker || (diagnosticsProducingTypeChecker = createTypeChecker(program, /*produceDiagnostics:*/ true)); } + function dropDiagnosticsProducingTypeChecker() { + diagnosticsProducingTypeChecker = undefined; + } + function getTypeChecker() { return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = createTypeChecker(program, /*produceDiagnostics:*/ false)); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index db34bb7c6e8..d55541dc44f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1725,6 +1725,7 @@ namespace ts { // For testing purposes only. Should not be used by any other consumers (including the // language service). /* @internal */ getDiagnosticsProducingTypeChecker(): TypeChecker; + /* @internal */ dropDiagnosticsProducingTypeChecker(): void; /* @internal */ getClassifiableNames(): Map; diff --git a/src/server/session.ts b/src/server/session.ts index 03fee122d39..d8a4ac86516 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -142,6 +142,7 @@ namespace ts.server { export const SynchronizeProjectList = "synchronizeProjectList"; export const ApplyChangedToOpenFiles = "applyChangedToOpenFiles"; export const EncodedSemanticClassificationsFull = "encodedSemanticClassifications-full"; + export const Cleanup = "cleanup"; } namespace Errors { @@ -331,6 +332,28 @@ namespace ts.server { } } + private cleanProjects(caption: string, projects: Project[]) { + if (!projects) { + return; + } + this.projectService.log(`cleaning ${caption}`); + for (const p of projects) { + p.languageService.cleanupSemanticCache(); + } + } + + private cleanup() { + this.cleanProjects("inferred projects", this.projectService.inferredProjects); + this.cleanProjects("configured projects", this.projectService.configuredProjects); + this.cleanProjects("external projects", this.projectService.externalProjects); + if (typeof global !== "undefined" && global.gc) { + this.projectService.log(`global.gc()`); + global.gc(); + global.gc(); + global.gc(); + } + } + private getEncodedSemanticClassifications(args: protocol.FileSpanRequestArgs) { const file = normalizePath(args.file); const project = this.projectService.getProjectForFile(file); @@ -1248,6 +1271,10 @@ namespace ts.server { [CommandNames.EncodedSemanticClassificationsFull]: (request: protocol.FileSpanRequest) => { return this.requiredResponse(this.getEncodedSemanticClassifications(request.arguments)); }, + [CommandNames.Cleanup]: (request: protocol.Request) => { + this.cleanup(); + return this.requiredResponse(true); + }, [CommandNames.Geterr]: (request: protocol.Request) => { const geterrArgs = request.arguments; return { response: this.getDiagnostics(geterrArgs.delay, geterrArgs.files), responseRequired: false }; diff --git a/src/services/services.ts b/src/services/services.ts index 5e6abd886bb..ce54221fafb 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3212,6 +3212,7 @@ namespace ts { function cleanupSemanticCache(): void { // TODO: Should we jettison the program (or it's type checker) here? + program.dropDiagnosticsProducingTypeChecker(); } function dispose(): void {