@@ -11,11 +11,7 @@ import * as strings from 'vs/base/common/strings';
1111import { guessIndentation } from 'vs/editor/common/model/indentationGuesser' ;
1212import { TPromise } from 'vs/base/common/winjs.base' ;
1313import { CharCode } from 'vs/base/common/charCode' ;
14-
15- export class ModelBuilderResult {
16- rawText : IRawText ;
17- hash : string ;
18- }
14+ import { IRawTextProvider } from 'vs/editor/common/services/modelService' ;
1915
2016class ModelLineBasedBuilder {
2117
@@ -46,14 +42,63 @@ class ModelLineBasedBuilder {
4642 this . hash . update ( lines . join ( '\n' ) + '\n' ) ;
4743 }
4844
49- public finish ( totalLength : number , carriageReturnCnt : number , containsRTL : boolean , isBasicASCII : boolean , opts : ITextModelCreationOptions ) : ModelBuilderResult {
45+ public finish ( totalLength : number , carriageReturnCnt : number , containsRTL : boolean , isBasicASCII : boolean ) : ModelBuilderResult {
46+ return new ModelBuilderResult ( this . BOM , this . lines , totalLength , carriageReturnCnt , containsRTL , isBasicASCII , this . hash . digest ( 'hex' ) ) ;
47+ }
48+ }
49+
50+ export class ModelBuilderResult implements IRawTextProvider {
51+ /**
52+ * The BOM (leading character sequence of the file).
53+ */
54+ private readonly BOM : string ;
55+ /**
56+ * The text split into lines.
57+ */
58+ private readonly lines : string [ ] ;
59+ /**
60+ * The entire text length.
61+ */
62+ private readonly length : number ;
63+ /**
64+ * Number of lines with EOL \r\n
65+ */
66+ private readonly carriageReturnCnt : number ;
67+ /**
68+ * The text contains Unicode characters classified as "R" or "AL".
69+ */
70+ private readonly containsRTL : boolean ;
71+ /**
72+ * The text contains only characters inside the ASCII range 32-126 or \t \r \n
73+ */
74+ private readonly isBasicASCII : boolean ;
75+ /**
76+ * The content hash.
77+ */
78+ public readonly hash : string ;
79+
80+ constructor ( BOM : string , lines : string [ ] , length : number , carriageReturnCnt : number , containsRTL : boolean , isBasicASCII : boolean , hash : string ) {
81+ this . BOM = BOM ;
82+ this . lines = lines ;
83+ this . length = length ;
84+ this . carriageReturnCnt = carriageReturnCnt ;
85+ this . containsRTL = containsRTL ;
86+ this . isBasicASCII = isBasicASCII ;
87+ this . hash = hash ;
88+ }
89+
90+ public getFirstLine ( ) : string {
91+ return this . lines [ 0 ] ;
92+ }
93+
94+ public toRawText ( opts : ITextModelCreationOptions ) : IRawText {
5095
5196 let lineFeedCnt = this . lines . length - 1 ;
5297 let EOL = '' ;
5398 if ( lineFeedCnt === 0 ) {
5499 // This is an empty file or a file with precisely one line
55100 EOL = ( opts . defaultEOL === DefaultEndOfLine . LF ? '\n' : '\r\n' ) ;
56- } else if ( carriageReturnCnt > lineFeedCnt / 2 ) {
101+ } else if ( this . carriageReturnCnt > lineFeedCnt / 2 ) {
57102 // More than half of the file contains \r\n ending lines
58103 EOL = '\r\n' ;
59104 } else {
@@ -80,16 +125,13 @@ class ModelLineBasedBuilder {
80125 }
81126
82127 return {
83- rawText : {
84- BOM : this . BOM ,
85- EOL : EOL ,
86- lines : this . lines ,
87- length : totalLength ,
88- containsRTL : containsRTL ,
89- isBasicASCII : isBasicASCII ,
90- options : resolvedOpts
91- } ,
92- hash : this . hash . digest ( 'hex' )
128+ BOM : this . BOM ,
129+ EOL : EOL ,
130+ lines : this . lines ,
131+ length : this . length ,
132+ containsRTL : this . containsRTL ,
133+ isBasicASCII : this . isBasicASCII ,
134+ options : resolvedOpts
93135 } ;
94136 }
95137}
@@ -112,7 +154,7 @@ export class ModelBuilder {
112154 private containsRTL : boolean ;
113155 private isBasicASCII : boolean ;
114156
115- public static fromStringStream ( stream : IStringStream , options : ITextModelCreationOptions ) : TPromise < ModelBuilderResult > {
157+ public static fromStringStream ( stream : IStringStream ) : TPromise < ModelBuilderResult > {
116158 return new TPromise < ModelBuilderResult > ( ( c , e , p ) => {
117159 let done = false ;
118160 let builder = new ModelBuilder ( ) ;
@@ -131,7 +173,7 @@ export class ModelBuilder {
131173 stream . on ( 'end' , ( ) => {
132174 if ( ! done ) {
133175 done = true ;
134- c ( builder . finish ( options ) ) ;
176+ c ( builder . finish ( ) ) ;
135177 }
136178 } ) ;
137179 } ) ;
@@ -196,12 +238,12 @@ export class ModelBuilder {
196238 this . leftoverPrevChunk = lines [ lines . length - 1 ] ;
197239 }
198240
199- public finish ( opts : ITextModelCreationOptions ) : ModelBuilderResult {
241+ public finish ( ) : ModelBuilderResult {
200242 let finalLines = [ this . leftoverPrevChunk ] ;
201243 if ( this . leftoverEndsInCR ) {
202244 finalLines . push ( '' ) ;
203245 }
204246 this . lineBasedBuilder . acceptLines ( finalLines ) ;
205- return this . lineBasedBuilder . finish ( this . totalLength , this . totalCRCount , this . containsRTL , this . isBasicASCII , opts ) ;
247+ return this . lineBasedBuilder . finish ( this . totalLength , this . totalCRCount , this . containsRTL , this . isBasicASCII ) ;
206248 }
207249}
0 commit comments