@@ -8,7 +8,7 @@ import { defaultJsSupersetLangsWithVue } from '@zardoy/vscode-utils/build/langs'
88import { offsetPosition } from '@zardoy/vscode-utils/build/position'
99import { RequestOptionsTypes , RequestResponseTypes } from '../typescript/src/ipcTypes'
1010import { sendCommand } from './sendCommand'
11- import { tsRangeToVscode , tsRangeToVscodeSelection } from './util'
11+ import { tsRangeToVscode , tsRangeToVscodeSelection , tsTextChangesToVcodeTextEdits } from './util'
1212
1313export default ( ) => {
1414 registerExtensionCommand ( 'removeFunctionArgumentsTypesInSelection' , async ( ) => {
@@ -260,23 +260,27 @@ export default () => {
260260 const editor = vscode . window . activeTextEditor !
261261 const edits = await sendTurnIntoArrayRequest < RequestResponseTypes [ 'turnArrayIntoObjectEdit' ] > ( editor . selection , selectedKey )
262262 if ( ! edits ) throw new Error ( 'Unknown error. Try debug.' )
263- await editor . edit ( builder => {
264- for ( const { span, newText } of edits ) {
265- const start = editor . document . positionAt ( span . start )
266- builder . replace ( new vscode . Range ( start , offsetPosition ( editor . document , start , span . length ) ) , newText )
267- }
268- } )
263+ const edit = new vscode . WorkspaceEdit ( )
264+ edit . set ( editor . document . uri , tsTextChangesToVcodeTextEdits ( editor . document , edits ) )
265+ await vscode . workspace . applyEdit ( edit )
269266 } )
270267
271268 // its actually a code action, but will be removed from there soon
272269 vscode . languages . registerCodeActionsProvider ( defaultJsSupersetLangsWithVue , {
273270 async provideCodeActions ( document , range , context , token ) {
274- if (
275- context . triggerKind !== vscode . CodeActionTriggerKind . Invoke ||
276- document !== vscode . window . activeTextEditor ?. document ||
277- ! getExtensionSetting ( 'enablePlugin' )
278- )
271+ if ( document !== vscode . window . activeTextEditor ?. document || ! getExtensionSetting ( 'enablePlugin' ) ) {
279272 return
273+ }
274+
275+ if ( context . only ?. contains ( vscode . CodeActionKind . SourceFixAll ) ) {
276+ const fixAllEdits = await sendCommand < RequestResponseTypes [ 'getFixAllEdits' ] > ( 'getFixAllEdits' )
277+ if ( ! fixAllEdits ) return
278+ const edit = new vscode . WorkspaceEdit ( )
279+ edit . set ( document . uri , tsTextChangesToVcodeTextEdits ( document , fixAllEdits ) )
280+ await vscode . workspace . applyEdit ( edit )
281+ }
282+
283+ if ( context . triggerKind !== vscode . CodeActionTriggerKind . Invoke ) return
280284 const result = await sendTurnIntoArrayRequest ( range )
281285 if ( ! result ) return
282286 const { keysCount, totalCount, totalObjectCount } = result
0 commit comments