williamboman / mason.nvim

Portable package manager for Neovim that runs everywhere Neovim runs. Easily install and manage LSP servers, DAP servers, linters, and formatters.
Apache License 2.0
7.51k stars 264 forks source link

JDTLS not working #1412

Closed Karol-Janowski closed 1 year ago

Karol-Janowski commented 1 year ago

I've searched open issues for similar requests

I've manually reviewed logs to find potential errors

I've recently downloaded the latest plugin version of mason.nvim

Problem description

Hello, i'm trying to write java code in Neovim. Although when i download JDTLS via Mason it doesn't work properly. Basically I have no features related to JDTLS when i open java file. When i do :Mason its prompting me that everything is OK - JDTLS is installed. I know that I can configure JDTLS by myself by downloading it from eclipse site etc but i would rather prefer to use it via Mason. For example in LunarVim it works perfectly fine. I have no idea what it's not working in my own neovim configuration ( not LunarVim ). Maybe someone know what is the problem. I heard in some YT tutorial about JDTLS that its just not supported via Mason so its needed to be configured by downloading from Eclipse site and manually configured (by creating ftpplugin folder and then java.lua). But I just downloaded LunarVim about week ago and i see its work there just fine. Please help maybe someone know how to configure JDTLS via Mason. Thanks!

Expected behavior

JDTLS language server should start when opening java file.

Steps to reproduce

  1. Install JDTLS language server via Mason
  2. Open any java file

Affected packages

All

Neovim version (>= 0.7)

NVIM v.0.9.1

Operating system/version

Mac OS

Healthcheck

Mason: require("Mason.health").check()

mason.nvim ~
- OK mason.nvim version v1.6.0
- OK PATH: prepend
- OK Providers: 
  mason.providers.registry-api
  mason.providers.client
- OK neovim version >= 0.7.0

mason.nvim [Registries] ~
- OK Registry `github.com/mason-org/mason-registry version: 2023-07-13-grand-nation` is installed.

mason.nvim [Core utils] ~
- OK unzip: `UnZip 6.00 of 20 April 2009, by Info-ZIP.  Maintained by C. Spieler.  Send`
- WARNING wget: not available
  - ADVICE:
    - spawn: wget failed with exit code - and signal -. wget is not executable
- OK curl: `curl 7.88.1 (x86_64-apple-darwin22.0) libcurl/7.88.1 (SecureTransport) LibreSSL/3.3.6 zlib/1.2.11 nghttp2/1.51.0`
- OK gzip: `Apple gzip 403.100.6`
- OK tar: `bsdtar 3.5.3 - libarchive 3.5.3 zlib/1.2.11 liblzma/5.0.5 bz2lib/1.0.8 `
- OK bash: `GNU bash, version 3.2.57(1)-release (arm64-apple-darwin22)`
- OK sh: `Ok`

mason.nvim [Languages] ~
- WARNING Go: not available
  - ADVICE:
    - spawn: go failed with exit code - and signal -. go is not executable
- WARNING Composer: not available
  - ADVICE:
    - spawn: composer failed with exit code - and signal -. composer is not executable
- WARNING PHP: not available
  - ADVICE:
    - spawn: php failed with exit code - and signal -. php is not executable
- WARNING luarocks: not available
  - ADVICE:
    - spawn: luarocks failed with exit code - and signal -. luarocks is not executable
- OK Ruby: `ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin22]`
- OK RubyGem: `3.0.3.1`
- OK java: `openjdk version "17.0.7" 2023-04-18 LTS`
- WARNING julia: not available
  - ADVICE:
    - spawn: julia failed with exit code - and signal -. julia is not executable
- OK python: `Python 3.11.4`
- OK JAVA_HOME: `openjdk version "17.0.7" 2023-04-18 LTS`
- OK cargo: `cargo 1.70.0 (ec8a8a0ca 2023-04-25)`
- OK javac: `javac 17.0.7`
- OK node: `v20.4.0`
- OK pip: `pip 23.0.1 from /opt/homebrew/lib/python3.11/site-packages/pip (python 3.11)`
- OK python venv: `Ok`
- OK npm: `9.7.2`

mason.nvim [GitHub] ~
- OK GitHub API rate limit. Used: 1. Remaining: 59. Limit: 60. Reset: Sun Jul 16 10:56:33 2023.
  Install and authenticate via gh-cli to increase rate limit.

Screenshots or recordings

Screenshot 2023-07-16 at 10 48 29
schizophrenical commented 1 year ago

Hi, just chiming in. I just setup jdtls (using my own neovim config) using the package provided by mason. Since jdtls recommends setting up via ftplugin, it's something that needs to be done in your config. I am not familiar with how LunarVim sets up the LSP servers but if you are writing your own config, you should add a java filetype to your ftplugin directory and manually the setup (you can refer to the configuration section) for it to work.

I am not an expert on neovim configuration, but from what I learned so far, mason.nvim helps with the building and downloading and building of external packages (such as eclipse jdtls); but one still needs some configuration to do in order to use the mason packages.

