release cached tree in compilation settings change

This commit is contained in:
Vladimir Matveev
2016-08-03 14:02:37 -07:00
parent de37f35f7c
commit c0bcf8f10c
5 changed files with 25 additions and 6 deletions
@@ -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);
});
});
}
+3
View File
@@ -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];
}
-5
View File
@@ -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*/
+5
View File
@@ -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,
+1 -1
View File
@@ -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);