File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,8 @@ export default class CodeActionAdapter {
42
42
editor : TextEditor ,
43
43
range : Range ,
44
44
linterMessages : linter . Message [ ] | atomIde . Diagnostic [ ] ,
45
- filterActions : ( actions : ( Command | CodeAction ) [ ] | null ) => ( Command | CodeAction ) [ ] | null = ( actions ) => actions
45
+ filterActions : ( actions : ( Command | CodeAction ) [ ] | null ) => ( Command | CodeAction ) [ ] | null = ( actions ) => actions ,
46
+ onApply : ( action : Command | CodeAction ) => Promise < boolean > = ( ) => Promise . resolve ( true )
46
47
) : Promise < atomIde . CodeAction [ ] > {
47
48
if ( linterAdapter == null ) {
48
49
return [ ]
@@ -54,15 +55,19 @@ export default class CodeActionAdapter {
54
55
if ( actions === null ) {
55
56
return [ ]
56
57
}
57
- return actions . map ( ( action ) => CodeActionAdapter . createCodeAction ( action , connection ) )
58
+ return actions . map ( ( action ) => CodeActionAdapter . createCodeAction ( action , connection , onApply ) )
58
59
}
59
60
60
61
private static createCodeAction (
61
62
action : Command | CodeAction ,
62
- connection : LanguageClientConnection
63
+ connection : LanguageClientConnection ,
64
+ onApply : ( action : Command | CodeAction ) => Promise < boolean >
63
65
) : atomIde . CodeAction {
64
66
return {
65
67
async apply ( ) {
68
+ if ( ( await onApply ( action ) ) === false ) {
69
+ return
70
+ }
66
71
if ( CodeAction . is ( action ) ) {
67
72
CodeActionAdapter . applyWorkspaceEdit ( action . edit )
68
73
await CodeActionAdapter . executeCommand ( action . command , connection )
Original file line number Diff line number Diff line change @@ -945,7 +945,8 @@ export default class AutoLanguageClient {
945
945
editor ,
946
946
range ,
947
947
diagnostics ,
948
- this . filterCodeActions . bind ( this )
948
+ this . filterCodeActions . bind ( this ) ,
949
+ this . onApplyCodeActions . bind ( this )
949
950
)
950
951
}
951
952
@@ -954,6 +955,14 @@ export default class AutoLanguageClient {
954
955
return actions
955
956
}
956
957
958
+ /**
959
+ * Optionally handle a code action before default handling. Return `false` to prevent default handling, `true` to
960
+ * continue with default handling.
961
+ */
962
+ protected async onApplyCodeActions ( _action : ls . Command | ls . CodeAction ) : Promise < boolean > {
963
+ return true
964
+ }
965
+
957
966
public provideRefactor ( ) : atomIde . RefactorProvider {
958
967
return {
959
968
grammarScopes : this . getGrammarScopes ( ) ,
You can’t perform that action at this time.
0 commit comments