Skip to content

Commit 66f8257

Browse files
committed
Remove isOpen from souceFile and LanugageServiceHost interfaces
1 parent 9346651 commit 66f8257

6 files changed

Lines changed: 31 additions & 68 deletions

File tree

src/harness/fourslash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,7 @@ module FourSlash {
13911391
var content = snapshot.getText(0, snapshot.getLength());
13921392

13931393
var referenceSourceFile = ts.createLanguageServiceSourceFile(
1394-
this.activeFile.fileName, createScriptSnapShot(content), ts.ScriptTarget.Latest, /*version:*/ "0", /*isOpen:*/ false, /*setNodeParents:*/ false);
1394+
this.activeFile.fileName, createScriptSnapShot(content), ts.ScriptTarget.Latest, /*version:*/ "0", /*setNodeParents:*/ false);
13951395
var referenceSyntaxDiagnostics = referenceSourceFile.getSyntacticDiagnostics();
13961396

13971397
Utils.assertDiagnosticsEquals(incrementalSyntaxDiagnostics, referenceSyntaxDiagnostics);

src/harness/harnessLanguageService.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Harness.LanguageService {
77
public editRanges: { length: number; textChangeRange: ts.TextChangeRange; }[] = [];
88
public lineMap: number[] = null;
99

10-
constructor(public fileName: string, public content: string, public isOpen = true) {
10+
constructor(public fileName: string, public content: string) {
1111
this.setContent(content);
1212
}
1313

@@ -109,11 +109,9 @@ module Harness.LanguageService {
109109
fileName: string,
110110
compilationSettings: ts.CompilerOptions,
111111
scriptSnapshot: ts.IScriptSnapshot,
112-
version: string,
113-
isOpen: boolean): ts.SourceFile {
112+
version: string): ts.SourceFile {
114113
var sourceFile = ts.createSourceFile(fileName, scriptSnapshot.getText(0, scriptSnapshot.getLength()), compilationSettings.target);
115114
sourceFile.version = version;
116-
sourceFile.isOpen = isOpen;
117115
return sourceFile;
118116
}
119117

@@ -123,10 +121,9 @@ module Harness.LanguageService {
123121
compilationSettings: ts.CompilerOptions,
124122
scriptSnapshot: ts.IScriptSnapshot,
125123
version: string,
126-
isOpen: boolean,
127124
textChangeRange: ts.TextChangeRange
128125
): ts.SourceFile {
129-
return ts.updateLanguageServiceSourceFile(document, scriptSnapshot, version, isOpen, textChangeRange);
126+
return ts.updateLanguageServiceSourceFile(document, scriptSnapshot, version, textChangeRange);
130127
}
131128

132129
public releaseDocument(fileName: string, compilationSettings: ts.CompilerOptions): void {
@@ -231,10 +228,6 @@ module Harness.LanguageService {
231228
return this.getScriptInfo(fileName).version.toString();
232229
}
233230

234-
public getScriptIsOpen(fileName: string): boolean {
235-
return this.getScriptInfo(fileName).isOpen;
236-
}
237-
238231
public getLocalizedDiagnosticMessages(): string {
239232
return JSON.stringify({});
240233
}
@@ -268,7 +261,6 @@ module Harness.LanguageService {
268261
public parseSourceText(fileName: string, sourceText: ts.IScriptSnapshot): ts.SourceFile {
269262
var result = ts.createSourceFile(fileName, sourceText.getText(0, sourceText.getLength()), ts.ScriptTarget.Latest);
270263
result.version = "1";
271-
result.isOpen = true;
272264
return result;
273265
}
274266

src/services/services.ts

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ module ts {
5656
}
5757

5858
export interface SourceFile {
59-
isOpen: boolean;
6059
version: string;
6160
scriptSnapshot: IScriptSnapshot;
6261

@@ -747,7 +746,6 @@ module ts {
747746
public identifierCount: number;
748747
public symbolCount: number;
749748
public version: string;
750-
public isOpen: boolean;
751749
public languageVersion: ScriptTarget;
752750
public identifiers: Map<string>;
753751

@@ -848,7 +846,6 @@ module ts {
848846
getCompilationSettings(): CompilerOptions;
849847
getScriptFileNames(): string[];
850848
getScriptVersion(fileName: string): string;
851-
getScriptIsOpen(fileName: string): boolean;
852849
getScriptSnapshot(fileName: string): IScriptSnapshot;
853850
getLocalizedDiagnosticMessages?(): any;
854851
getCancellationToken?(): CancellationToken;
@@ -1163,18 +1160,15 @@ module ts {
11631160
filename: string,
11641161
compilationSettings: CompilerOptions,
11651162
scriptSnapshot: IScriptSnapshot,
1166-
version: string,
1167-
isOpen: boolean): SourceFile;
1163+
version: string): SourceFile;
11681164

11691165
updateDocument(
11701166
sourceFile: SourceFile,
11711167
filename: string,
11721168
compilationSettings: CompilerOptions,
11731169
scriptSnapshot: IScriptSnapshot,
11741170
version: string,
1175-
isOpen: boolean,
1176-
textChangeRange: TextChangeRange
1177-
): SourceFile;
1171+
textChangeRange: TextChangeRange): SourceFile;
11781172

11791173
releaseDocument(filename: string, compilationSettings: CompilerOptions): void
11801174
}
@@ -1315,7 +1309,6 @@ module ts {
13151309
interface HostFileInformation {
13161310
filename: string;
13171311
version: string;
1318-
isOpen: boolean;
13191312
sourceText?: IScriptSnapshot;
13201313
}
13211314

@@ -1409,8 +1402,7 @@ module ts {
14091402
var filename = filenames[i];
14101403
this.filenameToEntry[normalizeSlashes(filename)] = {
14111404
filename: filename,
1412-
version: host.getScriptVersion(filename),
1413-
isOpen: host.getScriptIsOpen(filename)
1405+
version: host.getScriptVersion(filename)
14141406
};
14151407
}
14161408

@@ -1453,10 +1445,6 @@ module ts {
14531445
return this.getEntry(filename).version;
14541446
}
14551447

1456-
public isOpen(filename: string): boolean {
1457-
return this.getEntry(filename).isOpen;
1458-
}
1459-
14601448
public getScriptSnapshot(filename: string): IScriptSnapshot {
14611449
var file = this.getEntry(filename);
14621450
if (!file.sourceText) {
@@ -1507,7 +1495,7 @@ module ts {
15071495
var scriptSnapshot = this.hostCache.getScriptSnapshot(filename);
15081496

15091497
var start = new Date().getTime();
1510-
sourceFile = createLanguageServiceSourceFile(filename, scriptSnapshot, ScriptTarget.Latest, version, /*isOpen*/ true, /*setNodeParents;*/ true);
1498+
sourceFile = createLanguageServiceSourceFile(filename, scriptSnapshot, ScriptTarget.Latest, version, /*setNodeParents:*/ true);
15111499
this.log("SyntaxTreeCache.Initialize: createSourceFile: " + (new Date().getTime() - start));
15121500
}
15131501
else if (this.currentFileVersion !== version) {
@@ -1516,7 +1504,7 @@ module ts {
15161504
var editRange = this.hostCache.getChangeRange(filename, this.currentFileVersion, this.currentSourceFile.scriptSnapshot);
15171505

15181506
var start = new Date().getTime();
1519-
sourceFile = updateLanguageServiceSourceFile(this.currentSourceFile, scriptSnapshot, version, /*isOpen*/ true, editRange);
1507+
sourceFile = updateLanguageServiceSourceFile(this.currentSourceFile, scriptSnapshot, version, editRange);
15201508
this.log("SyntaxTreeCache.Initialize: updateSourceFile: " + (new Date().getTime() - start));
15211509
}
15221510

@@ -1538,21 +1526,20 @@ module ts {
15381526
}
15391527
}
15401528

1541-
function setSourceFileFields(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, isOpen: boolean) {
1529+
function setSourceFileFields(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string) {
15421530
sourceFile.version = version;
1543-
sourceFile.isOpen = isOpen;
15441531
sourceFile.scriptSnapshot = scriptSnapshot;
15451532
}
15461533

1547-
export function createLanguageServiceSourceFile(filename: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, isOpen: boolean, setNodeParents: boolean): SourceFile {
1534+
export function createLanguageServiceSourceFile(filename: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile {
15481535
var sourceFile = createSourceFile(filename, scriptSnapshot.getText(0, scriptSnapshot.getLength()), scriptTarget, setNodeParents);
1549-
setSourceFileFields(sourceFile, scriptSnapshot, version, isOpen);
1536+
setSourceFileFields(sourceFile, scriptSnapshot, version);
15501537
return sourceFile;
15511538
}
15521539

15531540
export var disableIncrementalParsing = false;
15541541

1555-
export function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, isOpen: boolean, textChangeRange: TextChangeRange): SourceFile {
1542+
export function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile {
15561543
if (textChangeRange && Debug.shouldAssert(AssertionLevel.Normal)) {
15571544
var oldText = sourceFile.scriptSnapshot;
15581545
var newText = scriptSnapshot;
@@ -1573,18 +1560,18 @@ module ts {
15731560
// If we were given a text change range, and our version or open-ness changed, then
15741561
// incrementally parse this file.
15751562
if (textChangeRange) {
1576-
if (version !== sourceFile.version || isOpen != sourceFile.isOpen) {
1563+
if (version !== sourceFile.version) {
15771564
// Once incremental parsing is ready, then just call into this function.
15781565
if (!disableIncrementalParsing) {
15791566
var newSourceFile = sourceFile.update(scriptSnapshot.getText(0, scriptSnapshot.getLength()), textChangeRange);
1580-
setSourceFileFields(newSourceFile, scriptSnapshot, version, isOpen);
1567+
setSourceFileFields(newSourceFile, scriptSnapshot, version);
15811568
return newSourceFile;
15821569
}
15831570
}
15841571
}
15851572

15861573
// Otherwise, just create a new source file.
1587-
return createLanguageServiceSourceFile(sourceFile.filename, scriptSnapshot, sourceFile.languageVersion, version, isOpen, /*setNodeParents:*/ true);
1574+
return createLanguageServiceSourceFile(sourceFile.filename, scriptSnapshot, sourceFile.languageVersion, version, /*setNodeParents:*/ true);
15881575
}
15891576

15901577
export function createDocumentRegistry(): DocumentRegistry {
@@ -1628,13 +1615,12 @@ module ts {
16281615
filename: string,
16291616
compilationSettings: CompilerOptions,
16301617
scriptSnapshot: IScriptSnapshot,
1631-
version: string,
1632-
isOpen: boolean): SourceFile {
1618+
version: string): SourceFile {
16331619

16341620
var bucket = getBucketForCompilationSettings(compilationSettings, /*createIfMissing*/ true);
16351621
var entry = lookUp(bucket, filename);
16361622
if (!entry) {
1637-
var sourceFile = createLanguageServiceSourceFile(filename, scriptSnapshot, compilationSettings.target, version, isOpen, /*setNodeParents:*/ false);
1623+
var sourceFile = createLanguageServiceSourceFile(filename, scriptSnapshot, compilationSettings.target, version, /*setNodeParents:*/ false);
16381624

16391625
bucket[filename] = entry = {
16401626
sourceFile: sourceFile,
@@ -1653,7 +1639,6 @@ module ts {
16531639
compilationSettings: CompilerOptions,
16541640
scriptSnapshot: IScriptSnapshot,
16551641
version: string,
1656-
isOpen: boolean,
16571642
textChangeRange: TextChangeRange
16581643
): SourceFile {
16591644

@@ -1662,7 +1647,7 @@ module ts {
16621647
var entry = lookUp(bucket, filename);
16631648
Debug.assert(entry !== undefined);
16641649

1665-
entry.sourceFile = updateLanguageServiceSourceFile(entry.sourceFile, scriptSnapshot, version, isOpen, textChangeRange);
1650+
entry.sourceFile = updateLanguageServiceSourceFile(entry.sourceFile, scriptSnapshot, version, textChangeRange);
16661651
return entry.sourceFile;
16671652
}
16681653

@@ -1962,7 +1947,7 @@ module ts {
19621947
}
19631948

19641949
function sourceFileUpToDate(sourceFile: SourceFile): boolean {
1965-
return sourceFile && sourceFile.version === hostCache.getVersion(sourceFile.filename) && sourceFile.isOpen === hostCache.isOpen(sourceFile.filename);
1950+
return sourceFile && sourceFile.version === hostCache.getVersion(sourceFile.filename);
19661951
}
19671952

19681953
function programUpToDate(): boolean {
@@ -2031,7 +2016,6 @@ module ts {
20312016
var filename = hostfilenames[i];
20322017

20332018
var version = hostCache.getVersion(filename);
2034-
var isOpen = hostCache.isOpen(filename);
20352019
var scriptSnapshot = hostCache.getScriptSnapshot(filename);
20362020

20372021
var sourceFile: SourceFile = getSourceFile(filename);
@@ -2043,21 +2027,13 @@ module ts {
20432027
continue;
20442028
}
20452029

2046-
// Only perform incremental parsing on open files that are being edited. If a file was
2047-
// open, but is now closed, we want to re-parse entirely so we don't have any tokens that
2048-
// are holding onto expensive script snapshot instances on the host. Similarly, if a
2049-
// file was closed, then we always want to re-parse. This is so our tree doesn't keep
2050-
// the old buffer alive that represented the file on disk (as the host has moved to a
2051-
// new text buffer).
20522030
var textChangeRange: TextChangeRange = null;
2053-
if (sourceFile.isOpen && isOpen) {
2054-
textChangeRange = hostCache.getChangeRange(filename, sourceFile.version, sourceFile.scriptSnapshot);
2055-
}
2031+
textChangeRange = hostCache.getChangeRange(filename, sourceFile.version, sourceFile.scriptSnapshot);
20562032

2057-
sourceFile = documentRegistry.updateDocument(sourceFile, filename, compilationSettings, scriptSnapshot, version, isOpen, textChangeRange);
2033+
sourceFile = documentRegistry.updateDocument(sourceFile, filename, compilationSettings, scriptSnapshot, version, textChangeRange);
20582034
}
20592035
else {
2060-
sourceFile = documentRegistry.acquireDocument(filename, compilationSettings, scriptSnapshot, version, isOpen);
2036+
sourceFile = documentRegistry.acquireDocument(filename, compilationSettings, scriptSnapshot, version);
20612037
}
20622038

20632039
// Remember the new sourceFile

src/services/shims.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ module ts {
5050
/** Returns a JSON-encoded value of the type: string[] */
5151
getScriptFileNames(): string;
5252
getScriptVersion(fileName: string): string;
53-
getScriptIsOpen(fileName: string): boolean;
5453
getScriptSnapshot(fileName: string): ScriptSnapshotShim;
5554
getLocalizedDiagnosticMessages(): string;
5655
getCancellationToken(): CancellationToken;
@@ -251,10 +250,6 @@ module ts {
251250
return this.shimHost.getScriptVersion(fileName);
252251
}
253252

254-
public getScriptIsOpen(fileName: string): boolean {
255-
return this.shimHost.getScriptIsOpen(fileName);
256-
}
257-
258253
public getLocalizedDiagnosticMessages(): any {
259254
var diagnosticMessagesJson = this.shimHost.getLocalizedDiagnosticMessages();
260255
if (diagnosticMessagesJson == null || diagnosticMessagesJson == "") {

tests/cases/unittests/incrementalParser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module ts {
2020
}
2121

2222
function createTree(text: IScriptSnapshot, version: string) {
23-
return createLanguageServiceSourceFile(/*fileName:*/ "", text, ScriptTarget.Latest, version, /*isOpen:*/ true, /*setNodeParents:*/ true)
23+
return createLanguageServiceSourceFile(/*fileName:*/ "", text, ScriptTarget.Latest, version, /*setNodeParents:*/ true)
2424
}
2525

2626
function assertSameDiagnostics(file1: SourceFile, file2: SourceFile) {
@@ -57,7 +57,7 @@ module ts {
5757
Utils.assertInvariants(newTree, /*parent:*/ undefined);
5858

5959
// Create a tree for the new text, in an incremental fashion.
60-
var incrementalNewTree = updateLanguageServiceSourceFile(oldTree, newText, oldTree.version + ".", /*isOpen:*/ true, textChangeRange);
60+
var incrementalNewTree = updateLanguageServiceSourceFile(oldTree, newText, oldTree.version + ".", textChangeRange);
6161
Utils.assertInvariants(incrementalNewTree, /*parent:*/ undefined);
6262

6363
// We should get the same tree when doign a full or incremental parse.

tests/cases/unittests/services/documentRegistry.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ describe("DocumentRegistry", () => {
55
var documentRegistry = ts.createDocumentRegistry();
66
var defaultCompilerOptions = ts.getDefaultCompilerOptions();
77

8-
var f1 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), "1", false);
9-
var f2 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), "1", false);
8+
var f1 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), "1");
9+
var f2 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), "1");
1010

1111
assert(f1 === f2, "DocumentRegistry should return the same document for the same name");
1212
});
@@ -17,21 +17,21 @@ describe("DocumentRegistry", () => {
1717

1818
// change compilation setting that doesn't affect parsing - should have the same document
1919
compilerOptions.declaration = true;
20-
var f1 = documentRegistry.acquireDocument("file1.ts", compilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), "1", false);
20+
var f1 = documentRegistry.acquireDocument("file1.ts", compilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), "1");
2121
compilerOptions.declaration = false;
22-
var f2 = documentRegistry.acquireDocument("file1.ts", compilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), "1", false);
22+
var f2 = documentRegistry.acquireDocument("file1.ts", compilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), "1");
2323

2424
assert(f1 === f2, "Expected to have the same document instance");
2525

2626

2727
// change value of compilation setting that is used during production of AST - new document is required
2828
compilerOptions.target = ts.ScriptTarget.ES3;
29-
var f3 = documentRegistry.acquireDocument("file1.ts", compilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), "1", false);
29+
var f3 = documentRegistry.acquireDocument("file1.ts", compilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), "1");
3030

3131
assert(f1 !== f3, "Changed target: Expected to have different instances of document");
3232

3333
compilerOptions.module = ts.ModuleKind.CommonJS;
34-
var f4 = documentRegistry.acquireDocument("file1.ts", compilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), "1", false);
34+
var f4 = documentRegistry.acquireDocument("file1.ts", compilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), "1");
3535

3636
assert(f1 !== f4, "Changed module: Expected to have different instances of document");
3737
});

0 commit comments

Comments
 (0)