@@ -125,7 +125,7 @@ module ts.server {
125125 }
126126
127127 private setupExpantionTable ( ) : void {
128- var request = this . processRequest ( "abbrev" ) ;
128+ var request = this . processRequest < ServerProtocol . AbbrevRequest > ( CommandNames . Abbrev ) ;
129129 var response = this . processResponse < ServerProtocol . AbbrevResponse > ( request ) ;
130130 var abbriviationTable = response . body ;
131131
@@ -198,20 +198,7 @@ module ts.server {
198198 return fileName ;
199199 }
200200
201- private processRequest ( command : "abbrev" ) : ServerProtocol . AbbrevRequest ;
202- private processRequest ( command : "open" , arguments : ServerProtocol . FileRequestArgs ) : ServerProtocol . OpenRequest ;
203- private processRequest ( command : "close" , arguments : ServerProtocol . FileRequestArgs ) : ServerProtocol . CloseRequest ;
204- private processRequest ( command : "change" , arguments : ServerProtocol . ChangeRequestArgs ) : ServerProtocol . ChangeRequest ;
205- private processRequest ( command : "quickinfo" , arguments : ServerProtocol . FileRequestArgs ) : ServerProtocol . QuickInfoRequest ;
206- private processRequest ( command : "format" , arguments : ServerProtocol . FormatRequestArgs ) : ServerProtocol . FormatRequest ;
207- private processRequest ( command : "formatonkey" , arguments : ServerProtocol . FormatOnKeyRequestArgs ) : ServerProtocol . FormatRequest ;
208- private processRequest ( command : "definition" , arguments : ServerProtocol . FileRequestArgs ) : ServerProtocol . DefinitionRequest ;
209- private processRequest ( command : "references" , arguments : ServerProtocol . FileRequestArgs ) : ServerProtocol . ReferencesRequest ;
210- private processRequest ( command : "completions" , arguments : ServerProtocol . CompletionsRequestArgs ) : ServerProtocol . CompletionsRequest ;
211- private processRequest ( command : "navto" , arguments : ServerProtocol . NavtoRequestArgs ) : ServerProtocol . NavtoRequest ;
212- private processRequest ( command : "saveto" , arguments : ServerProtocol . SavetoRequestArgs ) : ServerProtocol . SavetoRequest ;
213- private processRequest ( command : string , arguments ?: any ) : ServerProtocol . Request ;
214- private processRequest ( command : string , arguments : any ) : ServerProtocol . Request {
201+ private processRequest < T extends ServerProtocol . Request > ( command : string , arguments ?: any ) : T {
215202 var request : ServerProtocol . Request = {
216203 seq : this . sequence ++ ,
217204 type : "request" ,
@@ -221,7 +208,7 @@ module ts.server {
221208
222209 this . session . executeJSONcmd ( JSON . stringify ( request ) ) ;
223210
224- return request ;
211+ return < T > request ;
225212 }
226213
227214 private processResponse < T extends ServerProtocol . Response > ( request : ServerProtocol . Request ) : T {
@@ -271,37 +258,37 @@ module ts.server {
271258 }
272259
273260 openFile ( fileName : string ) : void {
274- this . processRequest ( "open" , {
275- file : fileName
276- } ) ;
261+ var args : ServerProtocol . FileRequestArgs = { file : fileName } ;
262+ this . processRequest ( CommandNames . Open , args ) ;
277263 }
278264
279265 closeFile ( fileName : string ) : void {
280- this . processRequest ( "close" , {
281- file : fileName
282- } ) ;
266+ var args : ServerProtocol . FileRequestArgs = { file : fileName } ;
267+ this . processRequest ( CommandNames . Close , args ) ;
283268 }
284269
285270 changeFile ( fileName : string , start : number , end : number , newText : string ) : void {
286271 var lineCol = this . positionToOneBasedLineCol ( fileName , start ) ;
287-
288- this . processRequest ( "change" , {
272+ var args : ServerProtocol . ChangeRequestArgs = {
289273 file : fileName ,
290274 line : lineCol . line ,
291275 col : lineCol . col ,
292276 insertLen : end - start ,
293277 deleteLen : end - start ,
294278 insertString : newText
295- } ) ;
279+ } ;
280+
281+ this . processRequest ( CommandNames . Change , args ) ;
296282 }
297283
298284 getQuickInfoAtPosition ( fileName : string , position : number ) : QuickInfo {
299- var request = this . processRequest ( "quickinfo" , {
285+ var args : ServerProtocol . CodeLocationRequestArgs = {
300286 file : fileName ,
301287 line : 0 ,
302288 col : 1
303- } ) ;
289+ } ;
304290
291+ var request = this . processRequest < ServerProtocol . QuickInfoRequest > ( CommandNames . Quickinfo , args ) ;
305292 var response = this . processResponse < ServerProtocol . QuickInfoResponse > ( request ) ;
306293
307294 var start = this . lineColToPosition ( fileName , response . body . start ) ;
@@ -320,12 +307,13 @@ module ts.server {
320307
321308 getCompletionsAtPosition ( fileName : string , position : number ) : CompletionInfo {
322309 var lineCol = this . positionToOneBasedLineCol ( fileName , position ) ;
323- var request = this . processRequest ( "completions" , {
310+ var args : ServerProtocol . CodeLocationRequestArgs = {
324311 file : fileName ,
325312 line : lineCol . line ,
326313 col : lineCol . col ,
327- } ) ;
314+ } ;
328315
316+ var request = this . processRequest < ServerProtocol . CompletionsRequest > ( CommandNames . Completions , args ) ;
329317 var response = this . processResponse < ServerProtocol . CompletionsResponse > ( request ) ;
330318
331319 return {
@@ -336,11 +324,12 @@ module ts.server {
336324 }
337325
338326 getNavigateToItems ( searchTerm : string ) : NavigateToItem [ ] {
339- var request = this . processRequest ( "navto" , {
340- searchTerm,
327+ var args : ServerProtocol . NavtoRequestArgs = {
328+ searchTerm,
341329 file : this . host . getFileNames ( ) [ 0 ]
342- } ) ;
343-
330+ } ;
331+
332+ var request = this . processRequest < ServerProtocol . NavtoRequest > ( CommandNames . Navto , args ) ;
344333 var response = this . processResponse < ServerProtocol . NavtoResponse > ( request ) ;
345334
346335 return response . body . map ( entry => {
@@ -364,15 +353,16 @@ module ts.server {
364353 getFormattingEditsForRange ( fileName : string , start : number , end : number , options : ts . FormatCodeOptions ) : ts . TextChange [ ] {
365354 var startLineCol = this . positionToOneBasedLineCol ( fileName , start ) ;
366355 var endLineCol = this . positionToOneBasedLineCol ( fileName , end ) ;
367- // TODO: handle FormatCodeOptions
368- var request = this . processRequest ( "format" , {
356+ var args : ServerProtocol . FormatRequestArgs = {
369357 file : fileName ,
370358 line : startLineCol . line ,
371359 col : startLineCol . col ,
372360 endLine : endLineCol . line ,
373361 endCol : endLineCol . col ,
374- } ) ;
362+ } ;
375363
364+ // TODO: handle FormatCodeOptions
365+ var request = this . processRequest < ServerProtocol . FormatRequest > ( CommandNames . Format , args ) ;
376366 var response = this . processResponse < ServerProtocol . FormatResponse > ( request ) ;
377367
378368 return response . body . map ( entry => this . convertCodeEditsToTextChange ( fileName , entry ) ) ;
@@ -384,27 +374,31 @@ module ts.server {
384374
385375 getFormattingEditsAfterKeystroke ( fileName : string , position : number , key : string , options : FormatCodeOptions ) : ts . TextChange [ ] {
386376 var lineCol = this . positionToOneBasedLineCol ( fileName , position ) ;
387- // TODO: handle FormatCodeOptions
388- var request = this . processRequest ( "formatonkey" , {
377+ var args : ServerProtocol . FormatOnKeyRequestArgs = {
389378 file : fileName ,
390379 line : lineCol . line ,
391380 col : lineCol . col ,
392381 key : key
393- } ) ;
382+ } ;
394383
384+ // TODO: handle FormatCodeOptions
385+ var request = this . processRequest < ServerProtocol . FormatOnKeyRequest > ( CommandNames . Formatonkey , args ) ;
395386 var response = this . processResponse < ServerProtocol . FormatResponse > ( request ) ;
387+
396388 return response . body . map ( entry => this . convertCodeEditsToTextChange ( fileName , entry ) ) ;
397389 }
398390
399391 getDefinitionAtPosition ( fileName : string , position : number ) : DefinitionInfo [ ] {
400392 var lineCol = this . positionToOneBasedLineCol ( fileName , position ) ;
401- var request = this . processRequest ( "definition" , {
393+ var args : ServerProtocol . CodeLocationRequestArgs = {
402394 file : fileName ,
403395 line : lineCol . line ,
404396 col : lineCol . col ,
405- } ) ;
397+ } ;
406398
399+ var request = this . processRequest < ServerProtocol . DefinitionRequest > ( CommandNames . Definition , args ) ;
407400 var response = this . processResponse < ServerProtocol . DefinitionResponse > ( request ) ;
401+
408402 return response . body . map ( entry => {
409403 var start = this . lineColToPosition ( fileName , entry . start ) ;
410404 var end = this . lineColToPosition ( fileName , entry . end ) ;
@@ -421,12 +415,13 @@ module ts.server {
421415
422416 getReferencesAtPosition ( fileName : string , position : number ) : ReferenceEntry [ ] {
423417 var lineCol = this . positionToOneBasedLineCol ( fileName , position ) ;
424- var request = this . processRequest ( "references" , {
418+ var args : ServerProtocol . CodeLocationRequestArgs = {
425419 file : fileName ,
426420 line : lineCol . line ,
427421 col : lineCol . col ,
428- } ) ;
422+ } ;
429423
424+ var request = this . processRequest < ServerProtocol . ReferencesRequest > ( CommandNames . References , args ) ;
430425 var response = this . processResponse < ServerProtocol . ReferencesResponse > ( request ) ;
431426
432427 return response . body . refs . map ( entry => {
0 commit comments