Skip to content

Commit 31ce6cf

Browse files
author
Andy
authored
Minor cleanups to ScriptVersionCache (microsoft#16983)
1 parent dcc3e72 commit 31ce6cf

File tree

3 files changed

+10
-22
lines changed

3 files changed

+10
-22
lines changed

src/harness/unittests/versionCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ and grew 1cm per day`;
271271
});
272272

273273
it("Edit ScriptVersionCache ", () => {
274-
const svc = server.ScriptVersionCache.fromString(<server.ServerHost>ts.sys, testContent);
274+
const svc = server.ScriptVersionCache.fromString(testContent);
275275
let checkText = testContent;
276276

277277
for (let i = 0; i < iterationCount; i++) {

src/server/scriptInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ namespace ts.server {
126126

127127
private switchToScriptVersionCache(newText?: string): ScriptVersionCache {
128128
if (!this.svc) {
129-
this.svc = ScriptVersionCache.fromString(this.host, newText !== undefined ? newText : this.getOrLoadText());
129+
this.svc = ScriptVersionCache.fromString(newText !== undefined ? newText : this.getOrLoadText());
130130
this.svcVersion++;
131131
this.text = undefined;
132132
}

src/server/scriptVersionCache.ts

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -257,16 +257,15 @@ namespace ts.server {
257257
}
258258

259259
export class ScriptVersionCache {
260-
changes: TextChange[] = [];
261-
versions: LineIndexSnapshot[] = new Array<LineIndexSnapshot>(ScriptVersionCache.maxVersions);
262-
minVersion = 0; // no versions earlier than min version will maintain change history
260+
private changes: TextChange[] = [];
261+
private readonly versions: LineIndexSnapshot[] = new Array<LineIndexSnapshot>(ScriptVersionCache.maxVersions);
262+
private minVersion = 0; // no versions earlier than min version will maintain change history
263263

264-
private host: ServerHost;
265264
private currentVersion = 0;
266265

267-
static changeNumberThreshold = 8;
268-
static changeLengthThreshold = 256;
269-
static maxVersions = 8;
266+
private static readonly changeNumberThreshold = 8;
267+
private static readonly changeLengthThreshold = 256;
268+
private static readonly maxVersions = 8;
270269

271270
private versionToIndex(version: number) {
272271
if (version < this.minVersion || version > this.currentVersion) {
@@ -300,16 +299,6 @@ namespace ts.server {
300299
return this.currentVersion;
301300
}
302301

303-
reloadFromFile(filename: string) {
304-
let content = this.host.readFile(filename);
305-
// If the file doesn't exist or cannot be read, we should
306-
// wipe out its cached content on the server to avoid side effects.
307-
if (!content) {
308-
content = "";
309-
}
310-
this.reload(content);
311-
}
312-
313302
// reload whole script, leaving no change history behind reload
314303
reload(script: string) {
315304
this.currentVersion++;
@@ -369,11 +358,10 @@ namespace ts.server {
369358
}
370359
}
371360

372-
static fromString(host: ServerHost, script: string) {
361+
static fromString(script: string) {
373362
const svc = new ScriptVersionCache();
374363
const snap = new LineIndexSnapshot(0, svc, new LineIndex());
375364
svc.versions[svc.currentVersion] = snap;
376-
svc.host = host;
377365
const lm = LineIndex.linesFromText(script);
378366
snap.index.load(lm.lines);
379367
return svc;
@@ -774,7 +762,7 @@ namespace ts.server {
774762
return { child, childIndex: i, charOffset, lineNumber };
775763
}
776764

777-
splitAfter(childIndex: number) {
765+
private splitAfter(childIndex: number) {
778766
let splitNode: LineNode;
779767
const clen = this.children.length;
780768
childIndex++;

0 commit comments

Comments
 (0)