mfussenegger / nvim-jdtls

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

Add bufnr to open_classfile #602

Closed kareem-abdul closed 6 months ago

kareem-abdul commented 6 months ago

Hi, This adds an optional parameter in the function open_classfile, to show decompiled class files to another buffer As per the docs, there is no need to call this function manually, but there are a few cases where we might need to do so. An example is a custom previewer in telescope where the current buffer and the preview buffer are not the same. usage:

require("jdtls").open_classfile(filename, { bufnr = bufnr })
kareem-abdul commented 6 months ago

Workaround

I just found out about this when searching for running functions for a specific buffer.

Neovim's API has a function called vim.api.nvim_buf_call(bufnr, func) which makes the current buffer as bufnr for all the calls that happens inside the func.
i.e

vim.api.nvim_buf_call(bufnr, function() 
   require("jdtls").open_classfile(filename)
end)

This works for me, let me know if this is the right approach.

kareem-abdul commented 6 months ago

Workaround

I just found out about this when searching for running functions for a specific buffer.

Neovim's API has a function called vim.api.nvim_buf_call(bufnr, func) which makes the current buffer as bufnr for all the calls that happens inside the func. i.e

vim.api.nvim_buf_call(bufnr, function() 
   require("jdtls").open_classfile(filename)
end)

This works for me, let me know if this is the right approach.

I've seen the same snippet being done in other repos, and doing it this way does not introduce any problems (I think). And since the snippet does what I originally intended, I'm closing this pr.