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 pathclient-command-handlers.lua
More file actions
129 lines (109 loc) · 3.83 KB
/
client-command-handlers.lua
File metadata and controls
129 lines (109 loc) · 3.83 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
local ClientCommand = require('java-refactor.client-command')
---@param message string
---@param func fun(action: java-refactor.Action)
local run = function(message, func)
local runner = require('async.runner')
local get_error_handler = require('java-refactor.utils.error_handler')
local instance = require('java-refactor.utils.instance-factory')
runner(function()
func(instance.get_action())
end)
.catch(get_error_handler(message))
.run()
end
local M = {
---@param params java-refactor.RenameAction[]
[ClientCommand.RENAME_COMMAND] = function(params)
run('Failed to rename the symbol', function(action)
action.rename(params)
end)
end,
---@param params nvim.CodeActionParamsResponse
[ClientCommand.GENERATE_CONSTRUCTORS_PROMPT] = function(_, params)
run('Failed to generate constructor', function(action)
action:generate_constructor(params)
end)
end,
---@param params nvim.CodeActionParamsResponse
[ClientCommand.GENERATE_TOSTRING_PROMPT] = function(_, params)
run('Failed to generate toString', function(action)
action:generate_to_string(params)
end)
end,
---@param params nvim.CodeActionParamsResponse
[ClientCommand.HASHCODE_EQUALS_PROMPT] = function(_, params)
run('Failed to generate hash code and equals', function(action)
action:generate_hash_code_and_equals(params)
end)
end,
---@param params nvim.CodeActionParamsResponse
[ClientCommand.GENERATE_DELEGATE_METHODS_PROMPT] = function(_, params)
run('Failed to generate delegate methods', function(action)
action:generate_delegate_mothods_prompt(params)
end)
end,
---@param command lsp.Command
[ClientCommand.APPLY_REFACTORING_COMMAND] = function(command)
run('Failed to apply refactoring command', function(action)
action:apply_refactoring_command(command)
end)
end,
---@param params nvim.CodeActionParamsResponse
[ClientCommand.OVERRIDE_METHODS_PROMPT] = function(_, params)
run('Failed to get overridable methods', function(action)
action:override_methods_prompt(params)
require('java-core.utils.notify').info('Successfully built the workspace')
end)
end,
---@param params [string, jdtls.ImportSelection[], boolean]
[ClientCommand.CHOOSE_IMPORTS] = function(params)
local get_error_handler = require('java-refactor.utils.error_handler')
local instance = require('java-refactor.utils.instance-factory')
local action = instance.get_action()
local selections = params[2]
local ok, result = pcall(function()
return action.choose_imports(selections)
end)
if not ok then
get_error_handler('Failed to choose imports')(result)
return
end
return result or {}
end,
---@param is_full_build boolean
[ClientCommand.COMPILE_WORKSPACE] = function(is_full_build)
run('Failed to build workspace', function(action)
action:build_workspace(is_full_build)
require('java-core.utils.notify').info('Successfully built the workspace')
end)
end,
[ClientCommand.CLEAN_WORKSPACE] = function()
run('Failed to clean workspace', function(action)
action:clean_workspace()
require('java-core.utils.notify').info(
'Successfully cleared the workspace cache'
.. '\nPlease close and reopen neovim to restart JDTLS'
)
end)
end,
}
local ignored_commands = { ClientCommand.REFRESH_BUNDLES_COMMAND }
for _, command in pairs(ClientCommand) do
if not M[command] and not vim.tbl_contains(ignored_commands, command) then
local message = string.format(
'"%s" is not supported yet!'
.. '\nPlease request the feature using below link'
.. '\nhttps://github.com/nvim-java/nvim-java/issues/new?assignees='
.. '&labels=enhancement&projects=&template=feature_request.yml&title=feature%%3A+',
command
)
M[command] = function()
require('java-core.utils.notify').warn(message)
return vim.lsp.rpc_response_error(
vim.lsp.protocol.ErrorCodes.MethodNotFound,
'Not implemented yes'
)
end
end
end
return M