This repository was archived by the owner on Nov 30, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefactor-commands.lua
More file actions
59 lines (45 loc) · 1.42 KB
/
refactor-commands.lua
File metadata and controls
59 lines (45 loc) · 1.42 KB
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
55
56
57
58
59
local class = require('java-core.utils.class')
local notify = require('java-core.utils.notify')
local lsp_refactor_commands = require('java-refactor.lsp-refactor-commands')
local JdtlsClient = require('java-core.ls.clients.jdtls-client')
---@class java-refactor.ClientCommands
---@field client lsp.Client
local RefactorCommands = class()
function RefactorCommands:_init(client)
self.client = client
self.jdtls_client = JdtlsClient(client)
end
function RefactorCommands:extract_variable()
local context = vim.lsp.util.make_range_params(0)
context.context = {}
context.context.diagnostics = vim.lsp.diagnostic.get_line_diagnostics(0)
local buffer = vim.api.nvim_get_current_buf()
local selection =
self.jdtls_client:java_infer_selection('extractVariable', context, buffer)
local edit = self.jdtls_client:java_get_refactor_edit(
'extractVariable',
context,
{},
selection,
buffer
)
vim.lsp.util.apply_workspace_edit(edit.edit, 'utf-8')
RefactorCommands.run_lsp_client_command(
edit.command.command,
edit.command.arguments
)
end
function RefactorCommands.run_lsp_client_command(command_name, arguments)
local command
if lsp_refactor_commands[command_name] then
command = lsp_refactor_commands[command_name]
else
command = vim.lsp.commands[command_name]
end
if not command then
notify.error('Command "' .. command_name .. '" is not supported')
return
end
command(arguments)
end
return RefactorCommands