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

Several issues with fzf-lua integration #478

Closed asmodeus812 closed 1 year ago

asmodeus812 commented 1 year ago

LSP client configuration

Hi, wanted to share how great nvim-jdtls has been recently, but i have noticed that two issues have popped up recently i think are related to the de compilation of the class files with fzf-lua's default builtin previewer. One of the issues is related to missing / invalid window handle error when working with lsp_workspace_symbols the other one is related to lsp_document symbols. Below i have tried to explain the issues and referenced the issue in the fzf-lua repo to reproduce it. I suspect the issue has something to do with the way we handle the jdt:// resources in the current buffer but not well versed with jdtls to know exactly what is going on.

                        cmd =  {
        executable,
        "-Declipse.application=org.eclipse.jdt.ls.core.id1",
        "-Dosgi.bundles.defaultStartLevel=4",
        "-Declipse.product=org.eclipse.jdt.ls.core.product",
        "--add-modules=ALL-SYSTEM",
        "--add-opens",
        "java.base/java.util=ALL-UNNAMED",
        "--add-opens",
        "java.base/java.lang=ALL-UNNAMED",
        "--add-opens",
        "java.base/sun.nio.fs=ALL-UNNAMED",
        "-javaagent:" .. SERVER_BUNDLES[1],
        "-jar",
        SERVER_BUNDLES[2],
        "-configuration",
        CONFIG_BUNDLES[1],
        "-data",
        data },
            -- See: https://github.com/eclipse/eclipse.jdt.ls#running-from-the-command-line for jdtls configuration
            filetypes = {
                "java"
            },
            init_options = {
                bundles = ext.get_pkg_bundles({
                    ["java-test"] = "extension/server/*",
                    ["java-debug-adapter"] = "extension/server/*",
                }),
            },
            -- See https://github.com/eclipse/eclipse.jdt.ls/wiki/running-the-java-ls-server-from-the-command-line#initialize-request
            settings = {
                java = {
                    trace = {
                        server = "message",
                    },
                    autobuild = {
                        enabled = true
                    },
                    configuration = {
                        updateBuildConfiguration = "interactive",
                    },
                    contentProvider = {
                        preferred = "fernflower"
                    },
                    references = {
                        includeDecompiledSources = true,
                    },
                    signatureHelp = {
                        enabled = true,
                        description = {
                            enabled = true
                        }
                    },
                    referencesCodeLens = {
                        enabled = false,
                    },
                    implementationsCodeLens = {
                        enabled = false,
                    },
                    format = {
                        -- See https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml for code style
                        enabled = true,
                    },
                    saveActions = {
                        organizeImports = true
                    },
                    sources = {
                        organizeImports = {
                            starThreshold = 9999,
                            staticStarThreshold = 9999
                        }
                    },
                    favoriteStaticMembers = {
                        "org.junit.jupiter.api.DynamicTest.*",
                        "org.junit.jupiter.api.Assertions.*",
                        "org.junit.jupiter.api.Assumptions.*",
                        "org.junit.jupiter.api.DynamicContainer.*",
                        "org.junit.Assert.*",
                        "org.junit.Assume.*",
                        "java.util.Objects.*",
                        "org.mockito.ArgumentMatchers.*",
                        "org.mockito.Mockito.*",
                        "org.mockito.Answers.*",
                    },
                    filteredTypes = {
                        "java.awt.*",
                        "com.sun.*",
                        "jdk.*",
                        "sun.*",
                    },
                    completion = {
                        importOrder = {
                            "javax",
                            "java",
                            "com",
                            "org"
                        }
                    },
                    codeGeneration = {
                        tostring = {
                            skipNullValues = true,
                            listArrayContents = true,
                            template = "${object.className}{${member.name()}=${member.value}, ${otherMembers}}",
                        },
                        useBlocks = true,
                        hashCodeEquals = {
                            useInstanceof = true,
                            useJava7Objects = true
                        },
                        generateComments = false,
                        insertLocation = true
                    },
                    eclipse = {
                        downloadSources = true
                    },
                    maven = {
                        downloadSources = true,
                        updateSnapshots = true
                    },
                }
            },

