-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathrefactor.lua
More file actions
38 lines (32 loc) · 876 Bytes
/
refactor.lua
File metadata and controls
38 lines (32 loc) · 876 Bytes
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
---@param action_type string
---@param filter? string
local function run_code_action(action_type, filter)
vim.lsp.buf.code_action({
apply = true,
context = {
diagnostics = vim.lsp.diagnostic.get_line_diagnostics(0),
only = { action_type },
},
filter = filter and function(refactor)
return refactor.command.arguments[1] == filter
end or nil,
})
end
local M = {
extract_variable = function()
run_code_action('refactor.extract.variable', 'extractVariable')
end,
extract_variable_all_occurrence = function()
run_code_action('refactor.extract.variable', 'extractVariableAllOccurrence')
end,
extract_constant = function()
run_code_action('refactor.extract.constant')
end,
extract_method = function()
run_code_action('refactor.extract.function')
end,
extract_field = function()
run_code_action('refactor.extract.field')
end,
}
return M