Skip to content

Commit

Permalink
fix: java-config not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
aceforeverd committed Nov 24, 2023
1 parent fe450df commit 7973891
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
25 changes: 19 additions & 6 deletions lua/aceforeverd/lsp/jdtls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,33 @@ local function search_jdk_runtimes()
local sdkman_java_candidates = '~/.sdkman/candidates/java/'
local jdk_versions = { '8', '11', '17', '21', '22', '18' }
for _, version in ipairs(jdk_versions) do
local path = vim.fn.glob(sdkman_java_candidates .. version .. '.*', true, true)
if #path > 0 then
table.insert(runtimes, { name = 'JDK' .. version, path = path[1] })
local paths = vim.fn.glob(sdkman_java_candidates .. version .. '.*', true, true)
for _, jdk_path in ipairs(paths) do
-- https://github.com/eclipse-jdtls/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
-- name is NOT arbitrary, go link above and search 'enum ExecutionEnvironment'
if version ~= '8' then
table.insert(runtimes, { name = 'JavaSE-' .. version, path = jdk_path })
else
table.insert(runtimes, { name = 'JavaSE-1.8', path = jdk_path })
end
end
end

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

return runtimes
end

-- TODO: setup java-debug & vscode-java-test & nvim-dap
-- they can install via mason

function M.jdtls()
local mason_registery = require('mason-registry')
local server = mason_registery.get_package('jdtls')
Expand Down
1 change: 1 addition & 0 deletions lua/aceforeverd/lsp/metals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function M.metals()
metals_config.settings = {
showImplicitArguments = true,
}
-- TODO: add message to statusline via vim.g['metals_status']
metals_config.init_options.statusBarProvider = 'on'

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

0 comments on commit 7973891

Please sign in to comment.