@@ -425,11 +425,35 @@ namespace ts.server {
425425 }
426426
427427 getSyntacticDiagnostics ( fileName : string ) : Diagnostic [ ] {
428- throw new Error ( "Not Implemented Yet." ) ;
428+ const args : protocol . SyntacticDiagnosticsSyncRequestArgs = { file : fileName } ;
429+
430+ const request = this . processRequest < protocol . SyntacticDiagnosticsSyncRequest > ( CommandNames . SyntacticDiagnosticsSync , args ) ;
431+ const response = this . processResponse < protocol . SyntacticDiagnosticsSyncResponse > ( request ) ;
432+
433+ return ( < protocol . Diagnostic [ ] > response . body ) . map ( entry => this . convertDiagnostic ( entry , fileName ) ) ;
429434 }
430435
431436 getSemanticDiagnostics ( fileName : string ) : Diagnostic [ ] {
432- throw new Error ( "Not Implemented Yet." ) ;
437+ const args : protocol . SemanticDiagnosticsSyncRequestArgs = { file : fileName } ;
438+
439+ const request = this . processRequest < protocol . SemanticDiagnosticsSyncRequest > ( CommandNames . SemanticDiagnosticsSync , args ) ;
440+ const response = this . processResponse < protocol . SemanticDiagnosticsSyncResponse > ( request ) ;
441+
442+ return ( < protocol . Diagnostic [ ] > response . body ) . map ( entry => this . convertDiagnostic ( entry , fileName ) ) ;
443+ }
444+
445+ convertDiagnostic ( entry : protocol . Diagnostic , fileName : string ) : Diagnostic {
446+ const start = this . lineOffsetToPosition ( fileName , entry . start ) ;
447+ const end = this . lineOffsetToPosition ( fileName , entry . end ) ;
448+
449+ return {
450+ file : undefined ,
451+ start : start ,
452+ length : end - start ,
453+ messageText : entry . text ,
454+ category : undefined ,
455+ code : entry . code
456+ } ;
433457 }
434458
435459 getCompilerOptionsDiagnostics ( ) : Diagnostic [ ] {
@@ -630,8 +654,46 @@ namespace ts.server {
630654 throw new Error ( "Not Implemented Yet." ) ;
631655 }
632656
633- getCodeFixesAtPosition ( fileName : string , start : number , end : number , errorCodes : number [ ] ) : ts . CodeAction [ ] {
634- throw new Error ( "Not Implemented Yet." ) ;
657+ getCodeFixesAtPosition ( fileName : string , start : number , end : number , errorCodes : number [ ] ) : CodeAction [ ] {
658+ const startLineOffset = this . positionToOneBasedLineOffset ( fileName , start ) ;
659+ const endLineOffset = this . positionToOneBasedLineOffset ( fileName , end ) ;
660+
661+ const args : protocol . CodeFixRequestArgs = {
662+ file : fileName ,
663+ startLine : startLineOffset . line ,
664+ startOffset : startLineOffset . offset ,
665+ endLine : endLineOffset . line ,
666+ endOffset : endLineOffset . offset ,
667+ errorCodes : errorCodes ,
668+ } ;
669+
670+ const request = this . processRequest < protocol . CodeFixRequest > ( CommandNames . GetCodeFixesFull , args ) ;
671+ const response = this . processResponse < protocol . CodeFixResponse > ( request ) ;
672+
673+ return response . body . map ( entry => this . convertCodeActions ( entry , fileName ) ) ;
674+ }
675+
676+ convertCodeActions ( entry : protocol . CodeAction , fileName : string ) : CodeAction {
677+ return {
678+ description : entry . description ,
679+ changes : entry . changes . map ( change => ( {
680+ fileName : change . fileName ,
681+ textChanges : change . textChanges . map ( textChange => this . convertTextChangeToCodeEdit ( textChange , fileName ) )
682+ } ) )
683+ } ;
684+ }
685+
686+ convertTextChangeToCodeEdit ( change : protocol . CodeEdit , fileName : string ) : ts . TextChange {
687+ const start = this . lineOffsetToPosition ( fileName , change . start ) ;
688+ const end = this . lineOffsetToPosition ( fileName , change . end ) ;
689+
690+ return {
691+ span : {
692+ start : start ,
693+ length : end - start
694+ } ,
695+ newText : change . newText ? change . newText : ""
696+ } ;
635697 }
636698
637699 getBraceMatchingAtPosition ( fileName : string , position : number ) : TextSpan [ ] {
0 commit comments