@@ -1887,6 +1887,45 @@ export class Session<TMessage = string> implements EventSender {
1887
1887
} ) ;
1888
1888
}
1889
1889
1890
+ private mapCode ( args : protocol . MapCodeRequestArgs ) : protocol . FileCodeEdits [ ] {
1891
+ const { file, project } = this . getFileAndProject ( args ) ;
1892
+ const scriptInfo = this . projectService . getScriptInfoForNormalizedPath ( file ) ! ;
1893
+ const selected = args . context ?. selected ?. map ( span => {
1894
+ const start = scriptInfo . lineOffsetToPosition ( span . start . line , span . start . offset ) ;
1895
+ const end = scriptInfo . lineOffsetToPosition ( span . end . line , span . end . offset ) ;
1896
+ return {
1897
+ start,
1898
+ length : end - start ,
1899
+ } ;
1900
+ } ) ;
1901
+ const updates = args . context ?. updates ?. map ( edit => {
1902
+ return {
1903
+ fileName : edit . fileName ,
1904
+ textChanges : edit . textChanges . map ( ( { start, end, newText } ) => {
1905
+ const newStart = scriptInfo . lineOffsetToPosition ( start . line , start . offset ) ;
1906
+ const newEnd = scriptInfo . lineOffsetToPosition ( end . line , end . offset ) ;
1907
+ return {
1908
+ span : { start : newStart , length : newEnd - newStart } ,
1909
+ newText,
1910
+ } ;
1911
+ } ) ,
1912
+ } ;
1913
+ } ) ;
1914
+ return project . getLanguageService ( ) . mapCode ( file , args . contents , selected , updates ) ?. map ( change => {
1915
+ return {
1916
+ fileName : change . fileName ,
1917
+ textChanges : change . textChanges . map ( ( { span, newText } ) => {
1918
+ const newSpan = toProtocolTextSpan ( span , scriptInfo ) ;
1919
+ return {
1920
+ start : newSpan . start ,
1921
+ end : newSpan . end ,
1922
+ newText
1923
+ } ;
1924
+ } ) ,
1925
+ } ;
1926
+ } ) ;
1927
+ }
1928
+
1890
1929
private setCompilerOptionsForInferredProjects ( args : protocol . SetCompilerOptionsForInferredProjectsArgs ) : void {
1891
1930
this . projectService . setCompilerOptionsForInferredProjects ( args . options , args . projectRootPath ) ;
1892
1931
}
@@ -3556,6 +3595,9 @@ export class Session<TMessage = string> implements EventSender {
3556
3595
[ protocol . CommandTypes . ProvideInlayHints ] : ( request : protocol . InlayHintsRequest ) => {
3557
3596
return this . requiredResponse ( this . provideInlayHints ( request . arguments ) ) ;
3558
3597
} ,
3598
+ [ protocol . CommandTypes . MapCode ] : ( request : protocol . MapCodeRequest ) => {
3599
+ return this . requiredResponse ( this . mapCode ( request . arguments ) ) ;
3600
+ } ,
3559
3601
} ) ) ;
3560
3602
3561
3603
public addProtocolHandler ( command : string , handler : ( request : protocol . Request ) => HandlerResponse ) {
0 commit comments