Karol-Janowski commented 1 year ago

Hi, just chiming in. I just setup jdtls (using my own neovim config) using the package provided by mason. Since jdtls recommends setting up via ftplugin, it's something that needs to be done in your config. I am not familiar with how LunarVim sets up the LSP servers but if you are writing your own config, you should add a java filetype to your ftplugin directory and manually the setup (you can refer to the configuration section) for it to work.

I am not an expert on neovim configuration, but from what I learned so far, mason.nvim helps with the building and downloading and building of external packages (such as eclipse jdtls); but one still needs some configuration to do in order to use the mason packages.

Hi and thank you for the answer. I think u hit the point and i just missed this configuration file ( actually im pretty sure because i configure it once by myself and it worked fine ). I just thought Mason would do all the "dirty work" for me :)

Karol-Janowski commented 1 year ago

Okey i did as u said via ftplugin/java.lua and it works fine but i still get the message on the bottom "LSP: No Lsp" - on the left "ServiceReady". In LunarVim u get the message "LSP: jdtls" - with no message on the bottom left. So i think there's need to be a way to configure it like they did. I tried to read LunarVim source code but i can't figure out how they did this - like for example clangd, pyright, Lua and others. Maybe someone have the answer how to do it like LunarVim. I like to use my own config but I really like the way how they configure jdtls in lunarVim lol

schizophrenical commented 1 year ago

In LunarVim u get the message "LSP: jdtls" - with no message on the bottom left. So i think there's need to be a way to configure it like they did.

If by 'message', you mean the statusline? I did a quick look on LunarVim's repository and this is what you are looking for. Take note that LunarVim has custom components for lualine, one of those is the LSP client's name. You can take a look at this example as it's much simpler that what is on LunarVim.

For the 'ServiceReady' message, you can implement your own handler for the LSP status messages like below:

-- In your java ftplugin file
local jdtls_conf = {
  handlers = {
    -- This will make the progress messages like 'ServiceReady' go away.
    -- Or you can customize the messages depending on what you like
    ['language/status'] = function() end,
  },
  -- settings
  settings = {
  -- jdtls settings goes here.
  },
}
jdtls.start_or_attach(jdtls_conf)
Karol-Janowski commented 1 year ago

In LunarVim u get the message "LSP: jdtls" - with no message on the bottom left. So i think there's need to be a way to configure it like they did.

If by 'message', you mean the statusline? I did a quick look on LunarVim's repository and this is what you are looking for. Take note that LunarVim has custom components for lualine, one of those is the LSP client's name. You can take a look at this example as it's much simpler that what is on LunarVim.

For the 'ServiceReady' message, you can implement your own handler for the LSP status messages like below:

-- In your java ftplugin file
local jdtls_conf = {
  handlers = {
    -- This will make the progress messages like 'ServiceReady' go away.
    -- Or you can customize the messages depending on what you like
    ['language/status'] = function() end,
  },
  -- settings
  settings = {
  -- jdtls settings goes here.
  },
}
jdtls.start_or_attach(jdtls_conf)

I have the same configuration in my lualine.lua file as u send in the second link. Although i'm still getting this prompt of "No Lsp" when JDTLS server is active. I see there is a bunch of configuration files in LunarVim LuaLine - your first link. I think i ll try to play around with but i see its a thought one ehh

image
schizophrenical commented 1 year ago

Maybe because there is no filetype detected from the jdtls LSP. How about trying this? See the new filetypes propety.

-- In your java ftplugin file
local jdtls_conf = {
  handlers = {
    -- handler here.
  },
  -- Add filetypes property for jdtls
  filetypes = {
    'java',
  },
  -- settings
  settings = {
  -- jdtls settings goes here.
  },
}
jdtls.start_or_attach(jdtls_conf)
Karol-Janowski commented 1 year ago

ok i opened some java project in LunarVim and when i did :LspInfo i get this:

image

So it looks like somehow they managed to configure JDTLS via nvim-lsp. Notice that if u do this "manually" ( ftplugin/java.lua and all the settings") u get the :LspInfo Autostart False. Very interesting i have no idea how they did this lol

Karol-Janowski commented 1 year ago

Okey i manage to do this. i just add "jdtls.setup{ cmd = { 'jdtls' } }" to my lspconfig.lua file then require it from lua.init. Its works fine but i see that when u do it manually you can configure more options then if u do this via lspconfig but then u ll have this prompt "No Lsp" and autostart "false". ehh its a pity.

here is the link: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#jdtls

So i see it's some kind of a trade - if u want to have more configs u cant do this via lspconfig but via ftplugins/java.lua but then u ll have no lsp prompt and autostart false. Hope they ll fix this someday to work like language servers for other languages :<

williamboman commented 1 year ago

Thanks @schizophrenical for helping. However this is not the right place for support for how to use LSP servers as there are many different options to do so, all unrelated to Mason.