@@ -1763,7 +1763,7 @@ namespace ts.server {
1763
1763
this . projectService ,
1764
1764
project => project . getLanguageService ( ) . getEditsForFileRename ( oldPath , newPath , formatOptions , preferences ) ,
1765
1765
( a , b ) => a . fileName === b . fileName ) ;
1766
- return simplifiedResult ? changes . map ( c => this . mapTextChangeToCodeEditUsingScriptInfo ( c ) ) : changes ;
1766
+ return simplifiedResult ? changes . map ( c => this . mapTextChangeToCodeEditUsingScriptInfoOrConfigFile ( c ) ) : changes ;
1767
1767
}
1768
1768
1769
1769
private getCodeFixes ( args : protocol . CodeFixRequestArgs , simplifiedResult : boolean ) : ReadonlyArray < protocol . CodeFixAction > | ReadonlyArray < CodeFixAction > | undefined {
@@ -1840,8 +1840,8 @@ namespace ts.server {
1840
1840
return mapTextChangesToCodeEditsForFile ( change , project . getSourceFileOrConfigFile ( this . normalizePath ( change . fileName ) ) ) ;
1841
1841
}
1842
1842
1843
- private mapTextChangeToCodeEditUsingScriptInfo ( change : FileTextChanges ) : protocol . FileCodeEdits {
1844
- return mapTextChangesToCodeEditsUsingScriptInfo ( change , this . projectService . getScriptInfo ( this . normalizePath ( change . fileName ) ) ) ;
1843
+ private mapTextChangeToCodeEditUsingScriptInfoOrConfigFile ( change : FileTextChanges ) : protocol . FileCodeEdits {
1844
+ return mapTextChangesToCodeEditsUsingScriptInfoOrConfig ( change , this . projectService . getScriptInfoOrConfig ( this . normalizePath ( change . fileName ) ) ) ;
1845
1845
}
1846
1846
1847
1847
private normalizePath ( fileName : string ) {
@@ -2358,7 +2358,7 @@ namespace ts.server {
2358
2358
}
2359
2359
2360
2360
function mapTextChangesToCodeEditsForFile ( textChanges : FileTextChanges , sourceFile : SourceFile | undefined ) : protocol . FileCodeEdits {
2361
- Debug . assert ( ! ! textChanges . isNewFile === ! sourceFile , "Expected isNewFile for (only) new files" , ( ) => JSON . stringify ( { isNewFile : textChanges . isNewFile , hasSourceFile : ! ! sourceFile } ) ) ;
2361
+ Debug . assert ( ! ! textChanges . isNewFile === ! sourceFile , "Expected isNewFile for (only) new files" , ( ) => JSON . stringify ( { isNewFile : ! ! textChanges . isNewFile , hasSourceFile : ! ! sourceFile } ) ) ;
2362
2362
if ( sourceFile ) {
2363
2363
return {
2364
2364
fileName : textChanges . fileName ,
@@ -2370,10 +2370,10 @@ namespace ts.server {
2370
2370
}
2371
2371
}
2372
2372
2373
- function mapTextChangesToCodeEditsUsingScriptInfo ( textChanges : FileTextChanges , scriptInfo : ScriptInfo | undefined ) : protocol . FileCodeEdits {
2374
- Debug . assert ( ! ! textChanges . isNewFile === ! scriptInfo ) ;
2373
+ function mapTextChangesToCodeEditsUsingScriptInfoOrConfig ( textChanges : FileTextChanges , scriptInfo : ScriptInfoOrConfig | undefined ) : protocol . FileCodeEdits {
2374
+ Debug . assert ( ! ! textChanges . isNewFile === ! scriptInfo , "Expected isNewFile for (only) new files" , ( ) => JSON . stringify ( { isNewFile : ! ! textChanges . isNewFile , hasScriptInfo : ! ! scriptInfo } ) ) ;
2375
2375
return scriptInfo
2376
- ? { fileName : textChanges . fileName , textChanges : textChanges . textChanges . map ( textChange => convertTextChangeToCodeEditUsingScriptInfo ( textChange , scriptInfo ) ) }
2376
+ ? { fileName : textChanges . fileName , textChanges : textChanges . textChanges . map ( textChange => convertTextChangeToCodeEditUsingScriptInfoOrConfig ( textChange , scriptInfo ) ) }
2377
2377
: convertNewFileTextChangeToCodeEdit ( textChanges ) ;
2378
2378
}
2379
2379
@@ -2385,8 +2385,16 @@ namespace ts.server {
2385
2385
} ;
2386
2386
}
2387
2387
2388
- function convertTextChangeToCodeEditUsingScriptInfo ( change : TextChange , scriptInfo : ScriptInfo ) {
2389
- return { start : scriptInfo . positionToLineOffset ( change . span . start ) , end : scriptInfo . positionToLineOffset ( textSpanEnd ( change . span ) ) , newText : change . newText } ;
2388
+ function convertTextChangeToCodeEditUsingScriptInfoOrConfig ( change : TextChange , scriptInfo : ScriptInfoOrConfig ) : protocol . CodeEdit {
2389
+ return { start : positionToLineOffset ( scriptInfo , change . span . start ) , end : positionToLineOffset ( scriptInfo , textSpanEnd ( change . span ) ) , newText : change . newText } ;
2390
+ }
2391
+
2392
+ function positionToLineOffset ( info : ScriptInfoOrConfig , position : number ) : protocol . Location {
2393
+ return isConfigFile ( info ) ? locationFromLineAndCharacter ( info . getLineAndCharacterOfPosition ( position ) ) : info . positionToLineOffset ( position ) ;
2394
+ }
2395
+
2396
+ function locationFromLineAndCharacter ( lc : LineAndCharacter ) : protocol . Location {
2397
+ return { line : lc . line + 1 , offset : lc . character + 1 } ;
2390
2398
}
2391
2399
2392
2400
function convertNewFileTextChangeToCodeEdit ( textChanges : FileTextChanges ) : protocol . FileCodeEdits {
0 commit comments