@@ -136,6 +136,7 @@ namespace ts.server {
136136 export const CompilerOptionsForInferredProjects = "compilerOptionsForInferredProjects" ;
137137 export const GetCodeFixes = "getCodeFixes" ;
138138 export const GetCodeFixesFull = "getCodeFixes-full" ;
139+ export const GetSupportedCodeFixes = "getSupportedCodeFixes" ;
139140 }
140141
141142 export function formatMessage < T extends protocol . Message > ( msg : T , logger : server . Logger , byteLength : ( s : string , encoding : string ) => number , newLine : string ) : string {
@@ -844,13 +845,7 @@ namespace ts.server {
844845 return undefined ;
845846 }
846847
847- return edits . map ( ( edit ) => {
848- return {
849- start : scriptInfo . positionToLineOffset ( edit . span . start ) ,
850- end : scriptInfo . positionToLineOffset ( ts . textSpanEnd ( edit . span ) ) ,
851- newText : edit . newText ? edit . newText : ""
852- } ;
853- } ) ;
848+ return edits . map ( edit => this . convertTextChangeToCodeEdit ( edit , scriptInfo ) ) ;
854849 }
855850
856851 private getFormattingEditsForRangeFull ( args : protocol . FormatRequestArgs ) {
@@ -1201,6 +1196,10 @@ namespace ts.server {
12011196 }
12021197 }
12031198
1199+ private getSupportedCodeFixes ( ) : string [ ] {
1200+ return ts . getSupportedCodeFixes ( ) ;
1201+ }
1202+
12041203 private getCodeFixes ( args : protocol . CodeFixRequestArgs , simplifiedResult : boolean ) : protocol . CodeAction [ ] | CodeAction [ ] {
12051204 const { file, project } = this . getFileAndProjectWithoutRefreshingInferredProjects ( args ) ;
12061205
@@ -1213,28 +1212,12 @@ namespace ts.server {
12131212 return undefined ;
12141213 }
12151214 if ( simplifiedResult ) {
1216- return codeActions . map ( mapCodeAction ) ;
1215+ return codeActions . map ( codeAction => this . mapCodeAction ( codeAction , scriptInfo ) ) ;
12171216 }
12181217 else {
12191218 return codeActions ;
12201219 }
12211220
1222- function mapCodeAction ( source : CodeAction ) : protocol . CodeAction {
1223- return {
1224- description : source . description ,
1225- changes : source . changes . map ( change => ( {
1226- fileName : change . fileName ,
1227- textChanges : change . textChanges . map ( textChange => ( {
1228- span : {
1229- start : scriptInfo . positionToLineOffset ( textChange . span . start ) ,
1230- end : scriptInfo . positionToLineOffset ( textChange . span . start + textChange . span . length )
1231- } ,
1232- newText : textChange . newText
1233- } ) )
1234- } ) )
1235- } ;
1236- }
1237-
12381221 function getStartPosition ( ) {
12391222 return args . startPosition !== undefined ? args . startPosition : scriptInfo . lineOffsetToPosition ( args . startLine , args . startOffset ) ;
12401223 }
@@ -1244,6 +1227,24 @@ namespace ts.server {
12441227 }
12451228 }
12461229
1230+ private mapCodeAction ( codeAction : CodeAction , scriptInfo : ScriptInfo ) : protocol . CodeAction {
1231+ return {
1232+ description : codeAction . description ,
1233+ changes : codeAction . changes . map ( change => ( {
1234+ fileName : change . fileName ,
1235+ textChanges : change . textChanges . map ( textChange => this . convertTextChangeToCodeEdit ( textChange , scriptInfo ) )
1236+ } ) )
1237+ } ;
1238+ }
1239+
1240+ private convertTextChangeToCodeEdit ( change : ts . TextChange , scriptInfo : ScriptInfo ) : protocol . CodeEdit {
1241+ return {
1242+ start : scriptInfo . positionToLineOffset ( change . span . start ) ,
1243+ end : scriptInfo . positionToLineOffset ( change . span . start + change . span . length ) ,
1244+ newText : change . newText
1245+ } ;
1246+ }
1247+
12471248 private getBraceMatching ( args : protocol . FileLocationRequestArgs , simplifiedResult : boolean ) : protocol . TextSpan [ ] | TextSpan [ ] {
12481249 const { file, project } = this . getFileAndProjectWithoutRefreshingInferredProjects ( args ) ;
12491250
@@ -1572,6 +1573,9 @@ namespace ts.server {
15721573 } ,
15731574 [ CommandNames . GetCodeFixesFull ] : ( request : protocol . CodeFixRequest ) => {
15741575 return this . requiredResponse ( this . getCodeFixes ( request . arguments , /*simplifiedResult*/ false ) ) ;
1576+ } ,
1577+ [ CommandNames . GetSupportedCodeFixes ] : ( request : protocol . Request ) => {
1578+ return this . requiredResponse ( this . getSupportedCodeFixes ( ) ) ;
15751579 }
15761580 } ) ;
15771581
0 commit comments