File tree Expand file tree Collapse file tree 4 files changed +26
-1
lines changed Expand file tree Collapse file tree 4 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 70
70
{
71
71
"command" : " printPerformanceMemoryInfo" ,
72
72
"title" : " Print Performance & Memory Info"
73
+ },
74
+ {
75
+ "command" : " migrateRequireToImports" ,
76
+ "title" : " Migrate Require to Imports"
73
77
}
74
78
],
75
79
"keybindings" : [
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import { compact } from '@zardoy/utils'
7
7
import { offsetPosition } from '@zardoy/vscode-utils/build/position'
8
8
import { RequestInputTypes , RequestOutputTypes } from '../typescript/src/ipcTypes'
9
9
import { sendCommand } from './sendCommand'
10
- import { tsRangeToVscode , tsRangeToVscodeSelection } from './util'
10
+ import { tsRangeToVscode , tsRangeToVscodeSelection , tsTextChangesToVscodeTextEdits } from './util'
11
11
import { onCompletionAcceptedOverride } from './onCompletionAccepted'
12
12
13
13
export default ( ) => {
@@ -309,6 +309,16 @@ export default () => {
309
309
console . show ( true )
310
310
} )
311
311
312
+ registerExtensionCommand ( 'migrateRequireToImports' , async ( ) => {
313
+ const data = await sendCommand ( 'getMigrateToImportsEdits' , { } )
314
+ if ( ! data ) return
315
+ const { document } = vscode . window . activeTextEditor !
316
+ const edits = tsTextChangesToVscodeTextEdits ( document , data )
317
+ const edit = new vscode . WorkspaceEdit ( )
318
+ edit . set ( document . uri , edits )
319
+ await vscode . workspace . applyEdit ( edit )
320
+ } )
321
+
312
322
// registerExtensionCommand('insertImportFlatten', () => {
313
323
// // got -> default, got
314
324
// type A = ts.Type
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ export const triggerCharacterCommands = [
17
17
'getLastResolvedCompletion' ,
18
18
'getArgumentReferencesFromCurrentParameter' ,
19
19
'performanceInfo' ,
20
+ 'getMigrateToImportsEdits' ,
20
21
] as const
21
22
22
23
export type TriggerCharacterCommand = ( typeof triggerCharacterCommands ) [ number ]
@@ -115,6 +116,7 @@ export type RequestOutputTypes = {
115
116
}
116
117
getArgumentReferencesFromCurrentParameter : Array < { line : number ; character : number ; filename : string } >
117
118
'emmet-completions' : EmmetResult
119
+ getMigrateToImportsEdits : ts . TextChange [ ]
118
120
}
119
121
120
122
// export type EmmetResult = {
Original file line number Diff line number Diff line change @@ -304,6 +304,15 @@ export default (
304
304
memoryUsedMb : toMb ( process . memoryUsage ( ) . heapUsed ) ,
305
305
}
306
306
}
307
+ if ( specialCommand === 'getMigrateToImportsEdits' ) {
308
+ const combinedCodeFix = languageService . getCombinedCodeFix (
309
+ { type : 'file' , fileName : sourceFile . fileName } ,
310
+ 'requireInTs' ,
311
+ ts . getDefaultFormatCodeSettings ( ) ,
312
+ preferences ,
313
+ )
314
+ return combinedCodeFix . changes [ 0 ] ?. textChanges
315
+ }
307
316
308
317
return null
309
318
}
You can’t perform that action at this time.
0 commit comments