feat: add Javap command to decompile classpath files

This commit is contained in:
əlemi 2023-03-19 15:26:17 +01:00
parent 2cfb946326
commit b14cf6bcfb
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -1,6 +1,50 @@
local nvim_jdtls = require("jdtls") local nvim_jdtls = require("jdtls")
nvim_jdtls.start_or_attach({ nvim_jdtls.start_or_attach({
cmd = { 'jdtls' }, cmd = { 'jdtls' },
root_dir = vim.fs.dirname(vim.fs.find({'.gradlew', '.git', 'mvnw'}, {upward = true})[1]), root_dir = vim.fs.dirname(vim.fs.find({'.gradlew', '.git', 'mvnw'}, {upward = true})[1]),
}) })
require('keybinds'):set_lsp_keys({buffer = 0}) require('keybinds'):set_lsp_keys({buffer = 0})
-- Allow decompiling classes coming from the language server too
vim.api.nvim_create_user_command(
'Javap',
function(args)
local fname = vim.api.nvim_buf_get_name(0)
if vim.startswith(fname, "jdt://") then
local _, _, classpath_raw, classname_raw = string.find(fname, "jdt://.+?=%a+/(.+).jar=/.+,test=/(.+)%.class.*")
local classpath = classpath_raw:gsub("%%5C", "") .. '.jar'
local classname = classname_raw:gsub("%%3C", ""):gsub("%(", ".")
vim.fn.jobstart(
{'javap', '-c', '--class-path', classpath, classname},
{
width = 1024,
stdout_buffered = true,
on_stdout = function(_, data, _)
local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_text(buf, 0, 0, 0, 0, data)
vim.api.nvim_buf_set_option(buf, 'ft', 'asm')
if args.bang then
local width = vim.fn.winwidth(0)
local height = vim.fn.winheight(0)
vim.api.nvim_open_win(buf, true, {
relative='win',
row = 5,
col = 10,
width=width - 20,
height=height - 10,
border="single",
zindex=100, -- TODO hardcoded?
})
else
vim.api.nvim_win_set_buf(0, buf)
vim.api.nvim_win_set_cursor(buf, { 1, 0 })
end
end
}
)
else
require('jdtls').javap()
end
end,
{ bang=true }
)