added cleanup message

This commit is contained in:
Vladimir Matveev 2016-06-17 16:22:03 -07:00
parent 6ebc8abea2
commit f34ba2df0b
4 changed files with 35 additions and 1 deletions

View File

@ -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));
}

View File

@ -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<string>;

View File

@ -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 = <protocol.GeterrRequestArgs>request.arguments;
return { response: this.getDiagnostics(geterrArgs.delay, geterrArgs.files), responseRequired: false };

View File

@ -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 {