@@ -1433,7 +1433,7 @@ namespace ts.server {
1433
1433
return project . getLanguageService ( ) . getCompletionEntryDetails ( file , position , name , formattingOptions , source , this . getPreferences ( file ) ) ;
1434
1434
} ) ;
1435
1435
return simplifiedResult
1436
- ? result . map ( details => ( { ...details , codeActions : map ( details . codeActions , action => this . mapCodeAction ( project , action ) ) } ) )
1436
+ ? result . map ( details => ( { ...details , codeActions : map ( details . codeActions , action => this . mapCodeAction ( action ) ) } ) )
1437
1437
: result ;
1438
1438
}
1439
1439
@@ -1735,7 +1735,7 @@ namespace ts.server {
1735
1735
const renameScriptInfo = project . getScriptInfoForNormalizedPath ( toNormalizedPath ( renameFilename ) ) ! ;
1736
1736
mappedRenameLocation = getLocationInNewDocument ( getSnapshotText ( renameScriptInfo . getSnapshot ( ) ) , renameFilename , renameLocation , edits ) ;
1737
1737
}
1738
- return { renameLocation : mappedRenameLocation , renameFilename, edits : this . mapTextChangesToCodeEdits ( project , edits ) } ;
1738
+ return { renameLocation : mappedRenameLocation , renameFilename, edits : this . mapTextChangesToCodeEdits ( edits ) } ;
1739
1739
}
1740
1740
else {
1741
1741
return result ;
@@ -1747,7 +1747,7 @@ namespace ts.server {
1747
1747
const { file, project } = this . getFileAndProject ( scope . args ) ;
1748
1748
const changes = project . getLanguageService ( ) . organizeImports ( { type : "file" , fileName : file } , this . getFormatOptions ( file ) , this . getPreferences ( file ) ) ;
1749
1749
if ( simplifiedResult ) {
1750
- return this . mapTextChangesToCodeEdits ( project , changes ) ;
1750
+ return this . mapTextChangesToCodeEdits ( changes ) ;
1751
1751
}
1752
1752
else {
1753
1753
return changes ;
@@ -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 . mapTextChangeToCodeEditUsingScriptInfoOrConfigFile ( c ) ) : changes ;
1766
+ return simplifiedResult ? changes . map ( c => this . mapTextChangeToCodeEdit ( c ) ) : changes ;
1767
1767
}
1768
1768
1769
1769
private getCodeFixes ( args : protocol . CodeFixRequestArgs , simplifiedResult : boolean ) : ReadonlyArray < protocol . CodeFixAction > | ReadonlyArray < CodeFixAction > | undefined {
@@ -1776,15 +1776,15 @@ namespace ts.server {
1776
1776
const { startPosition, endPosition } = this . getStartAndEndPosition ( args , scriptInfo ) ;
1777
1777
1778
1778
const codeActions = project . getLanguageService ( ) . getCodeFixesAtPosition ( file , startPosition , endPosition , args . errorCodes ! , this . getFormatOptions ( file ) , this . getPreferences ( file ) ) ;
1779
- return simplifiedResult ? codeActions . map ( codeAction => this . mapCodeFixAction ( project , codeAction ) ) : codeActions ;
1779
+ return simplifiedResult ? codeActions . map ( codeAction => this . mapCodeFixAction ( codeAction ) ) : codeActions ;
1780
1780
}
1781
1781
1782
1782
private getCombinedCodeFix ( { scope, fixId } : protocol . GetCombinedCodeFixRequestArgs , simplifiedResult : boolean ) : protocol . CombinedCodeActions | CombinedCodeActions {
1783
1783
Debug . assert ( scope . type === "file" ) ;
1784
1784
const { file, project } = this . getFileAndProject ( scope . args ) ;
1785
1785
const res = project . getLanguageService ( ) . getCombinedCodeFix ( { type : "file" , fileName : file } , fixId , this . getFormatOptions ( file ) , this . getPreferences ( file ) ) ;
1786
1786
if ( simplifiedResult ) {
1787
- return { changes : this . mapTextChangesToCodeEdits ( project , res . changes ) , commands : res . commands } ;
1787
+ return { changes : this . mapTextChangesToCodeEdits ( res . changes ) , commands : res . commands } ;
1788
1788
}
1789
1789
else {
1790
1790
return res ;
@@ -1824,28 +1824,20 @@ namespace ts.server {
1824
1824
return { startPosition, endPosition } ;
1825
1825
}
1826
1826
1827
- private mapCodeAction ( project : Project , { description, changes, commands } : CodeAction ) : protocol . CodeAction {
1828
- return { description, changes : this . mapTextChangesToCodeEdits ( project , changes ) , commands } ;
1827
+ private mapCodeAction ( { description, changes, commands } : CodeAction ) : protocol . CodeAction {
1828
+ return { description, changes : this . mapTextChangesToCodeEdits ( changes ) , commands } ;
1829
1829
}
1830
1830
1831
- private mapCodeFixAction ( project : Project , { fixName, description, changes, commands, fixId, fixAllDescription } : CodeFixAction ) : protocol . CodeFixAction {
1832
- return { fixName, description, changes : this . mapTextChangesToCodeEdits ( project , changes ) , commands, fixId, fixAllDescription } ;
1831
+ private mapCodeFixAction ( { fixName, description, changes, commands, fixId, fixAllDescription } : CodeFixAction ) : protocol . CodeFixAction {
1832
+ return { fixName, description, changes : this . mapTextChangesToCodeEdits ( changes ) , commands, fixId, fixAllDescription } ;
1833
1833
}
1834
1834
1835
- private mapTextChangesToCodeEdits ( project : Project , textChanges : ReadonlyArray < FileTextChanges > ) : protocol . FileCodeEdits [ ] {
1836
- return textChanges . map ( change => this . mapTextChangeToCodeEdit ( project , change ) ) ;
1835
+ private mapTextChangesToCodeEdits ( textChanges : ReadonlyArray < FileTextChanges > ) : protocol . FileCodeEdits [ ] {
1836
+ return textChanges . map ( change => this . mapTextChangeToCodeEdit ( change ) ) ;
1837
1837
}
1838
1838
1839
- private mapTextChangeToCodeEdit ( project : Project , change : FileTextChanges ) : protocol . FileCodeEdits {
1840
- return mapTextChangesToCodeEditsForFile ( change , project . getSourceFileOrConfigFile ( this . normalizePath ( change . fileName ) ) ) ;
1841
- }
1842
-
1843
- private mapTextChangeToCodeEditUsingScriptInfoOrConfigFile ( change : FileTextChanges ) : protocol . FileCodeEdits {
1844
- return mapTextChangesToCodeEditsUsingScriptInfoOrConfig ( change , this . projectService . getScriptInfoOrConfig ( this . normalizePath ( change . fileName ) ) ) ;
1845
- }
1846
-
1847
- private normalizePath ( fileName : string ) {
1848
- return normalizedPathToPath ( toNormalizedPath ( fileName ) , this . host . getCurrentDirectory ( ) , fileName => this . getCanonicalFileName ( fileName ) ) ;
1839
+ private mapTextChangeToCodeEdit ( change : FileTextChanges ) : protocol . FileCodeEdits {
1840
+ return mapTextChangesToCodeEdits ( change , this . projectService . getScriptInfoOrConfig ( change . fileName ) ) ;
1849
1841
}
1850
1842
1851
1843
private convertTextChangeToCodeEdit ( change : TextChange , scriptInfo : ScriptInfo ) : protocol . CodeEdit {
@@ -2357,35 +2349,14 @@ namespace ts.server {
2357
2349
return { file : fileName , start : scriptInfo . positionToLineOffset ( textSpan . start ) , end : scriptInfo . positionToLineOffset ( textSpanEnd ( textSpan ) ) } ;
2358
2350
}
2359
2351
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 } ) ) ;
2362
- if ( sourceFile ) {
2363
- return {
2364
- fileName : textChanges . fileName ,
2365
- textChanges : textChanges . textChanges . map ( textChange => convertTextChangeToCodeEdit ( textChange , sourceFile ) ) ,
2366
- } ;
2367
- }
2368
- else {
2369
- return convertNewFileTextChangeToCodeEdit ( textChanges ) ;
2370
- }
2371
- }
2372
-
2373
- function mapTextChangesToCodeEditsUsingScriptInfoOrConfig ( textChanges : FileTextChanges , scriptInfo : ScriptInfoOrConfig | undefined ) : protocol . FileCodeEdits {
2352
+ function mapTextChangesToCodeEdits ( textChanges : FileTextChanges , scriptInfo : ScriptInfoOrConfig | undefined ) : protocol . FileCodeEdits {
2374
2353
Debug . assert ( ! ! textChanges . isNewFile === ! scriptInfo , "Expected isNewFile for (only) new files" , ( ) => JSON . stringify ( { isNewFile : ! ! textChanges . isNewFile , hasScriptInfo : ! ! scriptInfo } ) ) ;
2375
2354
return scriptInfo
2376
- ? { fileName : textChanges . fileName , textChanges : textChanges . textChanges . map ( textChange => convertTextChangeToCodeEditUsingScriptInfoOrConfig ( textChange , scriptInfo ) ) }
2355
+ ? { fileName : textChanges . fileName , textChanges : textChanges . textChanges . map ( textChange => convertTextChangeToCodeEdit ( textChange , scriptInfo ) ) }
2377
2356
: convertNewFileTextChangeToCodeEdit ( textChanges ) ;
2378
2357
}
2379
2358
2380
- function convertTextChangeToCodeEdit ( change : TextChange , sourceFile : SourceFile ) : protocol . CodeEdit {
2381
- return {
2382
- start : convertToLocation ( sourceFile . getLineAndCharacterOfPosition ( change . span . start ) ) ,
2383
- end : convertToLocation ( sourceFile . getLineAndCharacterOfPosition ( change . span . start + change . span . length ) ) ,
2384
- newText : change . newText ? change . newText : "" ,
2385
- } ;
2386
- }
2387
-
2388
- function convertTextChangeToCodeEditUsingScriptInfoOrConfig ( change : TextChange , scriptInfo : ScriptInfoOrConfig ) : protocol . CodeEdit {
2359
+ function convertTextChangeToCodeEdit ( change : TextChange , scriptInfo : ScriptInfoOrConfig ) : protocol . CodeEdit {
2389
2360
return { start : positionToLineOffset ( scriptInfo , change . span . start ) , end : positionToLineOffset ( scriptInfo , textSpanEnd ( change . span ) ) , newText : change . newText } ;
2390
2361
}
2391
2362
0 commit comments