Eclipse.jdt.ls version

1.22

Steps to Reproduce

lsp_workspace_symbols

  1. Open/browse lsp_workspace_symbols
  2. For query enter with empty string
  3. Start writing immediately, (e.g hashmap)
  4. Observe error with the preview window
Error executing vim.schedule lua callback: .../nvim/site/pack/packer/start/fzf-lua/lua/fzf-lua/win.lua:288: Invalid
 window id: 1007
stack traceback:
        [C]: in function 'nvim_win_set_option'
        .../nvim/site/pack/packer/start/fzf-lua/lua/fzf-lua/win.lua:288: in function 'reset_win_highlights'
        ...k/packer/start/fzf-lua/lua/fzf-lua/previewer/builtin.lua:272: in function 'populate_preview_buf'
        ...k/packer/start/fzf-lua/lua/fzf-lua/previewer/builtin.lua:286: in function ''
        vim/_editor.lua: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

lsp_document_symbols

  1. Open regular java file from your project
  2. Open in a v/split window, java.util.Hashmap
  3. Open lsp_document_symbols in HashMap
  4. Filter to a symbol, enter to move to it
  5. All other split windows get closed

NOTE: if instead of filtering, we select the first entry the other split windows are not getting closed, the issue was discussed here https://github.com/ibhagwan/fzf-lua/issues/728#issuecomment-1518684511

Expected Result

No issues from both use cases should be observed. I can confirm that other language servers do not exhibit this issue. Tagging @ibhagwan for reference.

Actual Result

Described above, but the basic gist - document_symbols fails to navigate to the selected symbol, workspace_symbols throws error with invalid window handle.

mfussenegger commented 1 year ago

I don't really see how this could be an jdtls issue.

All nvim-jdtls is define a BufReadCmd:

au BufReadCmd jdt://* lua require('jdtls').open_classfile(vim.fn.expand('<amatch>'))
au BufReadCmd *.class lua require("jdtls").open_classfile(vim.fn.expand("<amatch>"))

and open_classfile queries the language server for the content and adds it to the buffer.

If that doesn't work with fzf-lua, I assume it in general has problems with custom BufReadCmd autocmds.

asmodeus812 commented 1 year ago

Indeed probably something to do with the way the class contents are populated or the view buffer is used, @ibhagwan and i talked about in the linked issue above, and that is why as he suggested i cross posted the issue, so we can take a look at what is going on, it is certainly an interaction between both, but i can't tell why either.

mfussenegger commented 1 year ago

Does the problem also reproduce with something like this:

api.nvim_create_autocmd("BufReadCmd", {
  pattern = "foo://*",
  callback = function()
    local bufnr =  api.nvim_get_current_buf()
    vim.bo[bufnr].modifiable = true
    vim.bo[bufnr].swapfile = false
    vim.bo[bufnr].buftype = 'nofile'
    api.nvim_buf_set_lines(bufnr, 0, -1, true, {"dummy", "content"})
    vim.bo[bufnr].modifiable = false
  end
})

And then opening foo://dummy?

ibhagwan commented 1 year ago

Unfortunately I am unable to attempt to fix this issue due to a startup crash of jdtls as described here https://github.com/mfussenegger/nvim-jdtls/issues/459#issuecomment-1517944867

It seems I’m not the only one experiencing this, never used Java before just installed it in order to tackle this issue but can’t get any further. It’s worth mentioning that the same setup worked in the past, when first adding support for nvim-jdtls previews.

ibhagwan commented 1 year ago

After fixing my jdtls setup I believe was able to fix the issues described in the OP in https://github.com/ibhagwan/fzf-lua/commit/9d9eea43c4e94268e22f1bb5d7cbff7c98f81300.

@asmodeus812 try the latest commit and let me know?