Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add infer selection support for extractMethod #17

Merged
merged 1 commit into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions lua/jdtls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,48 @@ local function handle_refactor_workspace_edit(err, _, result)
end


local function mk_refactor_options()
local sts = vim.bo.softtabstop;
return {
tabSize = (sts > 0 and sts) or (sts < 0 and vim.bo.shiftwidth) or vim.bo.tabstop;
insertSpaces = vim.bo.expandtab;
}
end


local function java_apply_refactoring_command(command, code_action_params)
local cmd = command.arguments[1]
local sts = vim.bo.softtabstop;
local params = {
command = cmd,
context = code_action_params,
options = {
tabSize = (sts > 0 and sts) or (sts < 0 and vim.bo.shiftwidth) or vim.bo.tabstop;
insertSpaces = vim.bo.expandtab;
},
options = mk_refactor_options(),
}
request(0, 'java/getRefactorEdit', params, handle_refactor_workspace_edit)
if cmd ~= 'extractMethod' then
request(0, 'java/getRefactorEdit', params, handle_refactor_workspace_edit)
return
end
request(0, 'java/inferSelection', params, function(err, _, selection_info)
assert(not err, vim.inspect(err))
if not selection_info or #selection_info == 0 then
print('No selection found that could be extracted into a method')
return
end
if #selection_info == 1 then
params.commandArguments = {selection_info}
request(0, 'java/getRefactorEdit', params, handle_refactor_workspace_edit)
else
ui.pick_one_async(
selection_info,
'Choices:',
function(x) return x.name end,
function(selection)
if not selection then return end
params.commandArguments = {selection}
request(0, 'java/getRefactorEdit', params, handle_refactor_workspace_edit)
end
)
end
end)
end


Expand Down
1 change: 1 addition & 0 deletions lua/jdtls/setup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ local extendedClientCapabilities = {
advancedOrganizeImportsSupport = true;
generateConstructorsPromptSupport = true;
generateDelegateMethodsPromptSupport = true;
inferSelectionSupport = {"extractMethod"};
};


Expand Down