mfussenegger / nvim-jdtls

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

Goto definition results in error after commit ad5ab1c #666

Open michaelPotter opened 3 weeks ago

michaelPotter commented 3 weeks ago

LSP client configuration

-- This specifies extra jars that get loaded into the Language Server
local bundles = {
    vim.fn.glob('$HOME/.local/share/nvim/mason/packages/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar'),
}
vim.list_extend(bundles, vim.split(vim.fn.glob("$HOME/.local/share/nvim/mason/packages/java-test/extension/server/*.jar", true), "\n"))

local jdtls_lsp = require("mason-registry").get_package("jdtls")

local config = {
    cmd = {
        vim.fn.expand('$HOME/.local/share/nvim/mason/bin/jdtls'),
        -- https://github.com/LazyVim/LazyVim/discussions/275
        "--jvm-arg=-javaagent:" .. jdtls_lsp:get_install_path() .. "/lombok.jar",
    },
    root_dir = vim.fs.dirname(vim.fs.find({'gradlew', '.git', 'mvnw'}, { upward = true })[1]),
    on_attach = on_attach,
    settings = {
        java = {
            configuration = {
                runtimes = {
                    {
                        name = "JavaSE-17",
                        path = "/usr/lib/jvm/java-17-openjdk/",
                    },
                },
            },
        },
    },
    init_options = {
        bundles = bundles,
    },
}

Eclipse.jdt.ls version

No response

Steps to Reproduce

(This seems to be a regression in commit ad5ab1c? It seems to work okay on commit 1069131 or earlier.)

First checkout commit ad5ab1c or later.

Call vim.lsp.buf.definition on a class, eg

import java.util.Arrays;

Expected Result

The class definition is opened.

Actual Result

An empty buffer loads and I get the following error:

Error executing vim.schedule lua callback: /usr/share/nvim/runtime/lua/vim/lsp/util.lua:1125: BufReadCmd Autocommands for "jdt://*": Vim(lua):E5108: Error executing lua ...mlpotter/.local/sha re/nvim/lazy/nvim-jdtls/lua/jdtls.lua:1193: Must have a jdtls client to load class file or jdt uri stack traceback: [C]: in function 'assert' ...mlpotter/.local/share/nvim/lazy/nvim-jdtls/lua/jdtls.lua:1193: in function 'open_classfile' [string ":lua"]:1: in main chunk [C]: in function 'nvim_win_set_buf' /usr/share/nvim/runtime/lua/vim/lsp/util.lua:1125: in function 'jump_to_location' ...nvim/lazy/telescope.nvim/lua/telescope/builtin/__lsp.lua:187: in function 'handler' /usr/share/nvim/runtime/lua/vim/lsp/client.lua:685: in function '' vim/_editor.lua: in function <vim/_editor.lua:0> stack traceback: [C]: in function 'nvim_win_set_buf' /usr/share/nvim/runtime/lua/vim/lsp/util.lua:1125: in function 'jump_to_location' ...nvim/lazy/telescope.nvim/lua/telescope/builtin/__lsp.lua:187: in function 'handler' /usr/share/nvim/runtime/lua/vim/lsp/client.lua:685: in function '' vim/_editor.lua: in function <vim/_editor.lua:0>

fwiw, in both commits where it does/doesn't work, set buftype? returns buftype=nofile for the jdt:// buffer

Thanks!

robertenjoy commented 3 weeks ago

I had the same problem。

639

close lazy.nvim lazyload create ~/.config/nvim/ftplugin/java.lua Solved my problem

michaelPotter commented 3 weeks ago

Thanks!

I already configure jdtls through ~/.config/nvim/ftplugin/java.lua. I don't lazy load either.

Some other info after reading through #639 and #59 again...

Running this ...

:lua require("jdtls").open_classfile("jdt://contents/java.base/java.util/Arrays.class?=jdt.ls-java-project/%5C/usr%5C/lib%5C/jvm%5C/java-17-openjdk%5C/lib%5C/jrt-fs.jar%60java.base=/javadoc_location=/https:%5C/%5C/docs.oracle.com%5C/en%5C/java%5C/javase%5C/17%5C/docs%5C/api%5C/=/%3Cjava.util(Arrays.class")

... DOES populate the (current, already open) buffer with both commits 1069131 and ad5ab1c (had the wrong commit here earlier but I double checked ad5ab1c).

Also ...

:verbose autocmd BufReadCmd jdt://*
--- Autocommands ---
BufReadCmd
    jdt://*   lua require('jdtls').open_classfile(vim.fn.expand('<amatch>'))
        Last set from ~/.local/share/nvim/lazy/nvim-jdtls/plugin/nvim_jdtls.vim line 6
michaelPotter commented 3 weeks ago

Did a little digging... Seems like jdtls.setup.attach_to_active_buf() might not be doing the right thing? Assuming the goal is to find an active jdtls client instance from other buffers and start_or_attach should use that to short-circuit before the code added in ad5ab1c ?

I get this message using both commits... Seems to come from the bottom of attach_to_active_buf.

No active LSP client found to use for jdt:// document

In case it is relevant I have ...

$ nvim --version
NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1713773202