@@ -71,8 +71,6 @@ module ts {
71
71
}
72
72
73
73
export interface SourceFile {
74
- getSourceUnit ( ) : TypeScript . SourceUnitSyntax ;
75
- getSyntaxTree ( ) : TypeScript . SyntaxTree ;
76
74
getScriptSnapshot ( ) : TypeScript . IScriptSnapshot ;
77
75
getNamedDeclarations ( ) : Declaration [ ] ;
78
76
update ( scriptSnapshot : TypeScript . IScriptSnapshot , version : string , isOpen : boolean , textChangeRange : TypeScript . TextChangeRange ) : SourceFile ;
@@ -660,23 +658,13 @@ module ts {
660
658
public languageVersion : ScriptTarget ;
661
659
public identifiers : Map < string > ;
662
660
663
- private syntaxTree : TypeScript . SyntaxTree ;
664
661
private scriptSnapshot : TypeScript . IScriptSnapshot ;
665
662
private namedDeclarations : Declaration [ ] ;
666
663
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
-
672
664
public getScriptSnapshot ( ) : TypeScript . IScriptSnapshot {
673
665
return this . scriptSnapshot ;
674
666
}
675
667
676
- public getLineMap ( ) : TypeScript . LineMap {
677
- return this . getSyntaxTree ( ) . lineMap ( ) ;
678
- }
679
-
680
668
public getNamedDeclarations ( ) {
681
669
if ( ! this . namedDeclarations ) {
682
670
var sourceFile = this ;
@@ -748,32 +736,11 @@ module ts {
748
736
return this . namedDeclarations ;
749
737
}
750
738
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
-
766
739
private isDeclareFile ( ) : boolean {
767
740
return TypeScript . isDTSFile ( this . filename ) ;
768
741
}
769
742
770
743
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
-
777
744
if ( textChangeRange && Debug . shouldAssert ( AssertionLevel . Normal ) ) {
778
745
var oldText = this . scriptSnapshot ;
779
746
var newText = scriptSnapshot ;
@@ -791,21 +758,12 @@ module ts {
791
758
}
792
759
}
793
760
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 ) ;
803
762
}
804
763
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 ) {
806
765
var newSourceFile = < SourceFileObject > < any > createSourceFile ( filename , scriptSnapshot . getText ( 0 , scriptSnapshot . getLength ( ) ) , languageVersion , version , isOpen ) ;
807
766
newSourceFile . scriptSnapshot = scriptSnapshot ;
808
- newSourceFile . syntaxTree = syntaxTree ;
809
767
return newSourceFile ;
810
768
}
811
769
}
@@ -1633,30 +1591,47 @@ module ts {
1633
1591
private initialize ( filename : string ) {
1634
1592
// ensure that both source file and syntax tree are either initialized or not initialized
1635
1593
Debug . assert ( ! ! this . currentFileSyntaxTree === ! ! this . currentSourceFile ) ;
1594
+ var start = new Date ( ) . getTime ( ) ;
1636
1595
this . hostCache = new HostCache ( this . host ) ;
1596
+ this . host . log ( "SyntaxTreeCache.Initialize: new HostCache: " + ( new Date ( ) . getTime ( ) - start ) ) ;
1637
1597
1638
1598
var version = this . hostCache . getVersion ( filename ) ;
1639
1599
var syntaxTree : TypeScript . SyntaxTree = null ;
1640
1600
var sourceFile : SourceFile ;
1641
1601
1642
1602
if ( this . currentFileSyntaxTree === null || this . currentFilename !== filename ) {
1643
1603
var scriptSnapshot = this . hostCache . getScriptSnapshot ( filename ) ;
1604
+ var start = new Date ( ) . getTime ( ) ;
1644
1605
syntaxTree = this . createSyntaxTree ( filename , scriptSnapshot ) ;
1606
+ this . host . log ( "SyntaxTreeCache.Initialize: createSyntaxTree: " + ( new Date ( ) . getTime ( ) - start ) ) ;
1607
+
1608
+ var start = new Date ( ) . getTime ( ) ;
1645
1609
sourceFile = createSourceFileFromScriptSnapshot ( filename , scriptSnapshot , getDefaultCompilerOptions ( ) , version , /*isOpen*/ true ) ;
1610
+ this . host . log ( "SyntaxTreeCache.Initialize: createSourceFile: " + ( new Date ( ) . getTime ( ) - start ) ) ;
1646
1611
1612
+ var start = new Date ( ) . getTime ( ) ;
1647
1613
fixupParentReferences ( sourceFile ) ;
1614
+ this . host . log ( "SyntaxTreeCache.Initialize: fixupParentRefs : " + ( new Date ( ) . getTime ( ) - start ) ) ;
1648
1615
}
1649
1616
else if ( this . currentFileVersion !== version ) {
1650
1617
var scriptSnapshot = this . hostCache . getScriptSnapshot ( filename ) ;
1618
+
1619
+ var start = new Date ( ) . getTime ( ) ;
1651
1620
syntaxTree = this . updateSyntaxTree ( filename , scriptSnapshot ,
1652
1621
this . currentSourceFile . getScriptSnapshot ( ) , this . currentFileSyntaxTree , this . currentFileVersion ) ;
1622
+ this . host . log ( "SyntaxTreeCache.Initialize: updateSyntaxTree: " + ( new Date ( ) . getTime ( ) - start ) ) ;
1653
1623
1654
1624
var editRange = this . hostCache . getChangeRange ( filename , this . currentFileVersion , this . currentSourceFile . getScriptSnapshot ( ) ) ;
1625
+
1626
+ var start = new Date ( ) . getTime ( ) ;
1655
1627
sourceFile = ! editRange
1656
1628
? createSourceFileFromScriptSnapshot ( filename , scriptSnapshot , getDefaultCompilerOptions ( ) , version , /*isOpen*/ true )
1657
1629
: this . currentSourceFile . update ( scriptSnapshot , version , /*isOpen*/ true , editRange ) ;
1630
+ this . host . log ( "SyntaxTreeCache.Initialize: updateSourceFile: " + ( new Date ( ) . getTime ( ) - start ) ) ;
1658
1631
1632
+ var start = new Date ( ) . getTime ( ) ;
1659
1633
fixupParentReferences ( sourceFile ) ;
1634
+ this . host . log ( "SyntaxTreeCache.Initialize: fixupParentRefs : " + ( new Date ( ) . getTime ( ) - start ) ) ;
1660
1635
}
1661
1636
1662
1637
if ( syntaxTree !== null ) {
@@ -5050,10 +5025,17 @@ module ts {
5050
5025
function getIndentationAtPosition ( filename : string , position : number , editorOptions : EditorOptions ) {
5051
5026
filename = TypeScript . switchToForwardSlashes ( filename ) ;
5052
5027
5028
+ var start = new Date ( ) . getTime ( ) ;
5053
5029
var sourceFile = getCurrentSourceFile ( filename ) ;
5030
+ host . log ( "getIndentationAtPosition: getCurrentSourceFile: " + ( new Date ( ) . getTime ( ) - start ) ) ;
5031
+
5032
+ var start = new Date ( ) . getTime ( ) ;
5054
5033
var options = new TypeScript . FormattingOptions ( ! editorOptions . ConvertTabsToSpaces , editorOptions . TabSize , editorOptions . IndentSize , editorOptions . NewLineCharacter )
5055
5034
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 ;
5057
5039
}
5058
5040
5059
5041
function getFormattingManager ( filename : string , options : FormatCodeOptions ) {
0 commit comments