From c0bcf8f10cbbe8be6f5af1b690284589fc09064d Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 3 Aug 2016 13:51:20 -0700 Subject: [PATCH] release cached tree in compilation settings change --- src/harness/unittests/tsserverProjectSystem.ts | 16 ++++++++++++++++ src/server/scriptInfo.ts | 3 +++ src/server/session.ts | 5 ----- src/server/utilities.ts | 5 +++++ src/services/services.ts | 2 +- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index cf475cf394e..a5e39735eae 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -1346,5 +1346,21 @@ namespace ts { projectService.setCompilerOptionsForInferredProjects({ moduleResolution: ModuleResolutionKind.Classic }); checkNumberOfProjects(projectService, { inferredProjects: 1 }); }); + + it("syntax tree cache handles changes in project settings", () => { + const file1 = { + path: "/a/b/app.ts", + content: "{x: 1}" + }; + const host = createServerHost([file1]); + const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useSingleInferredProject*/ true); + projectService.setCompilerOptionsForInferredProjects({ target: ScriptTarget.ES5, allowJs: false }); + projectService.openClientFile(file1.path); + projectService.inferredProjects[0].getLanguageService(/*ensureSynchronized*/ false).getOutliningSpans(file1.path); + projectService.setCompilerOptionsForInferredProjects({ target: ScriptTarget.ES5, allowJs: true }); + projectService.getScriptInfo(file1.path).editContent(0, 0, " "); + projectService.inferredProjects[0].getLanguageService(/*ensureSynchronized*/ false).getOutliningSpans(file1.path); + projectService.closeClientFile(file1.path); + }); }); } \ No newline at end of file diff --git a/src/server/scriptInfo.ts b/src/server/scriptInfo.ts index 007ac81b477..a930f7fa708 100644 --- a/src/server/scriptInfo.ts +++ b/src/server/scriptInfo.ts @@ -81,6 +81,9 @@ namespace ts.server { } getDefaultProject() { + if (this.containingProjects.length === 0) { + throw Errors.NoProject; + } Debug.assert(this.containingProjects.length !== 0); return this.containingProjects[0]; } diff --git a/src/server/session.ts b/src/server/session.ts index 172f8fc93af..5b103b07056 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -146,11 +146,6 @@ namespace ts.server { export const CompilerOptionsForInferredProjects = "compilerOptionsForInferredProjects"; } - namespace Errors { - export const NoProject = new Error("No Project."); - export const ProjectLanguageServiceDisabled = new Error("The project's language service is disabled."); - } - export class Session { protected projectService: ProjectService; private errorTimer: any; /*NodeJS.Timer | number*/ diff --git a/src/server/utilities.ts b/src/server/utilities.ts index e3e6470ebf2..616286ee8bf 100644 --- a/src/server/utilities.ts +++ b/src/server/utilities.ts @@ -29,6 +29,11 @@ namespace ts.server { export type Types = Err | Info | Perf; } + export namespace Errors { + export const NoProject = new Error("No Project."); + export const ProjectLanguageServiceDisabled = new Error("The project's language service is disabled."); + } + export function getDefaultFormatCodeSettings(host: ServerHost): FormatCodeSettings { return { indentSize: 4, diff --git a/src/services/services.ts b/src/services/services.ts index e7dc25f2aaa..1c98a3b86c9 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3284,7 +3284,7 @@ namespace ts { const scriptKind = ts.getScriptKind(fileName, host); const compilerOptions = host.getCompilationSettings(); let sourceFile: SourceFile; - if (currentFileName !== fileName) { + if (currentFileName !== fileName || (currentCompilerOptions && !mapIsEqualTo(compilerOptions, currentCompilerOptions))) { // Release the current document if (currentFileName) { documentRegistry.releaseDocument(currentFileName, currentCompilerOptions);