Skip to content

Commit

Permalink
Add a super_implementation function
Browse files Browse the repository at this point in the history
Closes #347
  • Loading branch information
mfussenegger committed Oct 14, 2022
1 parent 0422245 commit 75af958
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
15 changes: 4 additions & 11 deletions doc/jdtls.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ M.build_projects({opts}) *jdtls.build_projects*

JdtBuildProjectOpts *JdtBuildProjectOpts*


Fields: ~
{select_mode} (JdtProjectSelectMode) Show prompt to select projects or select all. Defaults to "prompt"
{full_build} (boolean) full rebuild or incremental build. Defaults to true (full build)
Expand All @@ -52,18 +51,20 @@ M.update_projects_config({opts}) *jdtls.update_projects_config*

JdtUpdateProjectsOpts *JdtUpdateProjectsOpts*


Fields: ~
{select_mode} (JdtProjectSelectMode|nil) show prompt to select projects or select all. Defaults to "prompt"


JdtProjectSelectMode *JdtProjectSelectMode*


Type: ~
"all"|"prompt"|nil


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


M.javap() *jdtls.javap*
Run the `javap` tool in a terminal buffer.
Sets the classpath based on the current project.
Expand Down Expand Up @@ -151,7 +152,6 @@ M.fetch_main_configs({opts}, {callback}) *jdtls.dap.fetch_main_configs*

JdtMainConfigOpts *JdtMainConfigOpts*


Fields: ~
{config_overrides} (nil|JdtDapConfig) Overrides for the |dap-configuration|, see |JdtDapConfig|

Expand All @@ -164,10 +164,6 @@ M.setup_dap_main_class_configs({opts}) *jdtls.dap.setup_dap_main_class_configs*


JdtSetupMainConfigOpts *JdtSetupMainConfigOpts*
: JdtMainConfigOpts

Fields: ~
{verbose} (nil|boolean) Print notifications on start and once finished. Default is false.


M.setup_dap({opts}) *jdtls.dap.setup_dap*
Expand All @@ -179,15 +175,13 @@ M.setup_dap({opts}) *jdtls.dap.setup_dap*

JdtSetupDapOpts *JdtSetupDapOpts*


Fields: ~
{config_overrides} (JdtDapConfig) These will be used as default overrides for |jdtls.dap.test_class|, |jdtls.dap.test_nearest_method| and discovered main classes
{hotcodereplace} (nil|"auto")


JdtDapConfig *JdtDapConfig*


Fields: ~
{cwd} (string|nil) working directory for the test
{vmArgs} (string|nil) vmArgs for the test
Expand All @@ -196,7 +190,6 @@ JdtDapConfig *JdtDapConfig*

JdtTestOpts *JdtTestOpts*


Fields: ~
{config} (nil|table) Skeleton used for the |dap-configuration|
{config_overrides} (nil|JdtDapConfig) Overrides for the |dap-configuration|, see |JdtDapConfig|
Expand Down
36 changes: 28 additions & 8 deletions lua/jdtls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ local execute_command = util.execute_command
local jdtls_dap = require('jdtls.dap')
local setup = require('jdtls.setup')

local offset_encoding = 'utf-16'



local M = {
Expand Down Expand Up @@ -56,7 +58,7 @@ M.jol_path = nil

local function java_apply_workspace_edit(command)
for _, argument in ipairs(command.arguments) do
vim.lsp.util.apply_workspace_edit(argument, 'utf-16')
vim.lsp.util.apply_workspace_edit(argument, offset_encoding)
end
end

Expand Down Expand Up @@ -88,7 +90,7 @@ local function java_generate_to_string_prompt(_, outer_ctx)
return
end
if edit then
vim.lsp.util.apply_workspace_edit(edit, 'utf-16')
vim.lsp.util.apply_workspace_edit(edit, offset_encoding)
end
end)
end)
Expand Down Expand Up @@ -135,7 +137,7 @@ local function java_generate_constructors_prompt(_, outer_ctx)
if err1 then
print("Could not execute java/generateConstructors: " .. err1.message)
elseif edit then
vim.lsp.util.apply_workspace_edit(edit, 'utf-16')
vim.lsp.util.apply_workspace_edit(edit, offset_encoding)
end
end)
end)
Expand Down Expand Up @@ -189,7 +191,7 @@ local function java_generate_delegate_methods_prompt(_, outer_ctx)
if err1 then
print('Could not execute java/generateDelegateMethods', err1.message)
elseif workspace_edit then
vim.lsp.util.apply_workspace_edit(workspace_edit, 'utf-16')
vim.lsp.util.apply_workspace_edit(workspace_edit, offset_encoding)
end
end)
end)
Expand All @@ -211,7 +213,7 @@ local function java_hash_code_equals_prompt(_, outer_ctx)
print("Could not execute java/generateHashCodeEquals: " .. e.message)
end
if edit then
vim.lsp.util.apply_workspace_edit(edit, 'utf-16')
vim.lsp.util.apply_workspace_edit(edit, offset_encoding)
end
end)
end)
Expand All @@ -228,7 +230,7 @@ local function handle_refactor_workspace_edit(err, result, ctx)
end

if result.edit then
vim.lsp.util.apply_workspace_edit(result.edit, 'utf-16')
vim.lsp.util.apply_workspace_edit(result.edit, offset_encoding)
end

if result.command then
Expand Down Expand Up @@ -509,7 +511,7 @@ local function java_action_organize_imports(_, ctx)
return
end
if resp then
vim.lsp.util.apply_workspace_edit(resp, 'utf-16')
vim.lsp.util.apply_workspace_edit(resp, offset_encoding)
end
end)
end
Expand Down Expand Up @@ -584,7 +586,7 @@ local function java_override_methods(_, context)
print("Error getting workspace edits: " .. e2.message)
return
end
vim.lsp.util.apply_workspace_edit(result2, 'utf-16')
vim.lsp.util.apply_workspace_edit(result2, offset_encoding)
end)
end)
end
Expand Down Expand Up @@ -805,6 +807,24 @@ M.extract_variable = mk_extract('extractVariable')
M.extract_method = mk_extract('extractMethod')


--- Jump to the super implementation of the method under the cursor
function M.super_implementation()
local params = {
type = 'superImplementation',
position = vim.lsp.util.make_position_params(0, offset_encoding),
}
request(0, 'java/findLinks', params, function(err, result)
assert(not err, vim.inspect(err))
if result and #result == 1 then
vim.lsp.util.jump_to_location(result[1], offset_encoding, true)
else
assert(result == nil or #result == 0, 'Expected one or zero results for `findLinks`')
vim.notify('No result found')
end
end)
end


--- Run the `javap` tool in a terminal buffer.
--- Sets the classpath based on the current project.
function M.javap()
Expand Down

0 comments on commit 75af958

Please sign in to comment.