Skip to content

Commit

Permalink
Add a extract_variable_all function for the corresponding code action
Browse files Browse the repository at this point in the history
  • Loading branch information
mfussenegger committed Dec 22, 2022
1 parent 2773a6b commit a5c6f38
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ alternative:

- [x] `organize_imports` function to organize imports
- [x] `extract_variable` function to introduce a local variable
- [x] `extract_variable_all` function to introduce a local variable and replace all occurrences.
- [x] `extract_constant` function to extract a constant
- [x] `extract_method` function to extract a block of code into a method
- [x] Open class file contents
Expand Down
16 changes: 16 additions & 0 deletions doc/jdtls.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ JdtProjectSelectMode *JdtProjectSelectMode*
string


M.extract_constant() *jdtls.extract_constant*
Extract a constant from the expression under the cursor


M.extract_variable() *jdtls.extract_variable*
Extract a variable from the expression under the cursor


M.extract_variable_all() *jdtls.extract_variable_all*
Extract a local variable from the expression under the cursor and replace all occurrences


M.extract_method() *jdtls.extract_method*
Extract a method


M.super_implementation() *jdtls.super_implementation*
Jump to the super implementation of the method under the cursor

Expand Down
31 changes: 23 additions & 8 deletions lua/jdtls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -828,16 +828,31 @@ end
---|"all"
---|"prompt"

local function mk_extract(entity)
return function(from_selection)
local params = make_code_action_params(from_selection or false)
java_apply_refactoring_command({ arguments = { entity }, }, { params = params })
end

local function extract(entity, from_selection)
local params = make_code_action_params(from_selection or false)
java_apply_refactoring_command({ arguments = { entity }, }, { params = params })
end

M.extract_constant = mk_extract('extractConstant')
M.extract_variable = mk_extract('extractVariable')
M.extract_method = mk_extract('extractMethod')
--- Extract a constant from the expression under the cursor
function M.extract_constant(from_selection)
extract('extractConstant', from_selection)
end

--- Extract a variable from the expression under the cursor
function M.extract_variable(from_selection)
extract('extractVariable', from_selection)
end

--- Extract a local variable from the expression under the cursor and replace all occurrences
function M.extract_variable_all(from_selection)
extract('extractVariableAllOccurrence', from_selection)
end

--- Extract a method
function M.extract_method(from_selection)
extract('extractMethod', from_selection)
end


--- Jump to the super implementation of the method under the cursor
Expand Down

0 comments on commit a5c6f38

Please sign in to comment.