-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathdecompile-watcher.lua
More file actions
56 lines (41 loc) · 1.34 KB
/
decompile-watcher.lua
File metadata and controls
56 lines (41 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
local jdtls = require('java.utils.jdtls2')
local get_error_handler = require('java.handlers.error')
local async = require('java-core.utils.async').sync
local JavaCoreJdtlsClient = require('java-core.ls.clients.jdtls-client')
local M = {}
---@class BufReadCmdCallbackArgs
---@field buf integer buffer number
---@field event string name of the event
---@field file string name of the file
---@field id integer event id?
---@field match string matched pattern in autocmd match
function M.setup()
vim.api.nvim_create_autocmd('BufReadCmd', {
pattern = 'jdt://*',
---@param opts BufReadCmdCallbackArgs
callback = function(opts)
local done = false
async(function()
local client = jdtls()
local buffer = opts.buf
local text = JavaCoreJdtlsClient(client):java_decompile(opts.file)
local lines = vim.split(text, '\n')
vim.bo[buffer].modifiable = true
vim.api.nvim_buf_set_lines(buffer, 0, -1, true, lines)
vim.bo[buffer].swapfile = false
vim.bo[buffer].filetype = 'java'
vim.bo[buffer].modifiable = false
if not vim.lsp.buf_is_attached(buffer, client.id) then
vim.lsp.buf_attach_client(buffer, client.id)
end
done = true
end)
.catch(get_error_handler('decompilation failed for ' .. opts.file))
.run()
vim.wait(10000, function()
return done
end)
end,
})
end
return M