Skip to content

Commit 798d080

Browse files
authored
mark containing project as dirty when file is closed (#12789)
* mark containing project as dirty when file is closed * remove debugger statement
1 parent a2fb5f9 commit 798d080

File tree

3 files changed

+67
-5
lines changed

3 files changed

+67
-5
lines changed

src/harness/unittests/textStorage.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ namespace ts.textStorage {
1616

1717
it("text based storage should be have exactly the same as script version cache", () => {
1818

19-
debugger
2019
const host = ts.projectSystem.createServerHost([f]);
2120

2221
const ts1 = new server.TextStorage(host, server.asNormalizedPath(f.path));

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ namespace ts.projectSystem {
140140
export interface TestServerHostCreationParameters {
141141
useCaseSensitiveFileNames?: boolean;
142142
executingFilePath?: string;
143-
libFile?: FileOrFolder;
144143
currentDirectory?: string;
145144
}
146145

@@ -1145,6 +1144,69 @@ namespace ts.projectSystem {
11451144
checkNumberOfProjects(projectService, {});
11461145
});
11471146

1147+
it("reload regular file after closing", () => {
1148+
const f1 = {
1149+
path: "/a/b/app.ts",
1150+
content: "x."
1151+
};
1152+
const f2 = {
1153+
path: "/a/b/lib.ts",
1154+
content: "let x: number;"
1155+
};
1156+
1157+
const host = createServerHost([f1, f2, libFile]);
1158+
const service = createProjectService(host);
1159+
service.openExternalProject({ projectFileName: "/a/b/project", rootFiles: toExternalFiles([f1.path, f2.path]), options: {} })
1160+
1161+
service.openClientFile(f1.path);
1162+
service.openClientFile(f2.path, "let x: string");
1163+
1164+
service.checkNumberOfProjects({ externalProjects: 1 });
1165+
checkProjectActualFiles(service.externalProjects[0], [f1.path, f2.path, libFile.path]);
1166+
1167+
const completions1 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 2);
1168+
// should contain completions for string
1169+
assert.isTrue(completions1.entries.some(e => e.name === "charAt"), "should contain 'charAt'");
1170+
assert.isFalse(completions1.entries.some(e => e.name === "toExponential"), "should not contain 'toExponential'");
1171+
1172+
service.closeClientFile(f2.path);
1173+
const completions2 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 2);
1174+
// should contain completions for string
1175+
assert.isFalse(completions2.entries.some(e => e.name === "charAt"), "should not contain 'charAt'");
1176+
assert.isTrue(completions2.entries.some(e => e.name === "toExponential"), "should contain 'toExponential'");
1177+
});
1178+
1179+
it("clear mixed content file after closing", () => {
1180+
const f1 = {
1181+
path: "/a/b/app.ts",
1182+
content: " "
1183+
};
1184+
const f2 = {
1185+
path: "/a/b/lib.html",
1186+
content: "<html/>"
1187+
};
1188+
1189+
const host = createServerHost([f1, f2, libFile]);
1190+
const service = createProjectService(host);
1191+
service.openExternalProject({ projectFileName: "/a/b/project", rootFiles: [{ fileName: f1.path }, { fileName: f2.path, hasMixedContent: true }], options: {} })
1192+
1193+
service.openClientFile(f1.path);
1194+
service.openClientFile(f2.path, "let somelongname: string");
1195+
1196+
service.checkNumberOfProjects({ externalProjects: 1 });
1197+
checkProjectActualFiles(service.externalProjects[0], [f1.path, f2.path, libFile.path]);
1198+
1199+
const completions1 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 0);
1200+
assert.isTrue(completions1.entries.some(e => e.name === "somelongname"), "should contain 'somelongname'");
1201+
1202+
service.closeClientFile(f2.path);
1203+
const completions2 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 0);
1204+
assert.isFalse(completions2.entries.some(e => e.name === "somelongname"), "should not contain 'somelongname'");
1205+
const sf2 = service.externalProjects[0].getLanguageService().getProgram().getSourceFile(f2.path);
1206+
assert.equal(sf2.text, "");
1207+
});
1208+
1209+
11481210
it("external project with included config file opened after configured project", () => {
11491211
const file1 = {
11501212
path: "/a/b/f1.ts",

src/server/scriptInfo.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ namespace ts.server {
2828
this.switchToScriptVersionCache(newText);
2929
}
3030

31-
public useText() {
31+
public useText(newText?: string) {
3232
this.svc = undefined;
33-
this.reloadFromFile();
33+
this.setText(newText);
3434
}
3535

3636
public edit(start: number, end: number, newText: string) {
@@ -199,7 +199,8 @@ namespace ts.server {
199199

200200
public close() {
201201
this.isOpen = false;
202-
this.textStorage.useText();
202+
this.textStorage.useText(this.hasMixedContent ? "" : undefined);
203+
this.markContainingProjectsAsDirty();
203204
}
204205

205206
public getSnapshot() {

0 commit comments

Comments
 (0)