@@ -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 ;
@@ -749,32 +737,11 @@ module ts {
749
737
return this . namedDeclarations ;
750
738
}
751
739
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
-
767
740
private isDeclareFile ( ) : boolean {
768
741
return TypeScript . isDTSFile ( this . filename ) ;
769
742
}
770
743
771
744
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
-
778
745
if ( textChangeRange && Debug . shouldAssert ( AssertionLevel . Normal ) ) {
779
746
var oldText = this . scriptSnapshot ;
780
747
var newText = scriptSnapshot ;
@@ -792,21 +759,12 @@ module ts {
792
759
}
793
760
}
794
761
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 ) ;
804
763
}
805
764
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 ) {
807
766
var newSourceFile = < SourceFileObject > < any > createSourceFile ( filename , scriptSnapshot . getText ( 0 , scriptSnapshot . getLength ( ) ) , languageVersion , version , isOpen ) ;
808
767
newSourceFile . scriptSnapshot = scriptSnapshot ;
809
- newSourceFile . syntaxTree = syntaxTree ;
810
768
return newSourceFile ;
811
769
}
812
770
}
@@ -1637,30 +1595,47 @@ module ts {
1637
1595
private initialize ( filename : string ) {
1638
1596
// ensure that both source file and syntax tree are either initialized or not initialized
1639
1597
Debug . assert ( ! ! this . currentFileSyntaxTree === ! ! this . currentSourceFile ) ;
1598
+ var start = new Date ( ) . getTime ( ) ;
1640
1599
this . hostCache = new HostCache ( this . host ) ;
1600
+ this . host . log ( "SyntaxTreeCache.Initialize: new HostCache: " + ( new Date ( ) . getTime ( ) - start ) ) ;
1641
1601
1642
1602
var version = this . hostCache . getVersion ( filename ) ;
1643
1603
var syntaxTree : TypeScript . SyntaxTree = null ;
1644
1604
var sourceFile : SourceFile ;
1645
1605
1646
1606
if ( this . currentFileSyntaxTree === null || this . currentFilename !== filename ) {
1647
1607
var scriptSnapshot = this . hostCache . getScriptSnapshot ( filename ) ;
1608
+ var start = new Date ( ) . getTime ( ) ;
1648
1609
syntaxTree = this . createSyntaxTree ( filename , scriptSnapshot ) ;
1610
+ this . host . log ( "SyntaxTreeCache.Initialize: createSyntaxTree: " + ( new Date ( ) . getTime ( ) - start ) ) ;
1611
+
1612
+ var start = new Date ( ) . getTime ( ) ;
1649
1613
sourceFile = createSourceFileFromScriptSnapshot ( filename , scriptSnapshot , getDefaultCompilerOptions ( ) , version , /*isOpen*/ true ) ;
1614
+ this . host . log ( "SyntaxTreeCache.Initialize: createSourceFile: " + ( new Date ( ) . getTime ( ) - start ) ) ;
1650
1615
1616
+ var start = new Date ( ) . getTime ( ) ;
1651
1617
fixupParentReferences ( sourceFile ) ;
1618
+ this . host . log ( "SyntaxTreeCache.Initialize: fixupParentRefs : " + ( new Date ( ) . getTime ( ) - start ) ) ;
1652
1619
}
1653
1620
else if ( this . currentFileVersion !== version ) {
1654
1621
var scriptSnapshot = this . hostCache . getScriptSnapshot ( filename ) ;
1622
+
1623
+ var start = new Date ( ) . getTime ( ) ;
1655
1624
syntaxTree = this . updateSyntaxTree ( filename , scriptSnapshot ,
1656
1625
this . currentSourceFile . getScriptSnapshot ( ) , this . currentFileSyntaxTree , this . currentFileVersion ) ;
1626
+ this . host . log ( "SyntaxTreeCache.Initialize: updateSyntaxTree: " + ( new Date ( ) . getTime ( ) - start ) ) ;
1657
1627
1658
1628
var editRange = this . hostCache . getChangeRange ( filename , this . currentFileVersion , this . currentSourceFile . getScriptSnapshot ( ) ) ;
1629
+
1630
+ var start = new Date ( ) . getTime ( ) ;
1659
1631
sourceFile = ! editRange
1660
1632
? createSourceFileFromScriptSnapshot ( filename , scriptSnapshot , getDefaultCompilerOptions ( ) , version , /*isOpen*/ true )
1661
1633
: this . currentSourceFile . update ( scriptSnapshot , version , /*isOpen*/ true , editRange ) ;
1634
+ this . host . log ( "SyntaxTreeCache.Initialize: updateSourceFile: " + ( new Date ( ) . getTime ( ) - start ) ) ;
1662
1635
1636
+ var start = new Date ( ) . getTime ( ) ;
1663
1637
fixupParentReferences ( sourceFile ) ;
1638
+ this . host . log ( "SyntaxTreeCache.Initialize: fixupParentRefs : " + ( new Date ( ) . getTime ( ) - start ) ) ;
1664
1639
}
1665
1640
1666
1641
if ( syntaxTree !== null ) {
@@ -5066,10 +5041,17 @@ module ts {
5066
5041
function getIndentationAtPosition ( filename : string , position : number , editorOptions : EditorOptions ) {
5067
5042
filename = TypeScript . switchToForwardSlashes ( filename ) ;
5068
5043
5044
+ var start = new Date ( ) . getTime ( ) ;
5069
5045
var sourceFile = getCurrentSourceFile ( filename ) ;
5046
+ host . log ( "getIndentationAtPosition: getCurrentSourceFile: " + ( new Date ( ) . getTime ( ) - start ) ) ;
5047
+
5048
+ var start = new Date ( ) . getTime ( ) ;
5070
5049
var options = new TypeScript . FormattingOptions ( ! editorOptions . ConvertTabsToSpaces , editorOptions . TabSize , editorOptions . IndentSize , editorOptions . NewLineCharacter )
5071
5050
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 ;
5073
5055
}
5074
5056
5075
5057
function getFormattingManager ( filename : string , options : FormatCodeOptions ) {
0 commit comments