Skip to content

Commit 7973891

Browse files
committed
fix: java-config not exists
1 parent fe450df commit 7973891

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

lua/aceforeverd/lsp/jdtls.lua

+19-6
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,33 @@ local function search_jdk_runtimes()
2121
local sdkman_java_candidates = '~/.sdkman/candidates/java/'
2222
local jdk_versions = { '8', '11', '17', '21', '22', '18' }
2323
for _, version in ipairs(jdk_versions) do
24-
local path = vim.fn.glob(sdkman_java_candidates .. version .. '.*', true, true)
25-
if #path > 0 then
26-
table.insert(runtimes, { name = 'JDK' .. version, path = path[1] })
24+
local paths = vim.fn.glob(sdkman_java_candidates .. version .. '.*', true, true)
25+
for _, jdk_path in ipairs(paths) do
26+
-- https://github.com/eclipse-jdtls/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
27+
-- name is NOT arbitrary, go link above and search 'enum ExecutionEnvironment'
28+
if version ~= '8' then
29+
table.insert(runtimes, { name = 'JavaSE-' .. version, path = jdk_path })
30+
else
31+
table.insert(runtimes, { name = 'JavaSE-1.8', path = jdk_path })
32+
end
2733
end
2834
end
2935

30-
local system_default = vim.fn.system({ 'java-config', '-O' })
31-
if vim.v.shell_error == 0 then
32-
table.insert(runtimes, { name = 'System Default', path = string.gsub(system_default, "%s+$", '') })
36+
if vim.fn.executable('java-config') == 1 then
37+
-- system default
38+
local system_default = vim.fn.system({ 'java-config', '-O' })
39+
if vim.v.shell_error == 0 and system_default ~= nil then
40+
-- TODO: extract jdk version
41+
table.insert(runtimes, { name = 'JavaSE-17', path = string.gsub(system_default, '%s+$', '') })
42+
end
3343
end
3444

3545
return runtimes
3646
end
3747

48+
-- TODO: setup java-debug & vscode-java-test & nvim-dap
49+
-- they can install via mason
50+
3851
function M.jdtls()
3952
local mason_registery = require('mason-registry')
4053
local server = mason_registery.get_package('jdtls')

lua/aceforeverd/lsp/metals.lua

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function M.metals()
2323
metals_config.settings = {
2424
showImplicitArguments = true,
2525
}
26+
-- TODO: add message to statusline via vim.g['metals_status']
2627
metals_config.init_options.statusBarProvider = 'on'
2728

2829
metals_config = vim.tbl_deep_extend('force', metals_config, require('aceforeverd.lsp.common').general_cfg)

0 commit comments

Comments
 (0)