Skip to content

Commit d07e02c

Browse files
authored
refactor: get plugin artifacts from mason shared directory (#13)
1 parent 960425f commit d07e02c

File tree

6 files changed

+22
-7
lines changed

6 files changed

+22
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
vendor/plenary.nvim
2+
.test_plugins

lua/java/server.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ local M = {}
1515

1616
---@alias JDTLSPluginPaths JDTLSPluginPathRecord[]
1717
M.plugins = {
18-
{ name = 'java-test', path = '/server/*.jar' },
19-
{ name = 'java-debug-adapter', path = '/extension/server/*.jar' },
18+
{ name = 'java-test', path = '/*.jar' },
19+
{ name = 'java-debug-adapter', path = '/*.jar' },
2020
}
2121

2222
---Returns a configuration for jdtls that you can pass into the setup of nvim-lspconfig

lua/java/utils/mason.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1+
local mason_registry = require('mason-registry')
2+
13
local M = {}
24

35
---Returns the path to the package in mason packages
46
---@param pkg_name string
57
---@return string | nil
68
function M.get_pkg_path(pkg_name)
7-
return require('mason-registry').get_package(pkg_name):get_install_path()
9+
return mason_registry.get_package(pkg_name):get_install_path()
810
end
911

1012
---Returns true if the package in installed in mason
1113
---@param pkg_name string
1214
---@return boolean
1315
function M.is_pkg_installed(pkg_name)
14-
return require('mason-registry').get_package(pkg_name):is_installed()
16+
return mason_registry.get_package(pkg_name):is_installed()
17+
end
18+
19+
---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
22+
function M.get_shared_path(pkg_name)
23+
return vim.fn.glob('$MASON/share/' .. pkg_name)
1524
end
1625

1726
return M

lua/java/utils/plugin.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function M.get_plugin_jars(pkg_name, path_to_jars)
1313
return {}
1414
end
1515

16-
local path = mason.get_pkg_path(pkg_name)
16+
local path = mason.get_shared_path(pkg_name)
1717

1818
log.fmt_info('looking for %s plugin files at %s', pkg_name, path)
1919

tests/prepare_config.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ end
1313

1414
vim.opt.rtp:prepend(lazypath)
1515

16-
local temp_path = '/tmp/nvim-java-test-plugins'
16+
local temp_path = './.test_plugins'
1717

1818
require('lazy').setup({
1919
{
@@ -24,6 +24,10 @@ require('lazy').setup({
2424
'nvim-lua/plenary.nvim',
2525
lazy = false,
2626
},
27+
{
28+
'williamboman/mason.nvim',
29+
lazy = false,
30+
},
2731
}, {
2832
root = temp_path,
2933
lockfile = temp_path .. '/lazy-lock.json',

tests/test_config.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
local temp_path = '/tmp/nvim-java-test-plugins'
1+
local temp_path = './.test_plugins'
22

33
vim.opt.rtp:append(temp_path .. '/plenary.nvim')
44
vim.opt.rtp:append(temp_path .. '/nvim-lspconfig')
5+
vim.opt.rtp:append(temp_path .. '/mason.nvim')

0 commit comments

Comments
 (0)