Error in java projects (jdtls.nvim)
Description
I've been using the plugin for months and it worked great for lua and js/ts, but now I have started working on Java and this error keeps poping the first time I open a Java project:
Error detected while processing LspAttach Autocommands for "*":
Error executing lua callback: vim/shared.lua:0: t: expected table, got nil
stack traceback:
[C]: in function 'error'
vim/shared.lua: in function 'validate'
vim/shared.lua: in function 'tbl_contains'
...pace-diagnostics.nvim/lua/workspace-diagnostics/init.lua:113: in function 'populate_workspace_diagnostics'
/home/sebas/.config/nvim/lua/plugins/lsp-config.lua:290: in function </home/sebas/.config/nvim/lua/plugins/lsp-config.lua:251>
[C]: in function 'nvim_exec_autocmds'
/usr/share/nvim/runtime/lua/vim/lsp/client.lua:946: in function '_on_attach'
/usr/share/nvim/runtime/lua/vim/lsp/client.lua:615: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>
I'm using nvim-jdtls for the lsp stuff. I can of course disable the plugin for Java, as workspace diagnostics work by default, but I guess it would be better if it wasn't needed. Or it's expected by the user to select on which lsp to load the plugin?
Steps to reproduce
- Create any Maven or Gradle project. No need to add code.
- Open a java file in the project
- Error (only the first time in the first file I open)
Expected behavior
Not having an error and just don't do anything, as it is not needed in this case.
Environment
- Neovim version: Nightly
- workspace-diagnostics version: latest
- Plugin clash: nvim-jdtls?
This code assumes that lsp client.config.filetypes exists, but that's evidently not the case with jdtls. Could you run :lua= vim.lsp.get_active_clients(), and paste here the output that corresponds to the client named jdtls?
You are right, it doesn't set a filetype as it's executed on filetype event so no needed (filetypes = { 'java' }, on lazy). I have to go now, but can try to post the client data later. Right now it's too large for a message and it gets cut off.
This code assumes that lsp
client.config.filetypesexists, but that's evidently not the case with jdtls. Could you run:lua= vim.lsp.get_active_client(), and paste here the output that corresponds to the client namedjdtls?
The roslyn server has the same issue, here is the client output for it (vim.lsp.get_active_client does not exist for me, so I used vim.lsp.get_clients() and filtered):
https://snips.sh/f/pe3PhTBOaH
Having the plugin work for it would be nice, as roslyn does not come with workspace diagnostics by default.
Edit: I added the filetype to the server config, but running the command doesn't seem to do anything. I use trouble.nvim to display diagnostics, but it just displays the ones from the open buffers.
This is what I used for initialization.
function()
for _, client in ipairs(vim.lsp.get_clients()) do
if vim.tbl_get(client.config, "filetypes") then
print("loading for" .. client.name)
require("workspace-diagnostics").populate_workspace_diagnostics(client, 0)
end
end
end
Is there something else that needs to be added for servers that are missing the filetype specification by default? If not, should I open a separate issue for this specific to roslyn?
vim.lsp.get_active_clientdoes not exist for me, so I usedvim.lsp.get_clients()
It's vim.lsp.get_active_clients() (I missed s at the end). However, vim.lsp.get_clients() does not exist for me. What's your nvim version?
vim.lsp.get_active_clientdoes not exist for me, so I usedvim.lsp.get_clients()It's
vim.lsp.get_active_clients()(I missedsat the end). However,vim.lsp.get_clients()does not exist for me. What's your nvim version?
Both exist for me :+1:
NVIM v0.11.0-nightly+e820474
Build type: Release
LuaJIT 2.1.1713773202
It looks like roslyn does not advertise file types. Instead it hooks itself on filetype event (just like jdtls):
https://github.com/seblj/roslyn.nvim/blob/5e36cac9371d014c52c4c1068a438bdb7d1c7987/lua/roslyn/init.lua#L256
Can't think of a good work around. We could just pass all project files in that case and hope the server won't fall over?
What I did was add the filetype manually. I think you can do that in the plugin setup like this
require("roslyn").setup({
config = {
filetypes = { 'cs' },
},
})
In any case, I think it would be good for the workspace-diagnostics plugin to early return if it can't identify the filetype instead of crashing, maybe with a message so that people know why it doesn't work.
What I did was add the filetype manually. I think you can do that in the plugin setup like this
Ah, that's nice. I updated the docs.
instead of crashing, maybe with a message so that people know why it doesn't work
Done.
Btw, looks like jdtls is now setting config.filetypes.
Stale issue message