11/// <reference path='..\services\services.ts' />
22/// <reference path='..\services\shims.ts' />
3+ /// <reference path='..\server\client.ts' />
34/// <reference path='harness.ts' />
45
56module Harness . LanguageService {
@@ -23,18 +24,18 @@ module Harness.LanguageService {
2324 this . version ++ ;
2425 }
2526
26- public editContent ( minChar : number , limChar : number , newText : string ) : void {
27+ public editContent ( start : number , end : number , newText : string ) : void {
2728 // Apply edits
28- var prefix = this . content . substring ( 0 , minChar ) ;
29+ var prefix = this . content . substring ( 0 , start ) ;
2930 var middle = newText ;
30- var suffix = this . content . substring ( limChar ) ;
31+ var suffix = this . content . substring ( end ) ;
3132 this . setContent ( prefix + middle + suffix ) ;
3233
3334 // Store edit range + new length of script
3435 this . editRanges . push ( {
3536 length : this . content . length ,
3637 textChangeRange : ts . createTextChangeRange (
37- ts . createTextSpanFromBounds ( minChar , limChar ) , newText . length )
38+ ts . createTextSpanFromBounds ( start , end ) , newText . length )
3839 } ) ;
3940
4041 // Update version #
@@ -127,9 +128,7 @@ module Harness.LanguageService {
127128 protected settings = ts . getDefaultCompilerOptions ( ) ) {
128129 }
129130
130- public getNewLine ( ) : string {
131- return "\r\n" ;
132- }
131+ public getNewLine ( ) : string { return "\r\n" ; }
133132
134133 public getFilenames ( ) : string [ ] {
135134 var fileNames : string [ ] = [ ] ;
@@ -145,20 +144,10 @@ module Harness.LanguageService {
145144 this . fileNameToScript [ fileName ] = new ScriptInfo ( fileName , content ) ;
146145 }
147146
148- public updateScript ( fileName : string , content : string ) {
149- var script = this . getScriptInfo ( fileName ) ;
150- if ( script !== null ) {
151- script . updateContent ( content ) ;
152- return ;
153- }
154-
155- this . addScript ( fileName , content ) ;
156- }
157-
158- public editScript ( fileName : string , minChar : number , limChar : number , newText : string ) {
147+ public editScript ( fileName : string , start : number , end : number , newText : string ) {
159148 var script = this . getScriptInfo ( fileName ) ;
160149 if ( script !== null ) {
161- script . editContent ( minChar , limChar , newText ) ;
150+ script . editContent ( start , end , newText ) ;
162151 return ;
163152 }
164153
@@ -236,8 +225,7 @@ module Harness.LanguageService {
236225 getFilenames ( ) : string [ ] { return this . nativeHost . getFilenames ( ) ; }
237226 getScriptInfo ( fileName : string ) : ScriptInfo { return this . nativeHost . getScriptInfo ( fileName ) ; }
238227 addScript ( fileName : string , content : string ) : void { this . nativeHost . addScript ( fileName , content ) ; }
239- updateScript ( fileName : string , content : string ) : void { return this . nativeHost . updateScript ( fileName , content ) ; }
240- editScript ( fileName : string , minChar : number , limChar : number , newText : string ) : void { this . nativeHost . editScript ( fileName , minChar , limChar , newText ) ; }
228+ editScript ( fileName : string , start : number , end : number , newText : string ) : void { this . nativeHost . editScript ( fileName , start , end , newText ) ; }
241229 lineColToPosition ( fileName : string , line : number , col : number ) : number { return this . nativeHost . lineColToPosition ( fileName , line , col ) ; }
242230 positionToZeroBasedLineCol ( fileName : string , position : number ) : ts . LineAndCharacter { return this . nativeHost . positionToZeroBasedLineCol ( fileName , position ) ; }
243231
@@ -442,5 +430,43 @@ module Harness.LanguageService {
442430 return convertResult ;
443431 }
444432 }
433+
434+ // Server adapter
435+ class ServerLanguageServiceHost extends NativeLanguageServiceHost {
436+ private client : ts . server . SessionClient ;
437+ constructor ( cancellationToken : ts . CancellationToken , settings : ts . CompilerOptions ) {
438+ super ( cancellationToken , settings ) ;
439+ }
440+
441+ setClient ( client : ts . server . SessionClient ) {
442+ this . client = client ;
443+ }
444+
445+ addScript ( fileName : string , content : string ) : void {
446+ super . addScript ( fileName , content ) ;
447+ this . client . openFile ( fileName ) ;
448+ }
449+
450+ editScript ( fileName : string , start : number , end : number , newText : string ) {
451+ super . editScript ( fileName , start , end , newText ) ;
452+ this . client . changeFile ( fileName , start , end , newText ) ;
453+ }
454+ }
455+
456+ export class ServerLanugageServiceAdapter implements LanguageServiceAdapter {
457+ private host : ServerLanguageServiceHost ;
458+ private client : ts . server . SessionClient ;
459+ constructor ( cancellationToken ?: ts . CancellationToken , options ?: ts . CompilerOptions ) {
460+ debugger ;
461+
462+ this . host = new ServerLanguageServiceHost ( cancellationToken , options ) ;
463+ this . client = new ts . server . SessionClient ( this . host ) ;
464+ this . host . setClient ( this . client ) ;
465+ }
466+ getHost ( ) { return this . host ; }
467+ getLanguageService ( ) : ts . LanguageService { return this . client ; }
468+ getClassifier ( ) : ts . Classifier { throw new Error ( "getClassifier is not available using the server interface." ) ; }
469+ getPreProcessedFileInfo ( fileName : string , fileContents : string ) : ts . PreProcessedFileInfo { throw new Error ( "getPreProcessedFileInfo is not available using the server interface." ) ; }
470+ }
445471}
446472
0 commit comments