Skip to content

Commit a991673

Browse files
authored
allow to replace content of script info with empty text (#11075)
1 parent ff082eb commit a991673

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,4 +2035,33 @@ namespace ts.projectSystem {
20352035
checkProjectActualFiles(projectService.configuredProjects[0], [f1.path, t2.path]);
20362036
});
20372037
});
2038+
2039+
describe("Open-file", () => {
2040+
it("can be reloaded with empty content", () => {
2041+
const f = {
2042+
path: "/a/b/app.ts",
2043+
content: "let x = 1"
2044+
};
2045+
const projectFileName = "externalProject";
2046+
const host = createServerHost([f]);
2047+
const projectService = createProjectService(host);
2048+
// create a project
2049+
projectService.openExternalProject({ projectFileName, rootFiles: [toExternalFile(f.path)], options: {} });
2050+
projectService.checkNumberOfProjects({ externalProjects: 1 });
2051+
2052+
const p = projectService.externalProjects[0];
2053+
// force to load the content of the file
2054+
p.updateGraph();
2055+
2056+
const scriptInfo = p.getScriptInfo(f.path);
2057+
checkSnapLength(scriptInfo.snap(), f.content.length);
2058+
2059+
// open project and replace its content with empty string
2060+
projectService.openClientFile(f.path, "");
2061+
checkSnapLength(scriptInfo.snap(), 0);
2062+
});
2063+
function checkSnapLength(snap: server.LineIndexSnapshot, expectedLength: number) {
2064+
assert.equal(snap.getLength(), expectedLength, "Incorrect snapshot size");
2065+
}
2066+
});
20382067
}

src/server/editorServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ namespace ts.server {
990990
}
991991
}
992992
if (info) {
993-
if (fileContent) {
993+
if (fileContent !== undefined) {
994994
info.reload(fileContent);
995995
}
996996
if (openedByClient) {

0 commit comments

Comments
 (0)