44/// <reference path="..\compiler\parser.ts"/>
55/// <reference path="..\compiler\checker.ts"/>
66
7- /// <reference path='syntax\incrementalParser.ts' />
87/// <reference path='outliningElementsCollector.ts' />
98/// <reference path='navigationBar.ts' />
109/// <reference path='breakpoints.ts' />
1312/// <reference path='smartIndenter.ts' />
1413/// <reference path='formatting.ts' />
1514
16- /// <reference path='core\references.ts' />
17- /// <reference path='resources\references.ts' />
18- /// <reference path='text\references.ts' />
19- /// <reference path='syntax\references.ts' />
20- /// <reference path='compiler\diagnostics.ts' />
21- /// <reference path='compiler\hashTable.ts' />
22- /// <reference path='compiler\ast.ts' />
23- /// <reference path='compiler\astWalker.ts' />
24- /// <reference path='compiler\astHelpers.ts' />
25- /// <reference path='compiler\pathUtils.ts' />
26-
2715module ts {
2816 export interface Node {
2917 getSourceFile ( ) : SourceFile ;
@@ -1263,10 +1251,6 @@ module ts {
12631251 prefix = 3
12641252 }
12651253
1266- interface IncrementalParse {
1267- ( oldSyntaxTree : TypeScript . SyntaxTree , textChangeRange : TypeScript . TextChangeRange , newText : TypeScript . ISimpleText ) : TypeScript . SyntaxTree
1268- }
1269-
12701254 /// Language Service
12711255
12721256 interface CompletionSession {
@@ -1606,28 +1590,22 @@ module ts {
16061590 private currentFilename : string = "" ;
16071591 private currentFileVersion : string = null ;
16081592 private currentSourceFile : SourceFile = null ;
1609- private currentFileSyntaxTree : TypeScript . SyntaxTree = null ;
16101593
16111594 constructor ( private host : LanguageServiceHost ) {
16121595 this . hostCache = new HostCache ( host ) ;
16131596 }
16141597
16151598 private initialize ( filename : string ) {
16161599 // ensure that both source file and syntax tree are either initialized or not initialized
1617- Debug . assert ( ! ! this . currentFileSyntaxTree === ! ! this . currentSourceFile ) ;
16181600 var start = new Date ( ) . getTime ( ) ;
16191601 this . hostCache = new HostCache ( this . host ) ;
16201602 this . host . log ( "SyntaxTreeCache.Initialize: new HostCache: " + ( new Date ( ) . getTime ( ) - start ) ) ;
16211603
16221604 var version = this . hostCache . getVersion ( filename ) ;
1623- var syntaxTree : TypeScript . SyntaxTree = null ;
16241605 var sourceFile : SourceFile ;
16251606
1626- if ( this . currentFileSyntaxTree === null || this . currentFilename !== filename ) {
1607+ if ( this . currentFilename !== filename ) {
16271608 var scriptSnapshot = this . hostCache . getScriptSnapshot ( filename ) ;
1628- var start = new Date ( ) . getTime ( ) ;
1629- syntaxTree = this . createSyntaxTree ( filename , scriptSnapshot ) ;
1630- this . host . log ( "SyntaxTreeCache.Initialize: createSyntaxTree: " + ( new Date ( ) . getTime ( ) - start ) ) ;
16311609
16321610 var start = new Date ( ) . getTime ( ) ;
16331611 sourceFile = createSourceFileFromScriptSnapshot ( filename , scriptSnapshot , getDefaultCompilerOptions ( ) , version , /*isOpen*/ true ) ;
@@ -1640,11 +1618,6 @@ module ts {
16401618 else if ( this . currentFileVersion !== version ) {
16411619 var scriptSnapshot = this . hostCache . getScriptSnapshot ( filename ) ;
16421620
1643- var start = new Date ( ) . getTime ( ) ;
1644- syntaxTree = this . updateSyntaxTree ( filename , scriptSnapshot ,
1645- this . currentSourceFile . getScriptSnapshot ( ) , this . currentFileSyntaxTree , this . currentFileVersion ) ;
1646- this . host . log ( "SyntaxTreeCache.Initialize: updateSyntaxTree: " + ( new Date ( ) . getTime ( ) - start ) ) ;
1647-
16481621 var editRange = this . hostCache . getChangeRange ( filename , this . currentFileVersion , this . currentSourceFile . getScriptSnapshot ( ) ) ;
16491622
16501623 var start = new Date ( ) . getTime ( ) ;
@@ -1658,12 +1631,10 @@ module ts {
16581631 this . host . log ( "SyntaxTreeCache.Initialize: fixupParentRefs : " + ( new Date ( ) . getTime ( ) - start ) ) ;
16591632 }
16601633
1661- if ( syntaxTree !== null ) {
1662- Debug . assert ( sourceFile !== undefined ) ;
1634+ if ( sourceFile ) {
16631635 // All done, ensure state is up to date
16641636 this . currentFileVersion = version ;
16651637 this . currentFilename = filename ;
1666- this . currentFileSyntaxTree = syntaxTree ;
16671638 this . currentSourceFile = sourceFile ;
16681639 }
16691640
@@ -1684,112 +1655,14 @@ module ts {
16841655 }
16851656 }
16861657
1687- public getCurrentFileSyntaxTree ( filename : string ) : TypeScript . SyntaxTree {
1688- this . initialize ( filename ) ;
1689- return this . currentFileSyntaxTree ;
1690- }
1691-
16921658 public getCurrentSourceFile ( filename : string ) : SourceFile {
16931659 this . initialize ( filename ) ;
16941660 return this . currentSourceFile ;
16951661 }
16961662
16971663 public getCurrentScriptSnapshot ( filename : string ) : TypeScript . IScriptSnapshot {
1698- // update currentFileScriptSnapshot as a part of 'getCurrentFileSyntaxTree' call
1699- this . getCurrentFileSyntaxTree ( filename ) ;
17001664 return this . getCurrentSourceFile ( filename ) . getScriptSnapshot ( ) ;
17011665 }
1702-
1703- private createSyntaxTree ( filename : string , scriptSnapshot : TypeScript . IScriptSnapshot ) : TypeScript . SyntaxTree {
1704- var text = TypeScript . SimpleText . fromScriptSnapshot ( scriptSnapshot ) ;
1705-
1706- // For the purposes of features that use this syntax tree, we can just use the default
1707- // compilation settings. The features only use the syntax (and not the diagnostics),
1708- // and the syntax isn't affected by the compilation settings.
1709- var syntaxTree = TypeScript . Parser . parse ( filename , text , getDefaultCompilerOptions ( ) . target , TypeScript . isDTSFile ( filename ) ) ;
1710-
1711- return syntaxTree ;
1712- }
1713-
1714- private updateSyntaxTree ( filename : string , scriptSnapshot : TypeScript . IScriptSnapshot , previousScriptSnapshot : TypeScript . IScriptSnapshot , previousSyntaxTree : TypeScript . SyntaxTree , previousFileVersion : string ) : TypeScript . SyntaxTree {
1715- var editRange = this . hostCache . getChangeRange ( filename , previousFileVersion , previousScriptSnapshot ) ;
1716-
1717- // Debug.assert(newLength >= 0);
1718-
1719- // The host considers the entire buffer changed. So parse a completely new tree.
1720- if ( editRange === null ) {
1721- return this . createSyntaxTree ( filename , scriptSnapshot ) ;
1722- }
1723-
1724- var nextSyntaxTree = TypeScript . IncrementalParser . parse (
1725- previousSyntaxTree , editRange , TypeScript . SimpleText . fromScriptSnapshot ( scriptSnapshot ) ) ;
1726-
1727- this . ensureInvariants ( filename , editRange , nextSyntaxTree , previousScriptSnapshot , scriptSnapshot ) ;
1728-
1729- return nextSyntaxTree ;
1730- }
1731-
1732- private ensureInvariants ( filename : string , editRange : TypeScript . TextChangeRange , incrementalTree : TypeScript . SyntaxTree , oldScriptSnapshot : TypeScript . IScriptSnapshot , newScriptSnapshot : TypeScript . IScriptSnapshot ) {
1733- // First, verify that the edit range and the script snapshots make sense.
1734-
1735- // If this fires, then the edit range is completely bogus. Somehow the lengths of the
1736- // old snapshot, the change range and the new snapshot aren't in sync. This is very
1737- // bad.
1738- var expectedNewLength = oldScriptSnapshot . getLength ( ) - editRange . span ( ) . length ( ) + editRange . newLength ( ) ;
1739- var actualNewLength = newScriptSnapshot . getLength ( ) ;
1740-
1741- function provideMoreDebugInfo ( ) {
1742-
1743- var debugInformation = [ "expected length:" , expectedNewLength , "and actual length:" , actualNewLength , "are not equal\r\n" ] ;
1744-
1745- var oldSpan = editRange . span ( ) ;
1746-
1747- function prettyPrintString ( s : string ) : string {
1748- return '"' + s . replace ( / \r / g, '\\r' ) . replace ( / \n / g, '\\n' ) + '"' ;
1749- }
1750-
1751- debugInformation . push ( 'Edit range (old text) (start: ' + oldSpan . start ( ) + ', end: ' + oldSpan . end ( ) + ') \r\n' ) ;
1752- debugInformation . push ( 'Old text edit range contents: ' + prettyPrintString ( oldScriptSnapshot . getText ( oldSpan . start ( ) , oldSpan . end ( ) ) ) ) ;
1753-
1754- var newSpan = editRange . newSpan ( ) ;
1755-
1756- debugInformation . push ( 'Edit range (new text) (start: ' + newSpan . start ( ) + ', end: ' + newSpan . end ( ) + ') \r\n' ) ;
1757- debugInformation . push ( 'New text edit range contents: ' + prettyPrintString ( newScriptSnapshot . getText ( newSpan . start ( ) , newSpan . end ( ) ) ) ) ;
1758-
1759- return debugInformation . join ( ' ' ) ;
1760- }
1761-
1762- Debug . assert (
1763- expectedNewLength === actualNewLength ,
1764- "Expected length is different from actual!" ,
1765- provideMoreDebugInfo ) ;
1766-
1767- if ( Debug . shouldAssert ( AssertionLevel . VeryAggressive ) ) {
1768- // If this fires, the text change range is bogus. It says the change starts at point
1769- // 'X', but we can see a text difference *before* that point.
1770- var oldPrefixText = oldScriptSnapshot . getText ( 0 , editRange . span ( ) . start ( ) ) ;
1771- var newPrefixText = newScriptSnapshot . getText ( 0 , editRange . span ( ) . start ( ) ) ;
1772- Debug . assert ( oldPrefixText === newPrefixText , 'Expected equal prefix texts!' ) ;
1773-
1774- // If this fires, the text change range is bogus. It says the change goes only up to
1775- // point 'X', but we can see a text difference *after* that point.
1776- var oldSuffixText = oldScriptSnapshot . getText ( editRange . span ( ) . end ( ) , oldScriptSnapshot . getLength ( ) ) ;
1777- var newSuffixText = newScriptSnapshot . getText ( editRange . newSpan ( ) . end ( ) , newScriptSnapshot . getLength ( ) ) ;
1778- Debug . assert ( oldSuffixText === newSuffixText , 'Expected equal suffix texts!' ) ;
1779-
1780- // Ok, text change range and script snapshots look ok. Let's verify that our
1781- // incremental parsing worked properly.
1782- //var normalTree = this.createSyntaxTree(filename, newScriptSnapshot);
1783- //Debug.assert(normalTree.structuralEquals(incrementalTree), 'Expected equal incremental and normal trees');
1784-
1785- // Ok, the trees looked good. So at least our incremental parser agrees with the
1786- // normal parser. Now, verify that the incremental tree matches the contents of the
1787- // script snapshot.
1788- var incrementalTreeText = TypeScript . fullText ( incrementalTree . sourceUnit ( ) ) ;
1789- var actualSnapshotText = newScriptSnapshot . getText ( 0 , newScriptSnapshot . getLength ( ) ) ;
1790- Debug . assert ( incrementalTreeText === actualSnapshotText , 'Expected full texts to be equal' ) ;
1791- }
1792- }
17931666 }
17941667
17951668 function createSourceFileFromScriptSnapshot ( filename : string , scriptSnapshot : TypeScript . IScriptSnapshot , settings : CompilerOptions , version : string , isOpen : boolean ) {
@@ -4883,11 +4756,6 @@ module ts {
48834756 }
48844757
48854758 /// Syntactic features
4886- function getSyntaxTree ( filename : string ) : TypeScript . SyntaxTree {
4887- filename = normalizeSlashes ( filename ) ;
4888- return syntaxTreeCache . getCurrentFileSyntaxTree ( filename ) ;
4889- }
4890-
48914759 function getCurrentSourceFile ( filename : string ) : SourceFile {
48924760 filename = normalizeSlashes ( filename ) ;
48934761 var currentSourceFile = syntaxTreeCache . getCurrentSourceFile ( filename ) ;
0 commit comments