Skip to content

Commit 1d176e4

Browse files
Remove syntaxTree from SourceFileObject
1 parent 4ffd0b3 commit 1d176e4

File tree

1 file changed

+27
-45
lines changed

1 file changed

+27
-45
lines changed

src/services/services.ts

+27-45
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ module ts {
7171
}
7272

7373
export interface SourceFile {
74-
getSourceUnit(): TypeScript.SourceUnitSyntax;
75-
getSyntaxTree(): TypeScript.SyntaxTree;
7674
getScriptSnapshot(): TypeScript.IScriptSnapshot;
7775
getNamedDeclarations(): Declaration[];
7876
update(scriptSnapshot: TypeScript.IScriptSnapshot, version: string, isOpen: boolean, textChangeRange: TypeScript.TextChangeRange): SourceFile;
@@ -660,23 +658,13 @@ module ts {
660658
public languageVersion: ScriptTarget;
661659
public identifiers: Map<string>;
662660

663-
private syntaxTree: TypeScript.SyntaxTree;
664661
private scriptSnapshot: TypeScript.IScriptSnapshot;
665662
private namedDeclarations: Declaration[];
666663

667-
public getSourceUnit(): TypeScript.SourceUnitSyntax {
668-
// If we don't have a script, create one from our parse tree.
669-
return this.getSyntaxTree().sourceUnit();
670-
}
671-
672664
public getScriptSnapshot(): TypeScript.IScriptSnapshot {
673665
return this.scriptSnapshot;
674666
}
675667

676-
public getLineMap(): TypeScript.LineMap {
677-
return this.getSyntaxTree().lineMap();
678-
}
679-
680668
public getNamedDeclarations() {
681669
if (!this.namedDeclarations) {
682670
var sourceFile = this;
@@ -748,32 +736,11 @@ module ts {
748736
return this.namedDeclarations;
749737
}
750738

751-
public getSyntaxTree(): TypeScript.SyntaxTree {
752-
if (!this.syntaxTree) {
753-
var start = new Date().getTime();
754-
755-
this.syntaxTree = TypeScript.Parser.parse(
756-
this.filename, TypeScript.SimpleText.fromScriptSnapshot(this.scriptSnapshot), this.languageVersion, this.isDeclareFile());
757-
758-
var time = new Date().getTime() - start;
759-
760-
//TypeScript.syntaxTreeParseTime += time;
761-
}
762-
763-
return this.syntaxTree;
764-
}
765-
766739
private isDeclareFile(): boolean {
767740
return TypeScript.isDTSFile(this.filename);
768741
}
769742

770743
public update(scriptSnapshot: TypeScript.IScriptSnapshot, version: string, isOpen: boolean, textChangeRange: TypeScript.TextChangeRange): SourceFile {
771-
// See if we are currently holding onto a syntax tree. We may not be because we're
772-
// either a closed file, or we've just been lazy and haven't had to create the syntax
773-
// tree yet. Access the field instead of the method so we don't accidentally realize
774-
// the old syntax tree.
775-
var oldSyntaxTree = this.syntaxTree;
776-
777744
if (textChangeRange && Debug.shouldAssert(AssertionLevel.Normal)) {
778745
var oldText = this.scriptSnapshot;
779746
var newText = scriptSnapshot;
@@ -791,21 +758,12 @@ module ts {
791758
}
792759
}
793760

794-
var text = TypeScript.SimpleText.fromScriptSnapshot(scriptSnapshot);
795-
796-
// If we don't have a text change, or we don't have an old syntax tree, then do a full
797-
// parse. Otherwise, do an incremental parse.
798-
var newSyntaxTree = !textChangeRange || !oldSyntaxTree
799-
? TypeScript.Parser.parse(this.filename, text, this.languageVersion, TypeScript.isDTSFile(this.filename))
800-
: TypeScript.IncrementalParser.parse(oldSyntaxTree, textChangeRange, text);
801-
802-
return SourceFileObject.createSourceFileObject(this.filename, scriptSnapshot, this.languageVersion, version, isOpen, newSyntaxTree);
761+
return SourceFileObject.createSourceFileObject(this.filename, scriptSnapshot, this.languageVersion, version, isOpen);
803762
}
804763

805-
public static createSourceFileObject(filename: string, scriptSnapshot: TypeScript.IScriptSnapshot, languageVersion: ScriptTarget, version: string, isOpen: boolean, syntaxTree?: TypeScript.SyntaxTree) {
764+
public static createSourceFileObject(filename: string, scriptSnapshot: TypeScript.IScriptSnapshot, languageVersion: ScriptTarget, version: string, isOpen: boolean) {
806765
var newSourceFile = <SourceFileObject><any>createSourceFile(filename, scriptSnapshot.getText(0, scriptSnapshot.getLength()), languageVersion, version, isOpen);
807766
newSourceFile.scriptSnapshot = scriptSnapshot;
808-
newSourceFile.syntaxTree = syntaxTree;
809767
return newSourceFile;
810768
}
811769
}
@@ -1633,30 +1591,47 @@ module ts {
16331591
private initialize(filename: string) {
16341592
// ensure that both source file and syntax tree are either initialized or not initialized
16351593
Debug.assert(!!this.currentFileSyntaxTree === !!this.currentSourceFile);
1594+
var start = new Date().getTime();
16361595
this.hostCache = new HostCache(this.host);
1596+
this.host.log("SyntaxTreeCache.Initialize: new HostCache: " + (new Date().getTime() - start));
16371597

16381598
var version = this.hostCache.getVersion(filename);
16391599
var syntaxTree: TypeScript.SyntaxTree = null;
16401600
var sourceFile: SourceFile;
16411601

16421602
if (this.currentFileSyntaxTree === null || this.currentFilename !== filename) {
16431603
var scriptSnapshot = this.hostCache.getScriptSnapshot(filename);
1604+
var start = new Date().getTime();
16441605
syntaxTree = this.createSyntaxTree(filename, scriptSnapshot);
1606+
this.host.log("SyntaxTreeCache.Initialize: createSyntaxTree: " + (new Date().getTime() - start));
1607+
1608+
var start = new Date().getTime();
16451609
sourceFile = createSourceFileFromScriptSnapshot(filename, scriptSnapshot, getDefaultCompilerOptions(), version, /*isOpen*/ true);
1610+
this.host.log("SyntaxTreeCache.Initialize: createSourceFile: " + (new Date().getTime() - start));
16461611

1612+
var start = new Date().getTime();
16471613
fixupParentReferences(sourceFile);
1614+
this.host.log("SyntaxTreeCache.Initialize: fixupParentRefs : " + (new Date().getTime() - start));
16481615
}
16491616
else if (this.currentFileVersion !== version) {
16501617
var scriptSnapshot = this.hostCache.getScriptSnapshot(filename);
1618+
1619+
var start = new Date().getTime();
16511620
syntaxTree = this.updateSyntaxTree(filename, scriptSnapshot,
16521621
this.currentSourceFile.getScriptSnapshot(), this.currentFileSyntaxTree, this.currentFileVersion);
1622+
this.host.log("SyntaxTreeCache.Initialize: updateSyntaxTree: " + (new Date().getTime() - start));
16531623

16541624
var editRange = this.hostCache.getChangeRange(filename, this.currentFileVersion, this.currentSourceFile.getScriptSnapshot());
1625+
1626+
var start = new Date().getTime();
16551627
sourceFile = !editRange
16561628
? createSourceFileFromScriptSnapshot(filename, scriptSnapshot, getDefaultCompilerOptions(), version, /*isOpen*/ true)
16571629
: this.currentSourceFile.update(scriptSnapshot, version, /*isOpen*/ true, editRange);
1630+
this.host.log("SyntaxTreeCache.Initialize: updateSourceFile: " + (new Date().getTime() - start));
16581631

1632+
var start = new Date().getTime();
16591633
fixupParentReferences(sourceFile);
1634+
this.host.log("SyntaxTreeCache.Initialize: fixupParentRefs : " + (new Date().getTime() - start));
16601635
}
16611636

16621637
if (syntaxTree !== null) {
@@ -5050,10 +5025,17 @@ module ts {
50505025
function getIndentationAtPosition(filename: string, position: number, editorOptions: EditorOptions) {
50515026
filename = TypeScript.switchToForwardSlashes(filename);
50525027

5028+
var start = new Date().getTime();
50535029
var sourceFile = getCurrentSourceFile(filename);
5030+
host.log("getIndentationAtPosition: getCurrentSourceFile: " + (new Date().getTime() - start));
5031+
5032+
var start = new Date().getTime();
50545033
var options = new TypeScript.FormattingOptions(!editorOptions.ConvertTabsToSpaces, editorOptions.TabSize, editorOptions.IndentSize, editorOptions.NewLineCharacter)
50555034

5056-
return formatting.SmartIndenter.getIndentation(position, sourceFile, options);
5035+
var result = formatting.SmartIndenter.getIndentation(position, sourceFile, options);
5036+
host.log("getIndentationAtPosition: computeIndentation : " + (new Date().getTime() - start));
5037+
5038+
return result;
50575039
}
50585040

50595041
function getFormattingManager(filename: string, options: FormatCodeOptions) {

0 commit comments

Comments
 (0)