mfussenegger / nvim-jdtls

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

Going to a class file definition via `vim.lsp.buf.definition()` causes errors. #375

Closed DasOhmoff closed 1 year ago

DasOhmoff commented 1 year ago

LSP client configuration

Hello 👋 and thanks again for this nice plugin :)

It works nicely, my only issue is that jumping to class definitions does not seem to be working for some reason. But the issue only occurs if one jumps to code outside my own projekt, for example when one jumps to println in the statement System.out.println.

I disabled everything else, including all other plugins and configs, except the jdtls config:

local jdtls_path = vim.fn.stdpath('data') .. '/mason/packages/jdtls'
local jdtls_config = {
  on_attach = function(_, _)
    require('jdtls').setup_dap({ hotcodereplace = 'auto' })
  end,
  cmd = {
    'java',
    '-Declipse.application=org.eclipse.jdt.ls.core.id1',
    '-Declipse.product=org.eclipse.jdt.ls.core.product',
    '-Dosgi.bundles.defaultStartLevel=4',
    '-Dlog.protocol=true',
    '-Dlog.level=ALL',
    '-Xms1g',

    '--add-modules=ALL-SYSTEM',
    '--add-opens',
    'java.base/java.util=ALL-UNNAMED',
    '--add-opens',
    'java.base/java.lang=ALL-UNNAMED',

    '-jar',
    vim.fn.glob(jdtls_path .. '/plugins/org.eclipse.equinox.launcher_*.jar'),

    '-configuration',
    jdtls_path .. '/config_win',
    '-data',
    jdtls_path
      .. '/my_projects/'
      .. vim.fn.fnamemodify(vim.fn.getcwd(), ':p:h:t'),
  },

  init_options = {
    extendedClientCapabilities = require('jdtls').extendedClientCapabilities,
  },
  settings = {
    java = {
    },
  },
}
}

local jdtls_group_id = vim.api.nvim_create_augroup('extensions.lsp.jdtls', {})
vim.api.nvim_create_autocmd({ 'FileType' }, {
  group = jdtls_group_id,
  pattern = 'java',
  callback = function() require('jdtls').start_or_attach(jdtls_config) end,
})

I am not sure what the issue is, I tried to read through everything carefully, and I tried a long time fixing it and searching for some solution, but I was not able to make it work yet.

Thank you for your help :)

Eclipse.jdt.ls version

v1.18.0

Steps to Reproduce

  1. Open a blank java project.
  2. Write the following code in some method: System.out.println("-");
  3. Put the cursor onto the word println
  4. Use vim.lsp.buf.definition() to jump to the definition
  5. Wait a bit and press efter if some prompt appears
  6. Now you should see an error being thrown

Expected Result

To jump to the definition of the println method, without any errors.

Actual Result

Error message:

Error executing vim.schedule lua callback: Vim(lua):E5108: Error executing lua ...vim-data\site\pack\packer\start\nvim-jdtls/lua/jdtls.lua:992: Vim:E303: Unable to open swap file for "jdt://contents/java.base/java.io/PrintStream.class?=app/C:%5C/Program%20Files%5C/Java%5C/jdk-17.0.5%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.io(PrintStream.class", recovery impossible
stack traceback:
    [C]: in function 'nvim_buf_set_lines'
    ...vim-data\site\pack\packer\start\nvim-jdtls/lua/jdtls.lua:992: in function 'open_jdt_link'
    [string ":lua"]:1: in main chunk
    [C]: in function 'bufload'
    ...ram Files\Neovim\share\nvim\runtime/lua/vim/lsp/util.lua:259: in function 'get_lines'
    ...ram Files\Neovim\share\nvim\runtime/lua/vim/lsp/util.lua:1729: in function 'locations_to_items'
    ...Files\Neovim\share\nvim\runtime/lua/vim/lsp/handlers.lua:352: in function 'handler'
    C:\Program Files\Neovim\share\nvim\runtime/lua/vim/lsp.lua:1390: in function 'cb'
    vim/_editor.lua:262: in function <vim/_editor.lua:261>
stack traceback:
    [C]: in function 'bufload'
    ...ram Files\Neovim\share\nvim\runtime/lua/vim/lsp/util.lua:259: in function 'get_lines'
    ...ram Files\Neovim\share\nvim\runtime/lua/vim/lsp/util.lua:1729: in function 'locations_to_items'
    ...Files\Neovim\share\nvim\runtime/lua/vim/lsp/handlers.lua:352: in function 'handler'
    C:\Program Files\Neovim\share\nvim\runtime/lua/vim/lsp.lua:1390: in function 'cb'
    vim/_editor.lua:262: in function <vim/_editor.lua:261>

Lsp log (verbose): https://pastebin.com/q74yUre0

mfussenegger commented 1 year ago

Can you try with https://github.com/mfussenegger/nvim-jdtls/pull/378 ?

Couldn't reproduce it, but judging from the error message it got something to do with trying to create swap files.

DasOhmoff commented 1 year ago

Perfekt, its working! Thanks :)

mfussenegger commented 1 year ago

Great. Merged the PR