Skip to content

Commit 52f4571

Browse files
authored
Merge pull request #12926 from Microsoft/vladima/getchangerange
allow to compute change ranges only for snapshots from the same script version cache
2 parents a7c0b25 + 321b235 commit 52f4571

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 25 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,31 @@ 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+
const host = createServerHost([f1]);
1949+
const projectFileName = "/a/b/proj.csproj";
1950+
const projectService = createProjectService(host);
1951+
projectService.openExternalProject({
1952+
projectFileName,
1953+
rootFiles: [toExternalFile(f1.path)],
1954+
options: {}
1955+
})
1956+
projectService.openClientFile(f1.path, "let x = 1;\nlet y = 2;");
1957+
1958+
projectService.checkNumberOfProjects({ externalProjects: 1 });
1959+
projectService.externalProjects[0].getLanguageService(/*ensureSynchronized*/false).getNavigationBarItems(f1.path);
1960+
projectService.closeClientFile(f1.path);
1961+
1962+
projectService.openClientFile(f1.path);
1963+
projectService.checkNumberOfProjects({ externalProjects: 1 });
1964+
const navbar = projectService.externalProjects[0].getLanguageService(/*ensureSynchronized*/false).getNavigationBarItems(f1.path);
1965+
assert.equal(navbar[0].spans[0].length, f1.content.length);
1966+
});
19431967
});
19441968

19451969
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)