Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jdtls will not start for windows #2341

Closed
couryrr opened this issue Dec 22, 2022 · 12 comments
Closed

jdtls will not start for windows #2341

couryrr opened this issue Dec 22, 2022 · 12 comments
Labels
bug Something isn't working

Comments

@couryrr
Copy link

couryrr commented Dec 22, 2022

Description

I have a Windows 11 machine with neovim installed. I have lsp-zero to configure lsp and other parts of the workflow. I have jdtls installed (no I do not need nvim-jdtls yet). I start nvim in a java project and open a file. The configuration is shown correctly but there are no clients attached. To ensure this is a Windows issue I moved my configs over to WSL Ubuntu install and jdtls works perfectly fine out of the box no configs needed.

Neovim version

NVIM v0.8.0-1210-gd367ed9b2
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

Nvim-lspconfig version

5292d60

Operating system and version

Windows 11

Affected language servers

jdtls

Steps to reproduce

  1. Using packer install lsp-zero
  2. In after configure lsp.lua
  3. Open a java file and run :LspInfo

Actual behavior

JDTLS does not start. There are 0 clients attached.

 Use [q] or [Esc] to quit the window
 
 Language client log: C:\Users\Coury\AppData\Local\nvim-data\lsp.log
 Detected filetype:   java
 
 0 client(s) attached to this buffer: 
 
 Other clients that match the filetype: java
 
 Config: jdtls
 	filetypes:         java
 	root directory:    C:\Users\Coury\Documents\Code\interviews\poc\app
 	cmd:               C:\Users\Coury\AppData\Local\nvim-data\mason\packages\jdtls\bin\jdtls-win.cmd -configuration C:\Users\Coury\AppData\Local\nvim-data\mason\packages\jdtls\config_win -data C:\Users\Coury\Documents\Code\java-workspaces\poc
 	cmd is executable: true
 	autostart:         true
 	custom handlers:   language/status, textDocument/codeAction, $/progress, workspace/applyEdit, textDocument/rename
 
 Configured servers list: jdtls, tsserver, eslint, sumneko_lua, gopls

Expected behavior

Import management and autocomplete (WSL Ubuntu works aok).

Minimal config

packer.lua


-- Only required if you have packer configured as `opt`
vim.cmd.packadd('packer.nvim')

return require('packer').startup(function(use)
-- Packer can manage itself
use 'wbthomason/packer.nvim'

use {
  'VonHeikemen/lsp-zero.nvim',
  requires = {
    -- LSP Support
    {'neovim/nvim-lspconfig'},
    {'williamboman/mason.nvim'},
    {'williamboman/mason-lspconfig.nvim'},

    -- Autocompletion
    {'hrsh7th/nvim-cmp'},
    {'hrsh7th/cmp-buffer'},
    {'hrsh7th/cmp-path'},
    {'saadparwaiz1/cmp_luasnip'},
    {'hrsh7th/cmp-nvim-lsp'},
    {'hrsh7th/cmp-nvim-lua'},

    -- Snippets
    {'L3MON4D3/LuaSnip'},
    {'rafamadriz/friendly-snippets'},
  }
}

end)

lsp.lua

local lsp = require('lsp-zero')

lsp.preset('recommended')
lsp.ensure_installed({
  'jdtls',
})

lsp.configure('jdtls', {
    cmd = {
        "jdtls-win.cmd",
        "-configuration",
        "C:\\Users\\Coury\\AppData\\Local\\nvim-data\\mason\\packages\\jdtls\\config_win",
  --      "-jar",
  --    "C:\\Users\\Coury\\AppData\\Local\\nvim-data\\mason\\packages\\jdtls\\plugins\\org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar",
        "-data",
        "C:\\Users\\Coury\\Documents\\Code\\java-workspaces\\poc"
    },
    root_dir = function()
        return vim.fs.dirname(vim.fs.find({'.gradlew', '.git', 'mvnw'}, { upward = true })[1])
    end,
    flags = {
        debounce_text_changes = 150,
    },
    on_attach = function(client, bufnr)
        print('lsp server (jdtls) attached')
    end
})
lsp.setup()

vim.lsp.set_log_level('debug')


### LSP log

https://gist.githubusercontent.com/couryrr/aff415110ff0ae5e6f99c1300f97734c/raw/9494174c9d8f50f6960459cbcc1fc382d0ab40c1/neovim-lspconfig_win_issue.txt
@couryrr couryrr added the bug Something isn't working label Dec 22, 2022
@glepnir
Copy link
Member

glepnir commented Jan 15, 2023

can you try the min config which provide by nvim-lspconfig and i can't open your log.

