-
Notifications
You must be signed in to change notification settings - Fork 59
/
code-actions.lua
54 lines (46 loc) · 1.66 KB
/
code-actions.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
local s = require("null-ls.state")
local u = require("null-ls.utils")
local methods = require("null-ls.methods")
local log = require("null-ls.logger")
local M = {}
local postprocess = function(action)
s.register_action(action)
action.action = nil
action.command = methods.internal.CODE_ACTION
action.arguments = {
title = action.title,
}
end
M.handler = function(method, original_params, handler)
if method == methods.lsp.CODE_ACTION then
if not original_params.textDocument then
return
end
if original_params._null_ls_ignore or (original_params.ctx and original_params.ctx._null_ls_ignore) then
return
end
s.clear_actions()
local params = u.make_params(original_params, methods.map[method])
require("null-ls.generators").run_registered({
filetype = params.ft,
method = methods.map[method],
params = params,
postprocess = postprocess,
callback = function(actions)
log:trace("received code actions from generators")
log:trace(vim.inspect(actions))
-- sort actions by title
table.sort(actions, function(a, b)
return a.title < b.title
end)
handler(actions)
end,
})
original_params._null_ls_handled = true
end
if method == methods.lsp.EXECUTE_COMMAND and original_params.command == methods.internal.CODE_ACTION then
s.run_action(original_params.arguments and original_params.arguments.title)
original_params._null_ls_handled = true
end
end
return M