mirror of
https://github.com/mfussenegger/nvim-jdtls
synced 2024-09-16 14:34:13 +02:00
Add a javap
command to show bytecode of current file
This commit is contained in:
parent
cab21547ee
commit
11fcd8df1f
2 changed files with 39 additions and 0 deletions
|
@ -12,6 +12,7 @@ Extensions for the built-in [Language Server Protocol][1] support in [Neovim][2]
|
|||
- [x] Code action extensions (`java.apply.workspaceEdit`).
|
||||
- [x] `toString` generation.
|
||||
- [x] `hashCode` and `equals` generation.
|
||||
- [x] `javap` command to show bytecode of current file
|
||||
- [x] Integration with [nvim-dap][5]
|
||||
|
||||
|
||||
|
|
|
@ -184,6 +184,44 @@ function M.organize_imports()
|
|||
end
|
||||
|
||||
|
||||
local function resolve_classname()
|
||||
local lines = api.nvim_buf_get_lines(0, 0, -1, true)
|
||||
local pkgname
|
||||
for _, line in ipairs(lines) do
|
||||
local match = line:match('package ([a-z\\.]+);')
|
||||
if match then
|
||||
pkgname = match
|
||||
break
|
||||
end
|
||||
end
|
||||
assert(pkgname, 'Could not find package name for current class')
|
||||
local classname = vim.fn.fnamemodify(vim.fn.expand('%'), ':t:r')
|
||||
return pkgname .. '.' .. classname
|
||||
end
|
||||
|
||||
|
||||
function M.javap()
|
||||
local options = vim.fn.json_encode({
|
||||
scope = 'runtime';
|
||||
})
|
||||
local cmd = {
|
||||
command = 'java.project.getClasspaths';
|
||||
arguments = { vim.uri_from_bufnr(0), options };
|
||||
}
|
||||
M.execute_command(cmd, function(err, resp)
|
||||
if err then
|
||||
print('Error executing java.project.getClasspaths: ' .. err.message)
|
||||
return
|
||||
end
|
||||
local classname = resolve_classname()
|
||||
local cp = table.concat(resp.classpaths, ':')
|
||||
local buf = api.nvim_create_buf(false, true)
|
||||
api.nvim_win_set_buf(0, buf)
|
||||
vim.fn.termopen({'javap', '-c', '--class-path', cp, classname})
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
--- Reads the uri into the current buffer
|
||||
--
|
||||
-- This requires at least one open buffer that is connected to the jdtls
|
||||
|
|
Loading…
Reference in a new issue