From afb5bd2241452c66d79488bc71ebd588de2f3200 Mon Sep 17 00:00:00 2001
From: Vladimir Matveev
Date: Thu, 8 Dec 2016 23:41:48 -0800
Subject: [PATCH 1/2] mark containing project as dirty when file is closed
---
.../unittests/tsserverProjectSystem.ts | 64 ++++++++++++++++++-
src/server/scriptInfo.ts | 7 +-
2 files changed, 67 insertions(+), 4 deletions(-)
diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts
index fa4d65af4ab64..a69a226becfa2 100644
--- a/src/harness/unittests/tsserverProjectSystem.ts
+++ b/src/harness/unittests/tsserverProjectSystem.ts
@@ -140,7 +140,6 @@ namespace ts.projectSystem {
export interface TestServerHostCreationParameters {
useCaseSensitiveFileNames?: boolean;
executingFilePath?: string;
- libFile?: FileOrFolder;
currentDirectory?: string;
}
@@ -1145,6 +1144,69 @@ namespace ts.projectSystem {
checkNumberOfProjects(projectService, {});
});
+ it("reload regular file after closing", () => {
+ const f1 = {
+ path: "/a/b/app.ts",
+ content: "x."
+ };
+ const f2 = {
+ path: "/a/b/lib.ts",
+ content: "let x: number;"
+ };
+
+ const host = createServerHost([f1, f2, libFile]);
+ const service = createProjectService(host);
+ service.openExternalProject({ projectFileName: "/a/b/project", rootFiles: toExternalFiles([f1.path, f2.path]), options: {} })
+
+ service.openClientFile(f1.path);
+ service.openClientFile(f2.path, "let x: string");
+
+ service.checkNumberOfProjects({ externalProjects: 1 });
+ checkProjectActualFiles(service.externalProjects[0], [f1.path, f2.path, libFile.path]);
+
+ const completions1 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 2);
+ // should contain completions for string
+ assert.isTrue(completions1.entries.some(e => e.name === "charAt"), "should contain 'charAt'");
+ assert.isFalse(completions1.entries.some(e => e.name === "toExponential"), "should not contain 'toExponential'");
+
+ service.closeClientFile(f2.path);
+ const completions2 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 2);
+ // should contain completions for string
+ assert.isFalse(completions2.entries.some(e => e.name === "charAt"), "should not contain 'charAt'");
+ assert.isTrue(completions2.entries.some(e => e.name === "toExponential"), "should contain 'toExponential'");
+ });
+
+ it("clear mixed content file after closing", () => {
+ const f1 = {
+ path: "/a/b/app.ts",
+ content: " "
+ };
+ const f2 = {
+ path: "/a/b/lib.html",
+ content: ""
+ };
+
+ const host = createServerHost([f1, f2, libFile]);
+ const service = createProjectService(host);
+ service.openExternalProject({ projectFileName: "/a/b/project", rootFiles: [{ fileName: f1.path }, { fileName: f2.path, hasMixedContent: true }], options: {} })
+
+ service.openClientFile(f1.path);
+ service.openClientFile(f2.path, "let somelongname: string");
+
+ service.checkNumberOfProjects({ externalProjects: 1 });
+ checkProjectActualFiles(service.externalProjects[0], [f1.path, f2.path, libFile.path]);
+
+ const completions1 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 0);
+ assert.isTrue(completions1.entries.some(e => e.name === "somelongname"), "should contain 'somelongname'");
+
+ service.closeClientFile(f2.path);
+ const completions2 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 0);
+ assert.isFalse(completions2.entries.some(e => e.name === "somelongname"), "should not contain 'somelongname'");
+ const sf2 = service.externalProjects[0].getLanguageService().getProgram().getSourceFile(f2.path);
+ assert.equal(sf2.text, "");
+ });
+
+
it("external project with included config file opened after configured project", () => {
const file1 = {
path: "/a/b/f1.ts",
diff --git a/src/server/scriptInfo.ts b/src/server/scriptInfo.ts
index e8acb676f1b40..b8d22c5c56df8 100644
--- a/src/server/scriptInfo.ts
+++ b/src/server/scriptInfo.ts
@@ -28,9 +28,9 @@ namespace ts.server {
this.switchToScriptVersionCache(newText);
}
- public useText() {
+ public useText(newText?: string) {
this.svc = undefined;
- this.reloadFromFile();
+ this.setText(newText);
}
public edit(start: number, end: number, newText: string) {
@@ -199,7 +199,8 @@ namespace ts.server {
public close() {
this.isOpen = false;
- this.textStorage.useText();
+ this.textStorage.useText(this.hasMixedContent ? "" : undefined);
+ this.markContainingProjectsAsDirty();
}
public getSnapshot() {
From 862e0552282b8f5d08caec43417d46b598d52026 Mon Sep 17 00:00:00 2001
From: Vladimir Matveev
Date: Fri, 9 Dec 2016 08:04:31 -0800
Subject: [PATCH 2/2] remove debugger statement
---
src/harness/unittests/textStorage.ts | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/harness/unittests/textStorage.ts b/src/harness/unittests/textStorage.ts
index 71ce83d9ee714..b4287f2610c21 100644
--- a/src/harness/unittests/textStorage.ts
+++ b/src/harness/unittests/textStorage.ts
@@ -16,7 +16,6 @@ namespace ts.textStorage {
it("text based storage should be have exactly the same as script version cache", () => {
- debugger
const host = ts.projectSystem.createServerHost([f]);
const ts1 = new server.TextStorage(host, server.asNormalizedPath(f.path));