@wangkaibule
Copy link

It is by any chance that every LSP configuration depending on root_pattern method won't successfully start on Windows?

At least I have to modify the source file everytime after having nvim-lspconfig updated. I believe that for whichever version of libuv that neovim is using does not behave correctly on Windows. Currently I think at least uv.fs_realpath is broken on Windows 10.

The patch below is my own workaround to let nvim-lspconfig work correctly on Windows:

diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua
index 843e63c..5b388fa 100644
--- a/lua/lspconfig/util.lua
+++ b/lua/lspconfig/util.lua
@@ -122,11 +122,7 @@ M.path = (function()
   end
 
   local function is_fs_root(path)
-    if is_windows then
-      return path:match '^%a:$'
-    else
-      return path == '/'
-    end
+    return path == vim.fn.fnamemodify(path, ':h')
   end
 
   local function is_absolute(filename)
@@ -138,20 +134,8 @@ M.path = (function()
   end
 
   local function dirname(path)
-    local strip_dir_pat = '/([^/]+)$'
-    local strip_sep_pat = '/$'
-    if not path or #path == 0 then
-      return
-    end
-    local result = path:gsub(strip_sep_pat, ''):gsub(strip_dir_pat, '')
-    if #result == 0 then
-      if is_windows then
-        return path:sub(1, 2):upper()
-      else
-        return '/'
-      end
-    end
-    return result
+    path = vim.fn.fnamemodify(path, ':h')
+    return path
   end
 
   local function path_join(...)
@@ -160,7 +144,7 @@ M.path = (function()
 
   -- Traverse the path calling cb along the way.
   local function traverse_parents(path, cb)
-    path = uv.fs_realpath(path)
+    path = vim.fn.fnamemodify(path, ':p')
     local dir = path
     -- Just in case our algo is buggy, don't infinite loop.
     for _ = 1, 100 do
@@ -186,7 +170,7 @@ M.path = (function()
       else
         return
       end
-      if v and uv.fs_realpath(v) then
+      if v and vim.fn.fnamemodify(v, ':p') then
         return v, path
       else
         return
@@ -358,7 +342,7 @@ function M.server_per_root_dir_manager(make_config)
 
       -- Launch the server in the root directory used internally by lspconfig, if otherwise unset
       -- also check that the path exist
-      if not new_config.cmd_cwd and uv.fs_realpath(root_dir) then
+      if not new_config.cmd_cwd and vim.fn.fnamemodify(root_dir, ':p') then
         new_config.cmd_cwd = root_dir
       end
 

@justinmk
Copy link
Member

The patch below is my own workaround to let nvim-lspconfig work correctly on Windows:

@wangkaibule PR welcome (any objections @glepnir ?)

@couryrr
Copy link
Author

couryrr commented Jan 26, 2023

@wangkaibule that did seem to be the case. I was trying to dig through myself but was pulled away by other priorities. I ended up switching to nvim-jdtls which works fine. I can pull a new version to try.

@wangkaibule
Copy link

@glepnir To further elaborate the problem, here is the document for uv.fs_realpath. In the document suggests several corner cases on Windows that uv_fs_realpath won't work.

@glepnir
Copy link
Member

glepnir commented Jan 27, 2023

yea there has same problem caused by fs_realpath in windows ..#2343. because I don't have windows . so I can't check how it works in windows.

@seyoatda
Copy link

seyoatda commented Apr 1, 2023

I got caught in the same situation using Windows 11. Is this problem solved yet?

@dundargoc
Copy link
Member

dundargoc commented Apr 1, 2023

This is the opposite of a minimal config. Is downloading for example "LuaSnip" really necessary to recreate the problem?

@dundargoc
Copy link
Member

I am closing the thread due to insufficient information. I do not want to wade through miles of config to find the actual source of the problem. If anyone is still encountering this problem (@wangkaibule @seyoatda perhaps?), then I encourage you make a new issue with an actual minimal configuration.

@dundargoc dundargoc closed this as not planned Won't fix, can't repro, duplicate, stale Apr 1, 2023
@couryrr
Copy link
Author

couryrr commented Apr 3, 2023

@dundargoc my apologies I will work to re-create with a smaller config. Would the appropriate take be to create a new issue?

@dundargoc dundargoc reopened this Apr 3, 2023
@dundargoc
Copy link
Member

Nah, you can edit this issue.

@couryrr
Copy link
Author

couryrr commented Apr 3, 2023

@dundargoc it looks like the fix mentioned above has been merged. I cannot appear to reproduce on newer versions. I am closing.

@couryrr couryrr closed this as completed Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants