workspace-diagnostics.nvim icon indicating copy to clipboard operation
workspace-diagnostics.nvim copied to clipboard

Error in java projects (jdtls.nvim)

Open SebasF1349 opened this issue 1 year ago • 10 comments

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

  1. Create any Maven or Gradle project. No need to add code.
  2. Open a java file in the project
  3. 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?

SebasF1349 avatar May 22 '24 19:05 SebasF1349

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?

artemave avatar May 23 '24 20:05 artemave

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.

SebasF1349 avatar May 25 '24 16:05 SebasF1349

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_client(), and paste here the output that corresponds to the client named jdtls?

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?

SchnozzleCat avatar Aug 08 '24 11:08 SchnozzleCat

vim.lsp.get_active_client does not exist for me, so I used vim.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?

artemave avatar Aug 08 '24 13:08 artemave

vim.lsp.get_active_client does not exist for me, so I used vim.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?

Both exist for me :+1: image

NVIM v0.11.0-nightly+e820474
Build type: Release
LuaJIT 2.1.1713773202

SchnozzleCat avatar Aug 08 '24 13:08 SchnozzleCat

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?

artemave avatar Aug 09 '24 18:08 artemave

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.

SebasF1349 avatar Aug 09 '24 19:08 SebasF1349

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.

artemave avatar Aug 10 '24 12:08 artemave

Btw, looks like jdtls is now setting config.filetypes.

artemave avatar Aug 10 '24 13:08 artemave

Stale issue message

github-actions[bot] avatar Oct 10 '24 04:10 github-actions[bot]