@@ -41,27 +41,33 @@ export default class CodeActionAdapter {
41
41
linterAdapter : LinterPushV2Adapter | IdeDiagnosticAdapter | undefined ,
42
42
editor : TextEditor ,
43
43
range : Range ,
44
- linterMessages : linter . Message [ ] | atomIde . Diagnostic [ ]
44
+ linterMessages : linter . Message [ ] | atomIde . Diagnostic [ ] ,
45
+ filterActions : ( actions : ( Command | CodeAction ) [ ] | null ) => ( Command | CodeAction ) [ ] | null = ( actions ) => actions ,
46
+ onApply : ( action : Command | CodeAction ) => Promise < boolean > = ( ) => Promise . resolve ( true )
45
47
) : Promise < atomIde . CodeAction [ ] > {
46
48
if ( linterAdapter == null ) {
47
49
return [ ]
48
50
}
49
51
assert ( serverCapabilities . codeActionProvider , "Must have the textDocument/codeAction capability" )
50
52
51
53
const params = createCodeActionParams ( linterAdapter , editor , range , linterMessages )
52
- const actions = await connection . codeAction ( params )
54
+ const actions = filterActions ( await connection . codeAction ( params ) )
53
55
if ( actions === null ) {
54
56
return [ ]
55
57
}
56
- return actions . map ( ( action ) => CodeActionAdapter . createCodeAction ( action , connection ) )
58
+ return actions . map ( ( action ) => CodeActionAdapter . createCodeAction ( action , connection , onApply ) )
57
59
}
58
60
59
61
private static createCodeAction (
60
62
action : Command | CodeAction ,
61
- connection : LanguageClientConnection
63
+ connection : LanguageClientConnection ,
64
+ onApply : ( action : Command | CodeAction ) => Promise < boolean >
62
65
) : atomIde . CodeAction {
63
66
return {
64
67
async apply ( ) {
68
+ if ( ( await onApply ( action ) ) === false ) {
69
+ return
70
+ }
65
71
if ( CodeAction . is ( action ) ) {
66
72
CodeActionAdapter . applyWorkspaceEdit ( action . edit )
67
73
await CodeActionAdapter . executeCommand ( action . command , connection )
0 commit comments