@@ -99,6 +99,8 @@ module ts {
99
99
100
100
getSyntacticClassifications ( fileName : string , start : number , length : number ) : string ;
101
101
getSemanticClassifications ( fileName : string , start : number , length : number ) : string ;
102
+ getEncodedSyntacticClassifications ( fileName : string , start : number , length : number ) : string ;
103
+ getEncodedSemanticClassifications ( fileName : string , start : number , length : number ) : string ;
102
104
103
105
getCompletionsAtPosition ( fileName : string , position : number ) : string ;
104
106
getCompletionEntryDetails ( fileName : string , position : number , entryName : string ) : string ;
@@ -189,6 +191,7 @@ module ts {
189
191
}
190
192
191
193
export interface ClassifierShim extends Shim {
194
+ getEncodedLexicalClassifications ( text : string , lexState : EndOfLineState , syntacticClassifierAbsent ?: boolean ) : string ;
192
195
getClassificationsForLine ( text : string , lexState : EndOfLineState , syntacticClassifierAbsent ?: boolean ) : string ;
193
196
}
194
197
@@ -199,7 +202,9 @@ module ts {
199
202
}
200
203
201
204
function logInternalError ( logger : Logger , err : Error ) {
202
- logger . log ( "*INTERNAL ERROR* - Exception in typescript services: " + err . message ) ;
205
+ if ( logger ) {
206
+ logger . log ( "*INTERNAL ERROR* - Exception in typescript services: " + err . message ) ;
207
+ }
203
208
}
204
209
205
210
class ScriptSnapshotShimAdapter implements IScriptSnapshot {
@@ -321,25 +326,32 @@ module ts {
321
326
}
322
327
}
323
328
324
- function simpleForwardCall ( logger : Logger , actionDescription : string , action : ( ) => any ) : any {
325
- logger . log ( actionDescription ) ;
326
- var start = Date . now ( ) ;
329
+ function simpleForwardCall ( logger : Logger , actionDescription : string , action : ( ) => any , noPerfLogging : boolean ) : any {
330
+ if ( ! noPerfLogging ) {
331
+ logger . log ( actionDescription ) ;
332
+ var start = Date . now ( ) ;
333
+ }
334
+
327
335
var result = action ( ) ;
328
- var end = Date . now ( ) ;
329
- logger . log ( actionDescription + " completed in " + ( end - start ) + " msec" ) ;
330
- if ( typeof ( result ) === "string" ) {
331
- var str = < string > result ;
332
- if ( str . length > 128 ) {
333
- str = str . substring ( 0 , 128 ) + "..." ;
336
+
337
+ if ( ! noPerfLogging ) {
338
+ var end = Date . now ( ) ;
339
+ logger . log ( actionDescription + " completed in " + ( end - start ) + " msec" ) ;
340
+ if ( typeof ( result ) === "string" ) {
341
+ var str = < string > result ;
342
+ if ( str . length > 128 ) {
343
+ str = str . substring ( 0 , 128 ) + "..." ;
344
+ }
345
+ logger . log ( " result.length=" + str . length + ", result='" + JSON . stringify ( str ) + "'" ) ;
334
346
}
335
- logger . log ( " result.length=" + str . length + ", result='" + JSON . stringify ( str ) + "'" ) ;
336
347
}
348
+
337
349
return result ;
338
350
}
339
351
340
- function forwardJSONCall ( logger : Logger , actionDescription : string , action : ( ) => any ) : string {
352
+ function forwardJSONCall ( logger : Logger , actionDescription : string , action : ( ) => any , noPerfLogging : boolean ) : string {
341
353
try {
342
- var result = simpleForwardCall ( logger , actionDescription , action ) ;
354
+ var result = simpleForwardCall ( logger , actionDescription , action , noPerfLogging ) ;
343
355
return JSON . stringify ( { result : result } ) ;
344
356
}
345
357
catch ( err ) {
@@ -387,7 +399,7 @@ module ts {
387
399
}
388
400
389
401
public forwardJSONCall ( actionDescription : string , action : ( ) => any ) : string {
390
- return forwardJSONCall ( this . logger , actionDescription , action ) ;
402
+ return forwardJSONCall ( this . logger , actionDescription , action , /*noPerfLogging:*/ false ) ;
391
403
}
392
404
393
405
/// DISPOSE
@@ -457,6 +469,26 @@ module ts {
457
469
} ) ;
458
470
}
459
471
472
+ public getEncodedSyntacticClassifications ( fileName : string , start : number , length : number ) : string {
473
+ return this . forwardJSONCall (
474
+ "getEncodedSyntacticClassifications('" + fileName + "', " + start + ", " + length + ")" ,
475
+ ( ) => {
476
+ // directly serialize the spans out to a string. This is much faster to decode
477
+ // on the managed side versus a full JSON array.
478
+ return convertClassifications ( this . languageService . getEncodedSyntacticClassifications ( fileName , createTextSpan ( start , length ) ) ) ;
479
+ } ) ;
480
+ }
481
+
482
+ public getEncodedSemanticClassifications ( fileName : string , start : number , length : number ) : string {
483
+ return this . forwardJSONCall (
484
+ "getEncodedSemanticClassifications('" + fileName + "', " + start + ", " + length + ")" ,
485
+ ( ) => {
486
+ // directly serialize the spans out to a string. This is much faster to decode
487
+ // on the managed side versus a full JSON array.
488
+ return convertClassifications ( this . languageService . getEncodedSemanticClassifications ( fileName , createTextSpan ( start , length ) ) ) ;
489
+ } ) ;
490
+ }
491
+
460
492
private getNewLine ( ) : string {
461
493
return this . host . getNewLine ? this . host . getNewLine ( ) : "\r\n" ;
462
494
}
@@ -736,14 +768,24 @@ module ts {
736
768
}
737
769
}
738
770
771
+ function convertClassifications ( classifications : Classifications ) : { spans : string , endOfLineState : EndOfLineState } {
772
+ return { spans : classifications . spans . join ( "," ) , endOfLineState : classifications . endOfLineState } ;
773
+ }
774
+
739
775
class ClassifierShimObject extends ShimBase implements ClassifierShim {
740
776
public classifier : Classifier ;
741
777
742
- constructor ( factory : ShimFactory ) {
778
+ constructor ( factory : ShimFactory , private logger : Logger ) {
743
779
super ( factory ) ;
744
780
this . classifier = createClassifier ( ) ;
745
781
}
746
782
783
+ public getEncodedLexicalClassifications ( text : string , lexState : EndOfLineState , syntacticClassifierAbsent ?: boolean ) : string {
784
+ return forwardJSONCall ( this . logger , "getEncodedLexicalClassifications" ,
785
+ ( ) => convertClassifications ( this . classifier . getEncodedLexicalClassifications ( text , lexState , syntacticClassifierAbsent ) ) ,
786
+ /*noPerfLogging:*/ true ) ;
787
+ }
788
+
747
789
/// COLORIZATION
748
790
public getClassificationsForLine ( text : string , lexState : EndOfLineState , classifyKeywordsInGenerics ?: boolean ) : string {
749
791
var classification = this . classifier . getClassificationsForLine ( text , lexState , classifyKeywordsInGenerics ) ;
@@ -765,7 +807,7 @@ module ts {
765
807
}
766
808
767
809
private forwardJSONCall ( actionDescription : string , action : ( ) => any ) : any {
768
- return forwardJSONCall ( this . logger , actionDescription , action ) ;
810
+ return forwardJSONCall ( this . logger , actionDescription , action , /*noPerfLogging:*/ false ) ;
769
811
}
770
812
771
813
public getPreProcessedFileInfo ( fileName : string , sourceTextSnapshot : IScriptSnapshot ) : string {
@@ -858,7 +900,7 @@ module ts {
858
900
859
901
public createClassifierShim ( logger : Logger ) : ClassifierShim {
860
902
try {
861
- return new ClassifierShimObject ( this ) ;
903
+ return new ClassifierShimObject ( this , logger ) ;
862
904
}
863
905
catch ( err ) {
864
906
logInternalError ( logger , err ) ;
0 commit comments