mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Restore useText
This commit is contained in:
@@ -64,7 +64,8 @@ namespace ts.server {
|
||||
this.switchToScriptVersionCache();
|
||||
}
|
||||
|
||||
public useText_TestOnly(newText?: string) {
|
||||
/** Public for testing */
|
||||
public useText(newText?: string) {
|
||||
this.svc = undefined;
|
||||
this.text = newText;
|
||||
this.lineMap = undefined;
|
||||
@@ -90,22 +91,13 @@ namespace ts.server {
|
||||
// Reload always has fresh content
|
||||
this.pendingReloadFromDisk = false;
|
||||
|
||||
// We only need both this.text and this.fileSize if this.text
|
||||
// is artificially empty because it was too large.
|
||||
// We assume that an empty string passed to reload is not
|
||||
// for a file that was too large to store.
|
||||
this.fileSize = undefined;
|
||||
|
||||
// If text changed set the text
|
||||
// This also ensures that if we had switched to version cache,
|
||||
// we are switching back to text.
|
||||
// The change to version cache will happen when needed
|
||||
// Thus avoiding the computation if there are no changes
|
||||
if (this.text !== newText) {
|
||||
this.text = newText;
|
||||
this.version.text++;
|
||||
this.svc = undefined;
|
||||
this.lineMap = undefined;
|
||||
this.useText(newText);
|
||||
// We cant guarantee new text is own file text
|
||||
this.ownFileText = false;
|
||||
return true;
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace ts.textStorage {
|
||||
const ts2 = new server.TextStorage(host, server.asNormalizedPath(f.path), /*initialVersion*/ undefined, /*info*/undefined!);
|
||||
|
||||
ts1.useScriptVersionCache_TestOnly();
|
||||
ts2.useText_TestOnly();
|
||||
ts2.useText();
|
||||
|
||||
const lineMap = computeLineStarts(f.content);
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace ts.textStorage {
|
||||
ts1.edit(0, 5, " ");
|
||||
assert.isTrue(ts1.hasScriptVersionCache_TestOnly(), "have script version cache - 1");
|
||||
|
||||
ts1.useText_TestOnly();
|
||||
ts1.useText();
|
||||
assert.isFalse(ts1.hasScriptVersionCache_TestOnly(), "should not have script version cache - 2");
|
||||
|
||||
ts1.getLineInfo(0);
|
||||
@@ -77,7 +77,7 @@ namespace ts.textStorage {
|
||||
// Since script info is not used in these tests, just cheat by passing undefined
|
||||
const ts1 = new server.TextStorage(host, server.asNormalizedPath(f.path), /*initialVersion*/ undefined, /*info*/undefined!);
|
||||
|
||||
ts1.useText_TestOnly(f.content);
|
||||
ts1.useText(f.content);
|
||||
assert.isFalse(ts1.hasScriptVersionCache_TestOnly());
|
||||
|
||||
assert.strictEqual(f.content.length, ts1.getTelemetryFileSize());
|
||||
|
||||
Reference in New Issue
Block a user