@@ -93,6 +93,8 @@ module ts {
93
93
94
94
getSyntacticClassifications ( fileName : string , start : number , length : number ) : string ;
95
95
getSemanticClassifications ( fileName : string , start : number , length : number ) : string ;
96
+ getEncodedSyntacticClassifications ( fileName : string , start : number , length : number ) : string ;
97
+ getEncodedSemanticClassifications ( fileName : string , start : number , length : number ) : string ;
96
98
97
99
getCompletionsAtPosition ( fileName : string , position : number ) : string ;
98
100
getCompletionEntryDetails ( fileName : string , position : number , entryName : string ) : string ;
@@ -183,6 +185,7 @@ module ts {
183
185
}
184
186
185
187
export interface ClassifierShim extends Shim {
188
+ getEncodedLexicalClassifications ( text : string , lexState : EndOfLineState , syntacticClassifierAbsent ?: boolean ) : string ;
186
189
getClassificationsForLine ( text : string , lexState : EndOfLineState , syntacticClassifierAbsent ?: boolean ) : string ;
187
190
}
188
191
@@ -192,7 +195,9 @@ module ts {
192
195
}
193
196
194
197
function logInternalError ( logger : Logger , err : Error ) {
195
- logger . log ( "*INTERNAL ERROR* - Exception in typescript services: " + err . message ) ;
198
+ if ( logger ) {
199
+ logger . log ( "*INTERNAL ERROR* - Exception in typescript services: " + err . message ) ;
200
+ }
196
201
}
197
202
198
203
class ScriptSnapshotShimAdapter implements IScriptSnapshot {
@@ -303,25 +308,32 @@ module ts {
303
308
}
304
309
}
305
310
306
- function simpleForwardCall ( logger : Logger , actionDescription : string , action : ( ) => any ) : any {
307
- logger . log ( actionDescription ) ;
308
- var start = Date . now ( ) ;
311
+ function simpleForwardCall ( logger : Logger , actionDescription : string , action : ( ) => any , noPerfLogging : boolean ) : any {
312
+ if ( ! noPerfLogging ) {
313
+ logger . log ( actionDescription ) ;
314
+ var start = Date . now ( ) ;
315
+ }
316
+
309
317
var result = action ( ) ;
310
- var end = Date . now ( ) ;
311
- logger . log ( actionDescription + " completed in " + ( end - start ) + " msec" ) ;
312
- if ( typeof ( result ) === "string" ) {
313
- var str = < string > result ;
314
- if ( str . length > 128 ) {
315
- str = str . substring ( 0 , 128 ) + "..." ;
318
+
319
+ if ( ! noPerfLogging ) {
320
+ var end = Date . now ( ) ;
321
+ logger . log ( actionDescription + " completed in " + ( end - start ) + " msec" ) ;
322
+ if ( typeof ( result ) === "string" ) {
323
+ var str = < string > result ;
324
+ if ( str . length > 128 ) {
325
+ str = str . substring ( 0 , 128 ) + "..." ;
326
+ }
327
+ logger . log ( " result.length=" + str . length + ", result='" + JSON . stringify ( str ) + "'" ) ;
316
328
}
317
- logger . log ( " result.length=" + str . length + ", result='" + JSON . stringify ( str ) + "'" ) ;
318
329
}
330
+
319
331
return result ;
320
332
}
321
333
322
- function forwardJSONCall ( logger : Logger , actionDescription : string , action : ( ) => any ) : string {
334
+ function forwardJSONCall ( logger : Logger , actionDescription : string , action : ( ) => any , noPerfLogging : boolean ) : string {
323
335
try {
324
- var result = simpleForwardCall ( logger , actionDescription , action ) ;
336
+ var result = simpleForwardCall ( logger , actionDescription , action , noPerfLogging ) ;
325
337
return JSON . stringify ( { result : result } ) ;
326
338
}
327
339
catch ( err ) {
@@ -369,7 +381,7 @@ module ts {
369
381
}
370
382
371
383
public forwardJSONCall ( actionDescription : string , action : ( ) => any ) : string {
372
- return forwardJSONCall ( this . logger , actionDescription , action ) ;
384
+ return forwardJSONCall ( this . logger , actionDescription , action , /*noPerfLogging:*/ false ) ;
373
385
}
374
386
375
387
/// DISPOSE
@@ -439,6 +451,26 @@ module ts {
439
451
} ) ;
440
452
}
441
453
454
+ public getEncodedSyntacticClassifications ( fileName : string , start : number , length : number ) : string {
455
+ return this . forwardJSONCall (
456
+ "getEncodedSyntacticClassifications('" + fileName + "', " + start + ", " + length + ")" ,
457
+ ( ) => {
458
+ // directly serialize the spans out to a string. This is much faster to decode
459
+ // on the managed side versus a full JSON array.
460
+ return convertClassifications ( this . languageService . getEncodedSyntacticClassifications ( fileName , createTextSpan ( start , length ) ) ) ;
461
+ } ) ;
462
+ }
463
+
464
+ public getEncodedSemanticClassifications ( fileName : string , start : number , length : number ) : string {
465
+ return this . forwardJSONCall (
466
+ "getEncodedSemanticClassifications('" + fileName + "', " + start + ", " + length + ")" ,
467
+ ( ) => {
468
+ // directly serialize the spans out to a string. This is much faster to decode
469
+ // on the managed side versus a full JSON array.
470
+ return convertClassifications ( this . languageService . getEncodedSemanticClassifications ( fileName , createTextSpan ( start , length ) ) ) ;
471
+ } ) ;
472
+ }
473
+
442
474
private getNewLine ( ) : string {
443
475
return this . host . getNewLine ? this . host . getNewLine ( ) : "\r\n" ;
444
476
}
@@ -718,14 +750,24 @@ module ts {
718
750
}
719
751
}
720
752
753
+ function convertClassifications ( classifications : Classifications ) : { spans : string , endOfLineState : EndOfLineState } {
754
+ return { spans : classifications . spans . join ( "," ) , endOfLineState : classifications . endOfLineState } ;
755
+ }
756
+
721
757
class ClassifierShimObject extends ShimBase implements ClassifierShim {
722
758
public classifier : Classifier ;
723
759
724
- constructor ( factory : ShimFactory ) {
760
+ constructor ( factory : ShimFactory , private logger : Logger ) {
725
761
super ( factory ) ;
726
762
this . classifier = createClassifier ( ) ;
727
763
}
728
764
765
+ public getEncodedLexicalClassifications ( text : string , lexState : EndOfLineState , syntacticClassifierAbsent ?: boolean ) : string {
766
+ return forwardJSONCall ( this . logger , "getEncodedLexicalClassifications" ,
767
+ ( ) => convertClassifications ( this . classifier . getEncodedLexicalClassifications ( text , lexState , syntacticClassifierAbsent ) ) ,
768
+ /*noPerfLogging:*/ true ) ;
769
+ }
770
+
729
771
/// COLORIZATION
730
772
public getClassificationsForLine ( text : string , lexState : EndOfLineState , classifyKeywordsInGenerics ?: boolean ) : string {
731
773
var classification = this . classifier . getClassificationsForLine ( text , lexState , classifyKeywordsInGenerics ) ;
@@ -746,7 +788,7 @@ module ts {
746
788
}
747
789
748
790
private forwardJSONCall ( actionDescription : string , action : ( ) => any ) : any {
749
- return forwardJSONCall ( this . logger , actionDescription , action ) ;
791
+ return forwardJSONCall ( this . logger , actionDescription , action , /*noPerfLogging:*/ false ) ;
750
792
}
751
793
752
794
public getPreProcessedFileInfo ( fileName : string , sourceTextSnapshot : IScriptSnapshot ) : string {
@@ -813,7 +855,7 @@ module ts {
813
855
814
856
public createClassifierShim ( logger : Logger ) : ClassifierShim {
815
857
try {
816
- return new ClassifierShimObject ( this ) ;
858
+ return new ClassifierShimObject ( this , logger ) ;
817
859
}
818
860
catch ( err ) {
819
861
logInternalError ( logger , err ) ;
0 commit comments