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.71k stars 271 forks source link

jdtls cannot find the projects root directory. Language server does not start #401

Closed DasOhmoff closed 2 years ago

DasOhmoff commented 2 years ago

I believe this to be an issue that should be addressed by maintainers of mason.nvim.

Why do you think this is an issue with mason.nvim?

After installing the language server via Mason, I think the LSP is supposed to automatically start when entering java files, which it does not do.

Neovim version (>= 0.7)

NVIM v0.7.2 Build type: RelWithDebInfo LuaJIT 2.1.0-beta3

Operating system/version

Windows 10, 64 bit

I've manually reviewed logs to find potential errors

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

Affected packages

jdtls

Problem description

After installing jdtls via mason, jdtls cannot find the projects root directory. Language server does not start. Here is the error:

 Config: jdtls
    Refer to :h lspconfig-root-detection for help.
    filetypes:         java
    root directory:    Not found. Searched for: { -- Single-module projects { 'build.xml', -- Ant 'pom.xml', -- Maven 'settings.gradle', -- Gradle 'settings.gradle.kts', -- Gradle }, -- Multi-module projects { 'build.gradle', 'build.gradle.kts' }, } or vim.fn.getcwd().
    cmd:               C:\Users\Adam\AppData\Local\nvim-data\mason\bin\jdtls.CMD -configuration C:\Users\Adam/.cache/jdtls/config -data C:\Users\Adam/.cache/jdtls/workspace
    cmd is executable: true
    autostart:         true
    custom handlers:   workspace/applyEdit, textDocument/rename, language/status, textDocument/codeAction

Steps to reproduce

  1. Set the vim config:
    
    call plug#begin("~/.vim/plugged")

Plug 'williamboman/mason.nvim' Plug 'williamboman/mason-lspconfig.nvim' Plug 'neovim/nvim-lspconfig'

call plug#end()

2. Set the lua config:
```lua
require("mason").setup()
require("mason-lspconfig").setup()
require("lspconfig").jdtls.setup {}
  1. Install jdtls via MasonInstall jdtls
  2. Open a java file in a java project that contains a settings.gradle or so image
  3. Use the LspInfo command to see that the root directory of the project was not found image

Actual behavior

After installing jdtls via mason, jdtls cannot find the projects root directory. Language server does not start.

Expected behavior

After installing jdtls via mason, jdtls should be able to find the projects root directory. Language server should start.

Healthcheck

mason: require("mason.health").check()
========================================================================
## mason.nvim report
  - OK: neovim version >= 0.7.0
  - WARNING: **Go**: unsupported version `go version go1.16.7 windows/amd64`. Go version must be >= 1.17.
  - OK: **cargo**: `cargo 1.61.0 (a028ae42f 2022-04-29)`
  - OK: **luarocks**: `luarocks 3.9.1
`
  - OK: **Ruby**: `ruby 2.6.5p114 (2019-10-01 revision 67812) [x64-mingw32]
`
  - OK: **RubyGem**: `3.0.3
`
  - WARNING: **Composer**: not available
  - WARNING: **PHP**: not available
  - OK: **npm**: `8.18.0`
  - OK: **node**: `v16.17.0
`
  - OK: **python3**: `Python 3.10.6
`
  - OK: **pip3**: `pip 22.2.1 from C:\Users\Adam\AppData\Local\Programs\Python310\lib\site-packages\pip (python 3.10)

`
  - OK: **javac**: `javac 17.0.4.1
`
  - OK: **java**: `java version "17.0.4.1" 2022-08-18 LTS
`
  - WARNING: **julia**: not available
  - ERROR: **wget**: not available
  - OK: **curl**: `curl 7.83.1 (Windows) libcurl/7.83.1 Schannel
`
  - OK: **gzip**: `gzip 1.11`
  - OK: **tar**: `bsdtar 3.5.2 - libarchive 3.5.2 zlib/1.2.5.f-ipp 
`
  - OK: **python**: `Ok`
  - OK: **pip**: `pip 22.2.1 from C:\Users\Adam\AppData\Local\Programs\Python310\lib\site-packages\pip (python 3.10)

`
  - WARNING: **python3_host_prog**: not available
  - OK: **JAVA_HOME**: `openjdk version "18.0.2.1" 2022-08-18
`
  - OK: GitHub API rate limit. Used: 0. Remaining: 60. Limit: 60. Reset: 9/10/2022 7:36:44 PM.


### Screenshots or recordings

_No response_
williamboman commented 2 years ago

Hello! Mason is not involved in starting servers, since you use lspconfig it's lspconfig that is responsible. I believe this is not an issue with Mason so I'll go ahead and close this. I'd recommend checking :LspLog if you haven't already - if you find something more that indicates this is indeed something with Mason let's reopen!

boning-w commented 2 years ago

It's not an issue of Mason. I think you need to configure the jdtls correctly with your lspconfig. The default configuration of jdtls in lspconfig is not suitable for us, we need to modify it.

See this for help

Mine is:

local home = vim.fn.getenv("HOME")

return {
    cmd = {
        "java",
        "-Declipse.application=org.eclipse.jdt.ls.core.id1",
        "-Dosgi.bundles.defaultStartLevel=4",
        "-Declipse.product=org.eclipse.jdt.ls.core.product",
        "-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",
        home .. "/.local/share/nvim/mason/packages/jdtls/plugins/org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar",
        "-configuration",
        home .. "/.local/share/nvim/mason/packages/jdtls/config_linux",
        "-data",
        home .. "/.local/share/nvim/mason/packages/jdtls/workspace",
    },
    root_dir = function(fname)
        return require("lspconfig").util.root_pattern("pom.xml", "gradle.build", ".git")(fname) or vim.fn.getcwd()
    end,
}

And here is the capture:

Screen Shot 2022-09-13 at 22 42 55
DasOhmoff commented 2 years ago

@boningggg Thanks! That was exactly the issue.

I did not know that it needs to be configured, there was nothing in the mason doc or installation or so that told me that I need to configure something, I think it would be nice if its mentioned somewhere. Especially as someone who just started using nvims lsp, there is so much stuff that has to be read and learned and so much time that has to be invested, the learning curve is very high.