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
61 lines (48 loc) · 1.53 KB
/
refactor-commands.lua
File metadata and controls
61 lines (48 loc) · 1.53 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
60
61
local class = require('java-core.utils.class')
local notify = require('java-core.utils.notify')
local JdtlsClient = require('java-core.ls.clients.jdtls-client')
---@class java-refactor.RefactorCommands
---@field client vim.lsp.Client
---@field jdtls_client java-core.JdtlsClient
local RefactorCommands = class()
---@param client vim.lsp.Client
function RefactorCommands:_init(client)
self.client = client
self.jdtls_client = JdtlsClient(client)
end
---Run refactor command
---@param refactor_type jdtls.CodeActionCommand
function RefactorCommands:refactor(refactor_type)
local context = vim.lsp.util.make_range_params(0)
context.context = {}
context.context.diagnostics = vim.lsp.diagnostic.get_line_diagnostics(0)
local formatting_options = {
tabSize = vim.bo.tabstop,
insertSpaces = vim.bo.expandtab,
}
local buffer = vim.api.nvim_get_current_buf()
local selection =
self.jdtls_client:java_infer_selection(refactor_type, context, buffer)
local edit = self.jdtls_client:java_get_refactor_edit(
refactor_type,
context,
formatting_options,
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)
-- vim.print(command_name, arguments)
local command = vim.lsp.commands[command_name]
if not command then
notify.error('Command "' .. command_name .. '" is not supported')
return
end
command(arguments)
end
return RefactorCommands