LazyVim / LazyVim

Neovim config for the lazy
https://lazyvim.github.io/
Apache License 2.0
17.08k stars 1.2k forks source link

feature: (extras.lang.java jdtls): Add ability to extend jdtls `bundles` by user #4578

Open sergii-dudar opened 1 week ago

sergii-dudar commented 1 week ago

Did you check the docs?

Is your feature request related to a problem? Please describe.

No, it's not a problem at all, but it makes it impossible to extend JDTLS if needs it. As a Java developer, for me, not enough just raw JDTLS; I need at least vs spring-boot tools ls support also, to achieve it, I need be able to add a couple extra *.jar to the result config.init_options.bundles, and that's where I have a problem - it looks impossible, I can only replace default bundles, but not extend.

https://github.com/LazyVim/LazyVim/blob/13a4a84e3485a36e64055365665a45dc82b6bf71/lua/lazyvim/plugins/extras/lang/java.lua#L161

Describe the solution you'd like

I want to be able to extend (not replace) actual jdtls config.init_options.bundles with extra functionalities I need

https://github.com/LazyVim/LazyVim/blob/13a4a84e3485a36e64055365665a45dc82b6bf71/lua/lazyvim/plugins/extras/lang/java.lua#L165

Describe alternatives you've considered

To resolve it right now, we can add support of additional function specifically to extend bundles, for example:

            if opts.extend_jdtls_bundles, then
                opts.extend_jdtls_bundles(bundles)
            end

In my config, to achieve it, I copied full extras.lang.java in my config, and added next 3 lines:

https://github.com/sergii-dudar/dotfiles/blob/c35c99ee6adcd53ab4c2429eeeef2e2c685f997a/nvim/.config/nvim/lua/plugins/editor/java/immutable-java.lua#L160

not sure it's very elegant.

Additional context

Please let me know if there present a better solution, and if I can create PR to extend it, just let me know. Thanks a lot

dpetka2001 commented 1 week ago

No need to define a new function. Putting the following just before the function attach_jdtls() at line 157

      if opts.extend_jdtls_bundles then
        vim.list_extend(bundles, opts.extend_jdtls_bundles)
      end

should achieve what you want I believe. bundles is a list of strings either way. Test it out to see if it works on your side, because I'm just a regular user like you and don't do any Java. If it works, then submit a PR for the maintainer to review.

Please note the maintainer is currently on vacation as also noted on the pinned issue.

sergii-dudar commented 1 week ago

No need to define a new function. Putting the following just before the function attach_jdtls() at line 157

  if opts.extend_jdtls_bundles then
    vim.list_extend(bundles, opts.extend_jdtls_bundles)
  end

should achieve what you want I believe.

Yes, it's exactly what I did to achieve it to work properly, see here in my config

https://github.com/sergii-dudar/dotfiles/blob/c35c99ee6adcd53ab4c2429eeeef2e2c685f997a/nvim/.config/nvim/lua/plugins/editor/java/immutable-java.lua#L160

immutable-java.lua it's exact copy of https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/plugins/extras/lang/java.lua with just one additional call of vim.list_extend(bundles, opts.extend_jdtls_bundles)

I don't want to create PR for now, as I'm not sure if my way is good enough, and if it's follows maintainer roles. It's my first feature request here.

Yeah, I will wait maintainer Thanks a lot