Skip to content

Commit dda24f6

Browse files
committed
allow to compute change ranges only for snapshots from the same script version cache
1 parent 8e94d84 commit dda24f6

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1799,7 +1799,6 @@ namespace ts.projectSystem {
17991799
});
18001800

18011801
it("language service disabled state is updated in external projects", () => {
1802-
debugger
18031802
const f1 = {
18041803
path: "/a/app.js",
18051804
content: "var x = 1"
@@ -1940,6 +1939,32 @@ namespace ts.projectSystem {
19401939
const edits = project.getLanguageService().getFormattingEditsForDocument(f1.path, options);
19411940
assert.deepEqual(edits, [{ span: createTextSpan(/*start*/ 7, /*length*/ 3), newText: " " }]);
19421941
});
1942+
1943+
it("snapshot from different caches are incompatible", () => {
1944+
const f1 = {
1945+
path: "/a/b/app.ts",
1946+
content: "let x = 1;"
1947+
};
1948+
debugger
1949+
const host = createServerHost([f1]);
1950+
const projectFileName = "/a/b/proj.csproj";
1951+
const projectService = createProjectService(host);
1952+
projectService.openExternalProject({
1953+
projectFileName,
1954+
rootFiles: [toExternalFile(f1.path)],
1955+
options: {}
1956+
})
1957+
projectService.openClientFile(f1.path, "let x = 1;\nlet y = 2;");
1958+
1959+
projectService.checkNumberOfProjects({ externalProjects: 1 });
1960+
projectService.externalProjects[0].getLanguageService(/*ensureSynchronized*/false).getNavigationBarItems(f1.path);
1961+
projectService.closeClientFile(f1.path);
1962+
1963+
projectService.openClientFile(f1.path);
1964+
projectService.checkNumberOfProjects({ externalProjects: 1 });
1965+
const navbar = projectService.externalProjects[0].getLanguageService(/*ensureSynchronized*/false).getNavigationBarItems(f1.path);
1966+
assert.equal(navbar[0].spans[0].length, f1.content.length);
1967+
});
19431968
});
19441969

19451970
describe("Proper errors", () => {

src/server/scriptVersionCache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ namespace ts.server {
398398
index: LineIndex;
399399
changesSincePreviousVersion: TextChange[] = [];
400400

401-
constructor(public version: number, public cache: ScriptVersionCache) {
401+
constructor(readonly version: number, readonly cache: ScriptVersionCache) {
402402
}
403403

404404
getText(rangeStart: number, rangeEnd: number) {
@@ -438,7 +438,7 @@ namespace ts.server {
438438
}
439439
}
440440
getChangeRange(oldSnapshot: ts.IScriptSnapshot): ts.TextChangeRange {
441-
if (oldSnapshot instanceof LineIndexSnapshot) {
441+
if (oldSnapshot instanceof LineIndexSnapshot && this.cache === oldSnapshot.cache) {
442442
return this.getTextChangeRangeSinceVersion(oldSnapshot.version);
443443
}
444444
}

0 commit comments

Comments
 (0)