Merge pull request #12926 from Microsoft/vladima/getchangerange

allow to compute change ranges only for snapshots from the same script version cache
This commit is contained in:
Mohamed Hegazy 2016-12-14 15:11:20 -08:00 committed by GitHub
commit 52f4571497
2 changed files with 27 additions and 3 deletions

View File

@ -1799,7 +1799,6 @@ namespace ts.projectSystem {
});
it("language service disabled state is updated in external projects", () => {
debugger
const f1 = {
path: "/a/app.js",
content: "var x = 1"
@ -1940,6 +1939,31 @@ namespace ts.projectSystem {
const edits = project.getLanguageService().getFormattingEditsForDocument(f1.path, options);
assert.deepEqual(edits, [{ span: createTextSpan(/*start*/ 7, /*length*/ 3), newText: " " }]);
});
it("snapshot from different caches are incompatible", () => {
const f1 = {
path: "/a/b/app.ts",
content: "let x = 1;"
};
const host = createServerHost([f1]);
const projectFileName = "/a/b/proj.csproj";
const projectService = createProjectService(host);
projectService.openExternalProject({
projectFileName,
rootFiles: [toExternalFile(f1.path)],
options: {}
})
projectService.openClientFile(f1.path, "let x = 1;\nlet y = 2;");
projectService.checkNumberOfProjects({ externalProjects: 1 });
projectService.externalProjects[0].getLanguageService(/*ensureSynchronized*/false).getNavigationBarItems(f1.path);
projectService.closeClientFile(f1.path);
projectService.openClientFile(f1.path);
projectService.checkNumberOfProjects({ externalProjects: 1 });
const navbar = projectService.externalProjects[0].getLanguageService(/*ensureSynchronized*/false).getNavigationBarItems(f1.path);
assert.equal(navbar[0].spans[0].length, f1.content.length);
});
});
describe("Proper errors", () => {

View File

@ -398,7 +398,7 @@ namespace ts.server {
index: LineIndex;
changesSincePreviousVersion: TextChange[] = [];
constructor(public version: number, public cache: ScriptVersionCache) {
constructor(readonly version: number, readonly cache: ScriptVersionCache) {
}
getText(rangeStart: number, rangeEnd: number) {
@ -438,7 +438,7 @@ namespace ts.server {
}
}
getChangeRange(oldSnapshot: ts.IScriptSnapshot): ts.TextChangeRange {
if (oldSnapshot instanceof LineIndexSnapshot) {
if (oldSnapshot instanceof LineIndexSnapshot && this.cache === oldSnapshot.cache) {
return this.getTextChangeRangeSinceVersion(oldSnapshot.version);
}
}