Skip to content

Commit fef288b

Browse files
committed
fix: update mason API usage for nvim-java compatibility
1 parent 401bf76 commit fef288b

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function M.get_config(opts)
3131
local jdtls_config = path.join(jdtls_root, 'config')
3232
local lombok_path = path.join(lombok_root, 'lombok.jar')
3333
local equinox_launcher =
34-
path.join(jdtls_root, 'plugins', 'org.eclipse.equinox.launcher.jar')
34+
path.join(jdtls_root, 'plugins', 'org.eclipse.equinox.launcher.jar')
3535
local plugin_paths = plugins.get_plugin_paths(opts.jdtls_plugins)
3636
local base_config = config.get_config()
3737

@@ -70,7 +70,7 @@ function M.get_config(opts)
7070

7171
if jdk:is_installed() then
7272
local java_home =
73-
vim.fn.glob(path.join(jdk:get_install_path(), '/jdk-17*'))
73+
vim.fn.glob(vim.fn.expand('$MASON/packages/openjdk-17/jdk-17*'))
7474
local java_bin = path.join(java_home, '/bin')
7575

7676
base_config.cmd_env = {
@@ -108,9 +108,9 @@ function M.get_root_finder(root_markers)
108108
local fallback_dir = vim.fn.getcwd()
109109
log.debug(
110110
"couldn't find root of "
111-
.. file_name
112-
.. ' using fallback dir '
113-
.. fallback_dir
111+
.. file_name
112+
.. ' using fallback dir '
113+
.. fallback_dir
114114
)
115115
return fallback_dir
116116
end

lua/java-core/utils/mason.lua

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@ local M = {}
66
---@param pkg_name string
77
---@return string | nil
88
function M.get_pkg_path(pkg_name)
9-
return mason_registry.get_package(pkg_name):get_install_path()
9+
local mason_data_path = vim.fn.stdpath("data") .. "/mason/packages/" .. pkg_name
10+
return mason_data_path
1011
end
1112

12-
---Returns true if the package in installed in mason
13+
---Returns true if the package is installed in mason
1314
---@param pkg_name string
1415
---@return boolean
1516
function M.is_pkg_installed(pkg_name)
16-
return mason_registry.get_package(pkg_name):is_installed()
17+
local ok, pkg = pcall(mason_registry.get_package, pkg_name)
18+
return ok and pkg:is_installed()
1719
end
1820

1921
---Returns the shared artifact path for a given package
20-
---@param pkg_name string name of the package to get the path of
21-
---@return string # path to the shared artifact directory of the package
22+
---@param pkg_name string
23+
---@return string
2224
function M.get_shared_path(pkg_name)
23-
return vim.fn.glob('$MASON/share/' .. pkg_name)
25+
local mason_share_path = vim.fn.stdpath("data") .. "/mason/share/" .. pkg_name
26+
return mason_share_path
2427
end
2528

2629
return M
30+

0 commit comments

Comments
 (0)