Skip to content

Commit

Permalink
feat: add chooseImports action
Browse files Browse the repository at this point in the history
  • Loading branch information
s1n7ax committed Jan 26, 2025
1 parent 5379779 commit 9060b97
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lua/java-refactor/action.lua
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,24 @@ function Action:override_methods_prompt(params)
self.jdtls:add_overridable_methods(params.params, selected_methods)
vim.lsp.util.apply_workspace_edit(edit, 'utf-8')
end

---@param selections jdtls.ImportSelection[]
function Action:choose_imports(selections)
local selected_candidates = {}

for _, selection in ipairs(selections) do
local selected_candidate = ui.select_sync(
'Select methods to override.',
selection.candidates,
function(candidate, index)
return index .. ' ' .. candidate.fullyQualifiedName
end
)

table.insert(selected_candidates, selected_candidate)
end

return selected_candidates
end

return Action
19 changes: 19 additions & 0 deletions lua/java-refactor/client-command-handlers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ local M = {
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)
Expand Down

0 comments on commit 9060b97

Please sign in to comment.