From 8f9b9acf485c7705dbffb9b6ca76e93196d00b10 Mon Sep 17 00:00:00 2001 From: s1n7ax Date: Wed, 27 Dec 2023 21:08:45 +0530 Subject: [PATCH] fix: trying to load jar that's not a jdtls extension --- lua/java-core/ls/servers/jdtls/plugins.lua | 47 ++++++++++++-------- lua/java-core/utils/file.lua | 50 ++++------------------ 2 files changed, 38 insertions(+), 59 deletions(-) diff --git a/lua/java-core/ls/servers/jdtls/plugins.lua b/lua/java-core/ls/servers/jdtls/plugins.lua index b5acc1d..292b8c1 100644 --- a/lua/java-core/ls/servers/jdtls/plugins.lua +++ b/lua/java-core/ls/servers/jdtls/plugins.lua @@ -1,32 +1,43 @@ local mason = require('java-core.utils.mason') -local path = require('java-core.utils.path') local file = require('java-core.utils.file') local List = require('java-core.utils.list') local M = {} -local plugin_to_jar_path_map = { - ['java-test'] = '*.jar', - ['java-debug-adapter'] = '*.jar', +local plug_jar_map = { + ['java-test'] = { + 'junit-jupiter-api_*.jar', + 'junit-jupiter-engine_*.jar', + 'junit-jupiter-migrationsupport_*.jar', + 'junit-jupiter-params_*.jar', + 'junit-platform-commons_*.jar', + 'junit-platform-engine_*.jar', + 'junit-platform-launcher_*.jar', + 'junit-platform-runner_*.jar', + 'junit-platform-suite-api_*.jar', + 'junit-platform-suite-commons_*.jar', + 'junit-platform-suite-engine_*.jar', + 'junit-vintage-engine_*.jar', + 'org.apiguardian.api_*.jar', + 'org.eclipse.jdt.junit4.runtime_*.jar', + 'org.eclipse.jdt.junit5.runtime_*.jar', + 'org.opentest4j_*.jar', + 'com.microsoft.java.test.plugin-*.jar', + }, + ['java-debug-adapter'] = { '*.jar' }, } ---Returns a list of .jar file paths for given list of jdtls plugins ----@param plugins string[] +---@param plugin_names string[] ---@return string[] # list of .jar file paths -function M.get_plugin_paths(plugins) - local plugin_paths = List:new() - - for _, plugin in ipairs(plugins) do - local relative_path = plugin_to_jar_path_map[plugin] - local plugin_shared_path = mason.get_shared_path(plugin) - local full_path = path.join(plugin_shared_path, relative_path) - local resolved_paths = file.get_file_list(full_path) - - plugin_paths:push(resolved_paths) - end - - return plugin_paths:flatten() +function M.get_plugin_paths(plugin_names) + return List:new(plugin_names) + :map(function(plugin_name) + local root = mason.get_shared_path(plugin_name) + return file.resolve_paths(root, plug_jar_map[plugin_name]) + end) + :flatten() end return M diff --git a/lua/java-core/utils/file.lua b/lua/java-core/utils/file.lua index f4e9f3a..c439548 100644 --- a/lua/java-core/utils/file.lua +++ b/lua/java-core/utils/file.lua @@ -1,47 +1,15 @@ -local M = {} - ----Return true if the given path is a directory ----@param path string ----@return boolean -function M.is_dir(path) - return vim.fn.isdirectory(path) == 1 -end +local path = require('java-core.utils.path') ----Returns true if the given path is a file ----@param path string ----@return boolean -function M.is_file(path) - return vim.fn.filereadable(path) == 1 -end - ----Returns true if the given path is an executable ----@param path string ----@return boolean -function M.is_exec(path) - return vim.fn.executable(path) == 1 -end +local List = require('java-core.utils.list') ----Returns a list of files from a path with wildcards ----@param path string path with the wildcards ----@return string[] -function M.get_file_list(path) - return vim.fn.glob(path, true, true) -end - ----Creates a directory in the given path ----@param path string ----@param opts JavaDirCreateFlags -function M.mkdir(path, opts) - local flags = '' - - if opts.create_intermediate then - flags = flags .. 'p' - end +local M = {} - vim.fn.mkdir(path, flags) +function M.resolve_paths(root, paths) + return List:new(paths) + :map(function(path_pattern) + return vim.fn.glob(path.join(root, path_pattern), true, true) + end) + :flatten() end return M - ----@class JavaDirCreateFlags ----@field create_intermediate boolean whether the intermediate directories should be created in the process