Skip to content

fix: update mason API usage for nvim-java compatibility #89

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lua/java-core/ls/servers/jdtls/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function M.get_config(opts)
local jdtls_config = path.join(jdtls_root, 'config')
local lombok_path = path.join(lombok_root, 'lombok.jar')
local equinox_launcher =
path.join(jdtls_root, 'plugins', 'org.eclipse.equinox.launcher.jar')
path.join(jdtls_root, 'plugins', 'org.eclipse.equinox.launcher.jar')
local plugin_paths = plugins.get_plugin_paths(opts.jdtls_plugins)
local base_config = config.get_config()

Expand Down Expand Up @@ -70,7 +70,7 @@ function M.get_config(opts)

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

base_config.cmd_env = {
Expand Down Expand Up @@ -108,9 +108,9 @@ function M.get_root_finder(root_markers)
local fallback_dir = vim.fn.getcwd()
log.debug(
"couldn't find root of "
.. file_name
.. ' using fallback dir '
.. fallback_dir
.. file_name
.. ' using fallback dir '
.. fallback_dir
)
return fallback_dir
end
Expand Down
16 changes: 10 additions & 6 deletions lua/java-core/utils/mason.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@ local M = {}
---@param pkg_name string
---@return string | nil
function M.get_pkg_path(pkg_name)
return mason_registry.get_package(pkg_name):get_install_path()
local mason_data_path = vim.fn.stdpath("data") .. "/mason/packages/" .. pkg_name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In prev you used $MASON variable but here get stdpath?

return mason_data_path
end

---Returns true if the package in installed in mason
---Returns true if the package is installed in mason
---@param pkg_name string
---@return boolean
function M.is_pkg_installed(pkg_name)
return mason_registry.get_package(pkg_name):is_installed()
local ok, pkg = pcall(mason_registry.get_package, pkg_name)
return ok and pkg:is_installed()
end

---Returns the shared artifact path for a given package
---@param pkg_name string name of the package to get the path of
---@return string # path to the shared artifact directory of the package
---@param pkg_name string
---@return string
function M.get_shared_path(pkg_name)
return vim.fn.glob('$MASON/share/' .. pkg_name)
local mason_share_path = vim.fn.stdpath("data") .. "/mason/share/" .. pkg_name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use $MASON env variable?

return mason_share_path
end

return M