Skip to content

Commit 2c281a1

Browse files
authored
feat: add handler for overrideMethodsPrompt action (#16)
1 parent ea1420f commit 2c281a1

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

lua/java-refactor/action.lua

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,33 @@ end
270270
---@field params lsp.CodeActionParams
271271
---@field version number
272272

273+
---@param params nvim.CodeActionParamsResponse
274+
function Action:override_methods_prompt(params)
275+
local status = self.jdtls:list_overridable_methods(params.params)
276+
277+
if not status or not status.methods or #status.methods < 1 then
278+
notify.warn('No methods to override.')
279+
return
280+
end
281+
282+
local selected_methods = ui.multi_select(
283+
'Select methods to override.',
284+
status.methods,
285+
function(method)
286+
return string.format(
287+
'%s(%s)',
288+
method.name,
289+
table.concat(method.parameters, ', ')
290+
)
291+
end
292+
)
293+
294+
if not selected_methods or #selected_methods < 1 then
295+
return
296+
end
297+
298+
local edit =
299+
self.jdtls:add_overridable_methods(params.params, selected_methods)
300+
vim.lsp.util.apply_workspace_edit(edit, 'utf-8')
301+
end
273302
return Action

lua/java-refactor/client-command-handlers.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ local M = {
5757
end)
5858
end,
5959

60+
---@param params nvim.CodeActionParamsResponse
61+
[ClientCommand.OVERRIDE_METHODS_PROMPT] = function(_, params)
62+
run('Failed to get overridable methods', function(action)
63+
action:override_methods_prompt(params)
64+
require('java-core.utils.notify').info('Successfully built the workspace')
65+
end)
66+
end,
67+
6068
---@param is_full_build boolean
6169
[ClientCommand.COMPILE_WORKSPACE] = function(is_full_build)
6270
run('Failed to build workspace', function(action)

lua/java-refactor/refactor.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ function Refactor:move_file(action_info)
9898
params = nil,
9999
})
100100

101-
vim.print(move_des)
102-
103101
if
104102
not move_des
105103
or not move_des.destinations

0 commit comments

Comments
 (0)