Minor cleanups to ScriptVersionCache (#16983)
This commit is contained in:
parent
dcc3e72636
commit
31ce6cfba6
3 changed files with 10 additions and 22 deletions
|
@ -271,7 +271,7 @@ and grew 1cm per day`;
|
|||
});
|
||||
|
||||
it("Edit ScriptVersionCache ", () => {
|
||||
const svc = server.ScriptVersionCache.fromString(<server.ServerHost>ts.sys, testContent);
|
||||
const svc = server.ScriptVersionCache.fromString(testContent);
|
||||
let checkText = testContent;
|
||||
|
||||
for (let i = 0; i < iterationCount; i++) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -257,16 +257,15 @@ namespace ts.server {
|
|||
}
|
||||
|
||||
export class ScriptVersionCache {
|
||||
changes: TextChange[] = [];
|
||||
versions: LineIndexSnapshot[] = new Array<LineIndexSnapshot>(ScriptVersionCache.maxVersions);
|
||||
minVersion = 0; // no versions earlier than min version will maintain change history
|
||||
private changes: TextChange[] = [];
|
||||
private readonly versions: LineIndexSnapshot[] = new Array<LineIndexSnapshot>(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++;
|
||||
|
|
Loading…
Reference in a new issue