From 31ce6cfba62fbfbbb6db4aa21252db4835951626 Mon Sep 17 00:00:00 2001 From: Andy Date: Fri, 7 Jul 2017 10:49:59 -0700 Subject: [PATCH] Minor cleanups to ScriptVersionCache (#16983) --- src/harness/unittests/versionCache.ts | 2 +- src/server/scriptInfo.ts | 2 +- src/server/scriptVersionCache.ts | 28 ++++++++------------------- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/harness/unittests/versionCache.ts b/src/harness/unittests/versionCache.ts index ca64ea1118f..d6e0a7c2278 100644 --- a/src/harness/unittests/versionCache.ts +++ b/src/harness/unittests/versionCache.ts @@ -271,7 +271,7 @@ and grew 1cm per day`; }); it("Edit ScriptVersionCache ", () => { - const svc = server.ScriptVersionCache.fromString(ts.sys, testContent); + const svc = server.ScriptVersionCache.fromString(testContent); let checkText = testContent; for (let i = 0; i < iterationCount; i++) { diff --git a/src/server/scriptInfo.ts b/src/server/scriptInfo.ts index 769c8387e43..534d73a6410 100644 --- a/src/server/scriptInfo.ts +++ b/src/server/scriptInfo.ts @@ -126,7 +126,7 @@ namespace ts.server { private switchToScriptVersionCache(newText?: string): ScriptVersionCache { if (!this.svc) { - this.svc = ScriptVersionCache.fromString(this.host, newText !== undefined ? newText : this.getOrLoadText()); + this.svc = ScriptVersionCache.fromString(newText !== undefined ? newText : this.getOrLoadText()); this.svcVersion++; this.text = undefined; } diff --git a/src/server/scriptVersionCache.ts b/src/server/scriptVersionCache.ts index 852182a87ec..e25ddf9e03b 100644 --- a/src/server/scriptVersionCache.ts +++ b/src/server/scriptVersionCache.ts @@ -257,16 +257,15 @@ namespace ts.server { } export class ScriptVersionCache { - changes: TextChange[] = []; - versions: LineIndexSnapshot[] = new Array(ScriptVersionCache.maxVersions); - minVersion = 0; // no versions earlier than min version will maintain change history + private changes: TextChange[] = []; + private readonly versions: LineIndexSnapshot[] = new Array(ScriptVersionCache.maxVersions); + private minVersion = 0; // no versions earlier than min version will maintain change history - private host: ServerHost; private currentVersion = 0; - static changeNumberThreshold = 8; - static changeLengthThreshold = 256; - static maxVersions = 8; + private static readonly changeNumberThreshold = 8; + private static readonly changeLengthThreshold = 256; + private static readonly maxVersions = 8; private versionToIndex(version: number) { if (version < this.minVersion || version > this.currentVersion) { @@ -300,16 +299,6 @@ namespace ts.server { return this.currentVersion; } - reloadFromFile(filename: string) { - let content = this.host.readFile(filename); - // If the file doesn't exist or cannot be read, we should - // wipe out its cached content on the server to avoid side effects. - if (!content) { - content = ""; - } - this.reload(content); - } - // reload whole script, leaving no change history behind reload reload(script: string) { this.currentVersion++; @@ -369,11 +358,10 @@ namespace ts.server { } } - static fromString(host: ServerHost, script: string) { + static fromString(script: string) { const svc = new ScriptVersionCache(); const snap = new LineIndexSnapshot(0, svc, new LineIndex()); svc.versions[svc.currentVersion] = snap; - svc.host = host; const lm = LineIndex.linesFromText(script); snap.index.load(lm.lines); return svc; @@ -774,7 +762,7 @@ namespace ts.server { return { child, childIndex: i, charOffset, lineNumber }; } - splitAfter(childIndex: number) { + private splitAfter(childIndex: number) { let splitNode: LineNode; const clen = this.children.length; childIndex++;