Skip to content

Commit baf5e5b

Browse files
committed
refactor: handle plugin paths based on config
1 parent 86c427e commit baf5e5b

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

lua/java/server.lua

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ local workspace = require('java.workspace')
99

1010
local M = {}
1111

12+
---@class JDTLSPluginPathRecord
13+
---@field name string
14+
---@field path string
15+
16+
---@alias JDTLSPluginPaths JDTLSPluginPathRecord[]
17+
M.plugins = {
18+
{ name = 'java-test', path = '/server/*.jar' },
19+
{ name = 'java-debug-adapter', path = '/extension/server/*.jar' },
20+
}
21+
1222
---Returns a configuration for jdtls that you can pass into the setup of nvim-lspconfig
1323
--
1424
---@class JavaGetConfigOptions
@@ -22,7 +32,7 @@ function M.get_config(opts)
2232

2333
local jdtls_path = mason.get_pkg_path('jdtls')
2434
local curr_os = system.get_os()
25-
local plugins = plugin.get_plugins({ 'java-test', 'java-debug-adapter' })
35+
local plugins = plugin.get_plugins(M.plugins)
2636
local lombok_path = jdtls_path .. '/lombok.jar'
2737

2838
local cmd = {

lua/java/utils/plugin.lua

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local log = require('java.utils.log')
12
local file = require('java.utils.file')
23
local mason = require('java.utils.mason')
34

@@ -6,23 +7,30 @@ local M = {}
67
---Returns a list of jar files of given plugin
78
---@param pkg_name string name of the mason package name
89
---@return string[]
9-
function M.get_plugin_jars(pkg_name)
10+
function M.get_plugin_jars(pkg_name, path_to_jars)
1011
if not mason.is_pkg_installed(pkg_name) then
12+
log.fmt_debug('plugin %s is not installed', pkg_name)
1113
return {}
1214
end
1315

1416
local path = mason.get_pkg_path(pkg_name)
1517

16-
return file.get_file_list(path .. '/extension/server/*.jar')
18+
log.fmt_info('looking for %s plugin files at %s', pkg_name, path)
19+
20+
local files = file.get_file_list(path .. path_to_jars)
21+
22+
log.fmt_debug('found %d files for %s plugin ', #files, pkg_name)
23+
return files
1724
end
1825

1926
---Returns a list of jar files of all the plugins
27+
---@param plugin_list JDTLSPluginPaths
2028
---@return string[]
2129
function M.get_plugins(plugin_list)
2230
local plugins = {}
2331

2432
for _, plugin in ipairs(plugin_list) do
25-
vim.list_extend(plugins, M.get_plugin_jars(plugin))
33+
vim.list_extend(plugins, M.get_plugin_jars(plugin.name, plugin.path))
2634
end
2735

2836
return plugins

0 commit comments

Comments
 (0)