Skip to content

Commit e1bb01d

Browse files
committed
fix: windows compatibility issue (#439)
1 parent 9743dde commit e1bb01d

File tree

5 files changed

+54
-6
lines changed

5 files changed

+54
-6
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"lazy.nvim": { "branch": "main", "commit": "85c7ff3711b730b4030d03144f6db6375044ae82" },
33
"nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" },
4-
"nvim-dap": { "branch": "master", "commit": "b38f7d30366d9169d0a623c4c85fbcf99d8d58bb" },
5-
"nvim-jdtls": { "branch": "master", "commit": "943e2398aba6b7e976603708450c6c93c600e830" },
4+
"nvim-dap": { "branch": "master", "commit": "5860c7c501eb428d3137ee22c522828d20cca0b3" },
65
"spring-boot.nvim": { "branch": "main", "commit": "218c0c26c14d99feca778e4d13f5ec3e8b1b60f0" }
76
}

lua/java-core/ls/servers/jdtls/cmd.lua

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ function M.get_cmd(opts)
2020
return function(dispatchers, config)
2121
local cmd = M.get_jvm_args(opts):concat(M.get_jar_args())
2222

23-
M.validate_java_version(config.cmd_env)
23+
-- NOTE: eventhough we are setting the PATH env var, due to a bug, it's not
24+
-- working on Windows. So just lanching 'java' will result in executing the
25+
-- system java. So as a workaround, we use the absolute path to java instead
26+
-- So following check is not needed when we have auto_install set to true
27+
-- @see https://github.com/neovim/neovim/issues/36818
28+
if not conf.jdk.auto_install then
29+
M.validate_java_version(config.cmd_env)
30+
end
2431

2532
log.debug('Starting jdtls with cmd', cmd)
2633

@@ -40,8 +47,25 @@ end
4047
function M.get_jvm_args(opts)
4148
local jdtls_config = path.join(jdtls_root, system.get_config_suffix())
4249

50+
local java_exe = 'java'
51+
52+
-- NOTE: eventhough we are setting the PATH env var, due to a bug, it's not
53+
-- working on Windows. So we are using the absolute path to java instead
54+
-- @see https://github.com/neovim/neovim/issues/36818
55+
if conf.jdk.auto_install then
56+
local jdk_root = Manager:get_install_dir('openjdk', conf.jdk.version)
57+
local java_home
58+
if system.get_os() == 'mac' then
59+
java_home = vim.fn.glob(path.join(jdk_root, 'jdk-*', 'Contents', 'Home'))
60+
else
61+
java_home = vim.fn.glob(path.join(jdk_root, 'jdk-*'))
62+
end
63+
64+
java_exe = path.join(java_home, 'bin', 'java')
65+
end
66+
4367
local jvm_args = List:new({
44-
'java',
68+
java_exe,
4569
'-Declipse.application=org.eclipse.jdt.ls.core.id1',
4670
'-Dosgi.bundles.defaultStartLevel=4',
4771
'-Declipse.product=org.eclipse.jdt.ls.core.product',

lua/pkgm/downloaders/powershell.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local class = require('java-core.utils.class')
22
local log = require('java-core.utils.log2')
33
local err_util = require('java-core.utils.errors')
4+
local path = require('java-core.utils.path')
45

56
---@class java-core.PowerShell
67
---@field url string
@@ -21,7 +22,9 @@ function PowerShell:_init(opts)
2122

2223
if not opts.dest then
2324
local filename = vim.fs.basename(opts.url)
24-
self.dest = vim.fn.tempname() .. '-' .. filename
25+
local tmp_dir = vim.fn.tempname()
26+
vim.fn.mkdir(tmp_dir, 'p')
27+
self.dest = path.join(tmp_dir, filename)
2528
log.debug('Using temp destination:', self.dest)
2629
else
2730
self.dest = opts.dest

lua/pkgm/extractors/tar.lua

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ function Tar:_init(opts)
1717
self.dest = opts.dest
1818
end
1919

20+
---@private
21+
---Check if tar supports --force-local
22+
---@param tar_cmd string
23+
---@return boolean
24+
function Tar:tar_supports_force_local(tar_cmd)
25+
local ok, out = pcall(vim.fn.system, { tar_cmd, '--help' })
26+
if not ok then
27+
return false
28+
end
29+
return out:match('%-%-force%-local') ~= nil
30+
end
31+
2032
---Extract tar file using tar
2133
---@return boolean|nil # true on success, nil on failure
2234
---@return string|nil # Error message if failed
@@ -30,7 +42,13 @@ function Tar:extract()
3042
-- Windows: convert backslashes to forward slashes (tar accepts them)
3143
local source = self.source:gsub('\\', '/')
3244
local dest = self.dest:gsub('\\', '/')
33-
cmd = string.format('%s --no-same-owner --force-local -xf "%s" -C "%s"', tar_cmd, source, dest)
45+
cmd = string.format(
46+
'%s --no-same-owner %s -xf "%s" -C "%s"',
47+
tar_cmd,
48+
self:tar_supports_force_local(tar_cmd) and '--force-local' or '',
49+
source,
50+
dest
51+
)
3452
else
3553
-- Unix: use shellescape
3654
cmd = string.format(

tests/specs/lsp_spec.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local lsp_utils = dofile('tests/utils/lsp-utils.lua')
22
local assert = require('luassert')
3+
local system = require('java-core.utils.system')
34

45
describe('LSP Attach', function()
56
it('should attach when opening a Java buffer', function()
@@ -8,6 +9,9 @@ describe('LSP Attach', function()
89
local jdtls = lsp_utils.wait_for_lsp_attach('jdtls', 30000)
910
local spring = lsp_utils.wait_for_lsp_attach('spring-boot', 30000)
1011

12+
if system.get_os() == 'win' then
13+
vim.fn.readfile('C:/Users/runneradmin/AppData/Local/nvim-data/lsp.log')
14+
end
1115
assert.is_not_nil(jdtls, 'JDTLS should attach to Java buffer')
1216
assert.is_not_nil(spring, 'Spring Boot should attach to Java buffer')
1317
end)

0 commit comments

Comments
 (0)