Skip to content

Commit 8c7fd3c

Browse files
Merge pull request #985 from Microsoft/removeSyntaxTree
Remove syntaxTree from SourceFileObject
2 parents b187a0a + 1d176e4 commit 8c7fd3c

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;
@@ -749,32 +737,11 @@ module ts {
749737
return this.namedDeclarations;
750738
}
751739

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

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

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

806-
public static createSourceFileObject(filename: string, scriptSnapshot: TypeScript.IScriptSnapshot, languageVersion: ScriptTarget, version: string, isOpen: boolean, syntaxTree?: TypeScript.SyntaxTree) {
765+
public static createSourceFileObject(filename: string, scriptSnapshot: TypeScript.IScriptSnapshot, languageVersion: ScriptTarget, version: string, isOpen: boolean) {
807766
var newSourceFile = <SourceFileObject><any>createSourceFile(filename, scriptSnapshot.getText(0, scriptSnapshot.getLength()), languageVersion, version, isOpen);
808767
newSourceFile.scriptSnapshot = scriptSnapshot;
809-
newSourceFile.syntaxTree = syntaxTree;
810768
return newSourceFile;
811769
}
812770
}
@@ -1637,30 +1595,47 @@ module ts {
16371595
private initialize(filename: string) {
16381596
// ensure that both source file and syntax tree are either initialized or not initialized
16391597
Debug.assert(!!this.currentFileSyntaxTree === !!this.currentSourceFile);
1598+
var start = new Date().getTime();
16401599
this.hostCache = new HostCache(this.host);
1600+
this.host.log("SyntaxTreeCache.Initialize: new HostCache: " + (new Date().getTime() - start));
16411601

16421602
var version = this.hostCache.getVersion(filename);
16431603
var syntaxTree: TypeScript.SyntaxTree = null;
16441604
var sourceFile: SourceFile;
16451605

16461606
if (this.currentFileSyntaxTree === null || this.currentFilename !== filename) {
16471607
var scriptSnapshot = this.hostCache.getScriptSnapshot(filename);
1608+
var start = new Date().getTime();
16481609
syntaxTree = this.createSyntaxTree(filename, scriptSnapshot);
1610+
this.host.log("SyntaxTreeCache.Initialize: createSyntaxTree: " + (new Date().getTime() - start));
1611+
1612+
var start = new Date().getTime();
16491613
sourceFile = createSourceFileFromScriptSnapshot(filename, scriptSnapshot, getDefaultCompilerOptions(), version, /*isOpen*/ true);
1614+
this.host.log("SyntaxTreeCache.Initialize: createSourceFile: " + (new Date().getTime() - start));
16501615

1616+
var start = new Date().getTime();
16511617
fixupParentReferences(sourceFile);
1618+
this.host.log("SyntaxTreeCache.Initialize: fixupParentRefs : " + (new Date().getTime() - start));
16521619
}
16531620
else if (this.currentFileVersion !== version) {
16541621
var scriptSnapshot = this.hostCache.getScriptSnapshot(filename);
1622+
1623+
var start = new Date().getTime();
16551624
syntaxTree = this.updateSyntaxTree(filename, scriptSnapshot,
16561625
this.currentSourceFile.getScriptSnapshot(), this.currentFileSyntaxTree, this.currentFileVersion);
1626+
this.host.log("SyntaxTreeCache.Initialize: updateSyntaxTree: " + (new Date().getTime() - start));
16571627

16581628
var editRange = this.hostCache.getChangeRange(filename, this.currentFileVersion, this.currentSourceFile.getScriptSnapshot());
1629+
1630+
var start = new Date().getTime();
16591631
sourceFile = !editRange
16601632
? createSourceFileFromScriptSnapshot(filename, scriptSnapshot, getDefaultCompilerOptions(), version, /*isOpen*/ true)
16611633
: this.currentSourceFile.update(scriptSnapshot, version, /*isOpen*/ true, editRange);
1634+
this.host.log("SyntaxTreeCache.Initialize: updateSourceFile: " + (new Date().getTime() - start));
16621635

1636+
var start = new Date().getTime();
16631637
fixupParentReferences(sourceFile);
1638+
this.host.log("SyntaxTreeCache.Initialize: fixupParentRefs : " + (new Date().getTime() - start));
16641639
}
16651640

16661641
if (syntaxTree !== null) {
@@ -5066,10 +5041,17 @@ module ts {
50665041
function getIndentationAtPosition(filename: string, position: number, editorOptions: EditorOptions) {
50675042
filename = TypeScript.switchToForwardSlashes(filename);
50685043

5044+
var start = new Date().getTime();
50695045
var sourceFile = getCurrentSourceFile(filename);
5046+
host.log("getIndentationAtPosition: getCurrentSourceFile: " + (new Date().getTime() - start));
5047+
5048+
var start = new Date().getTime();
50705049
var options = new TypeScript.FormattingOptions(!editorOptions.ConvertTabsToSpaces, editorOptions.TabSize, editorOptions.IndentSize, editorOptions.NewLineCharacter)
50715050

5072-
return formatting.SmartIndenter.getIndentation(position, sourceFile, options);
5051+
var result = formatting.SmartIndenter.getIndentation(position, sourceFile, options);
5052+
host.log("getIndentationAtPosition: computeIndentation : " + (new Date().getTime() - start));
5053+
5054+
return result;
50735055
}
50745056

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

0 commit comments

Comments
 (0)