11local List = require (' java-core.utils.list' )
22local path = require (' java-core.utils.path' )
33local Manager = require (' pkgm.manager' )
4- local conf = require (' java.config' )
54local system = require (' java-core.utils.system' )
65local log = require (' java-core.utils.log2' )
76local err = require (' java-core.utils.errors' )
@@ -10,50 +9,50 @@ local lsp_utils = require('java-core.utils.lsp')
109
1110local M = {}
1211
13- local jdtls_root = Manager :get_install_dir (' jdtls' , conf .jdtls .version )
14-
1512--- Returns a function that returns the command to start jdtls
16- --- @param opts { use_lombok : boolean }
17- function M .get_cmd (opts )
13+ --- @param config java.Config
14+ function M .get_cmd (config )
1815 --- @param dispatchers ? vim.lsp.rpc.Dispatchers
19- --- @param config vim.lsp.ClientConfig
20- return function (dispatchers , config )
21- local cmd = M .get_jvm_args (opts ):concat (M .get_jar_args ())
16+ --- @param lsp_config vim.lsp.ClientConfig
17+ return function (dispatchers , lsp_config )
18+ local cmd = M .get_jvm_args (config ):concat (M .get_jar_args (config ))
2219
2320 -- NOTE: eventhough we are setting the PATH env var, due to a bug, it's not
2421 -- working on Windows. So just lanching 'java' will result in executing the
2522 -- system java. So as a workaround, we use the absolute path to java instead
2623 -- So following check is not needed when we have auto_install set to true
2724 -- @see https://github.com/neovim/neovim/issues/36818
28- if not conf .jdk .auto_install then
29- M .validate_java_version (config .cmd_env )
25+ if not config .jdk .auto_install then
26+ M .validate_java_version (config , lsp_config .cmd_env )
3027 end
3128
3229 log .debug (' Starting jdtls with cmd' , cmd )
3330
3431 local result = vim .lsp .rpc .start (cmd , dispatchers , {
35- cwd = config .cmd_cwd ,
36- env = config .cmd_env ,
37- detached = config .detached ,
32+ cwd = lsp_config .cmd_cwd ,
33+ env = lsp_config .cmd_env ,
34+ detached = lsp_config .detached ,
3835 })
3936
4037 return result
4138 end
4239end
4340
4441--- @private
45- --- @param opts { use_lombok : boolean }
42+ --- @param config java.Config
4643--- @return java-core.List
47- function M .get_jvm_args (opts )
44+ function M .get_jvm_args (config )
45+ local use_lombok = config .lombok .enable
46+ local jdtls_root = Manager :get_install_dir (' jdtls' , config .jdtls .version )
4847 local jdtls_config = path .join (jdtls_root , system .get_config_suffix ())
4948
5049 local java_exe = ' java'
5150
5251 -- NOTE: eventhough we are setting the PATH env var, due to a bug, it's not
5352 -- working on Windows. So we are using the absolute path to java instead
5453 -- @see https://github.com/neovim/neovim/issues/36818
55- if conf .jdk .auto_install then
56- local jdk_root = Manager :get_install_dir (' openjdk' , conf .jdk .version )
54+ if config .jdk .auto_install then
55+ local jdk_root = Manager :get_install_dir (' openjdk' , config .jdk .version )
5756 local java_home
5857 if system .get_os () == ' mac' then
5958 java_home = vim .fn .glob (path .join (jdk_root , ' jdk-*' , ' Contents' , ' Home' ))
@@ -84,8 +83,8 @@ function M.get_jvm_args(opts)
8483 })
8584
8685 -- Adding lombok
87- if opts . use_lombok then
88- local lombok_root = Manager :get_install_dir (' lombok' , conf .lombok .version )
86+ if use_lombok then
87+ local lombok_root = Manager :get_install_dir (' lombok' , config .lombok .version )
8988 local lombok_path = vim .fn .glob (path .join (lombok_root , ' lombok*.jar' ))
9089 jvm_args :push (' -javaagent:' .. lombok_path )
9190 end
@@ -94,9 +93,11 @@ function M.get_jvm_args(opts)
9493end
9594
9695--- @private
96+ --- @param config java.Config
9797--- @param cwd ? string
9898--- @return java-core.List
99- function M .get_jar_args (cwd )
99+ function M .get_jar_args (config , cwd )
100+ local jdtls_root = Manager :get_install_dir (' jdtls' , config .jdtls .version )
100101 cwd = cwd or vim .fn .getcwd ()
101102
102103 local launcher_reg = path .join (jdtls_root , ' plugins' , ' org.eclipse.equinox.launcher_*.jar' )
@@ -121,15 +122,16 @@ function M.get_jar_args(cwd)
121122end
122123
123124--- @private
125+ --- @param config java.Config
124126--- @param env table
125- function M .validate_java_version (env )
127+ function M .validate_java_version (config , env )
126128 local curr_ver = M .get_java_major_version (env )
127- local exp_ver = java_version_map [conf .jdtls .version ]
129+ local exp_ver = java_version_map [config .jdtls .version ]
128130
129131 if not (curr_ver >= exp_ver .to and curr_ver <= exp_ver .from ) then
130132 local msg = string.format (
131133 ' Java version mismatch: JDTLS %s requires Java %d <= java >= %d, but found Java %d' ,
132- conf .jdtls .version ,
134+ config .jdtls .version ,
133135 exp_ver .from ,
134136 exp_ver .to ,
135137 curr_ver
0 commit comments