mfussenegger / nvim-jdtls

Extensions for the built-in LSP support in Neovim for eclipse.jdt.ls
GNU General Public License v3.0
1.14k stars 62 forks source link

Synchroneous call of M.compile({type}) so that one can wait before any depending post-processing starts #689

Closed jamilraichouni closed 2 months ago

jamilraichouni commented 2 months ago

Problem Statement

I have no chance to know when .class file creation, compilation via M.compile({type}), is completed before I start to pack and deploy the according .jar file.

Ideas or possible solutions

Make run of M.compile({type}) snychroneous and provide return code, error message(s) etc.

mfussenegger commented 2 months ago

As a workaround you could make the underlying request directly with something like client.request_sync("java/buildWorkspace", false, 5000, bufnr)

You won't get the logic that populates the quickfix list with errors if there are any, but if all you want is to have the compilation and then trigger something that should be good enough. I also use that in my dotfiles.

(client is either from on_attach/LspAttach, or you can get it via vim.lsp.get_clients({ name = "jdtls" })[1])

jamilraichouni commented 2 months ago

Thank you @mfussenegger ,

I replaced

require("jdtls").compile("full")

with

local bufnr = vim.api.nvim_get_current_buf()
local client = vim.lsp.get_clients({ name = "jdtls", bufnr = bufnr })[1]
local resp = client.request_sync("java/buildWorkspace", true, 5000, bufnr)
if resp.result > 1 then
    require("jdtls").compile("full")
    return
end

That is a solution that is okax for not too big projects and I get the errors in the quickfix list. Looks like resp.result equals 1 in the case of a successful compilation.