@@ -110,10 +110,12 @@ local function get_jdtls_path()
110110 return env .JDTLS_HOME or vscode .find_one (" /redhat.java-*/server" )
111111end
112112
113+ local mason , _ = pcall (require , " mason-registry" )
114+
113115local function jdtls_launcher ()
114116 local jdtls_path = get_jdtls_path ()
115117 if jdtls_path then
116- elseif require (" mason-registry" ).has_package (" jdtls" ) then
118+ elseif mason and require (" mason-registry" ).has_package (" jdtls" ) then
117119 jdtls_path = require (" mason-registry" ).get_package (" jdtls" ):get_install_path ()
118120 end
119121 local jdtls_config = nil
@@ -163,14 +165,16 @@ end
163165local bundles = {}
164166-- This bundles definition is the same as in the previous section (java-debug installation)
165167
168+
166169local vscode_java_debug_path = (function ()
167170 local p = vscode .find_one (" /vscjava.vscode-java-debug-*/server" )
168171 if p then
169172 return p
170173 end
171- if require (" mason-registry" ).has_package (" java-debug-adapter" ) then
174+ if mason and require (" mason-registry" ).has_package (" java-debug-adapter" ) then
172175 return require (" mason-registry" ).get_package (" java-debug-adapter" ):get_install_path () .. " /extension/server"
173176 end
177+ return vim .env [" JDTLS_JAVA_DEBUG_PATH" ]
174178end )()
175179if vscode_java_debug_path then
176180 vim .list_extend (
@@ -186,31 +190,44 @@ local vscode_java_test_path = (function()
186190 if p then
187191 return p
188192 end
189- if require (" mason-registry" ).has_package (" java-test" ) then
193+ if mason and require (" mason-registry" ).has_package (" java-test" ) then
190194 return require (" mason-registry" ).get_package (" java-test" ):get_install_path () .. " /extension/server"
191195 end
196+ return vim .env [" JDTLS_JAVA_TEST_PATH" ]
192197end )()
193198if vscode_java_test_path then
194199 for _ , bundle in ipairs (vim .split (vim .fn .glob (vscode_java_test_path .. " /*.jar" ), " \n " )) do
195200 if
196- not vim .endswith (bundle , " com.microsoft.java.test.runner-jar-with-dependencies.jar" )
197- and not vim .endswith (bundle , " jacocoagent.jar" )
201+ not vim .endswith (bundle , " com.microsoft.java.test.runner-jar-with-dependencies.jar" )
202+ and not vim .endswith (bundle , " jacocoagent.jar" )
198203 then
199204 table.insert (bundles , bundle )
200205 end
201206 end
202207end
203208
204209-- /opt/software/lsp/java/vscode-java-decompiler/server/
205- local java_decoompiler_path = vscode .find_one (" /dgileadi.java-decompiler-*/server" )
210+ local java_decoompiler_path = (function ()
211+ local p = vscode .find_one (" /dgileadi.java-decompiler-*/server" )
212+ if p then
213+ return p
214+ end
215+ return vim .env [" JDTLS_JAVA_DECOMPILER_PATH" ]
216+ end )()
206217if java_decoompiler_path then
207218 vim .list_extend (bundles , vim .split (vim .fn .glob (java_decoompiler_path .. " /*.jar" ), " \n " ))
208219end
209220
210221-- /opt/software/lsp/java/vscode-java-dependency/jdtls.ext/
211222-- vim.list_extend(bundles, vim.split(vim.fn.glob("/opt/software/lsp/java/vscode-java-dependency/jdtls.ext/com.microsoft.jdtls.ext.core/target/com.microsoft.jdtls.ext.core-*.jar"), "\n"));
212223-- /opt/software/lsp/java/vscode-java-dependency/server/
213- local java_dependency_path = vscode .find_one (" /vscjava.vscode-java-dependency-*/server" )
224+ local java_dependency_path = (function ()
225+ local p = vscode .find_one (" /vscjava.vscode-java-dependency-*/server" )
226+ if p then
227+ return p
228+ end
229+ return vim .env [" JDTLS_JAVA_DEPENDENCY_PATH" ]
230+ end )()
214231if java_dependency_path then
215232 vim .list_extend (bundles , vim .split (vim .fn .glob (java_dependency_path .. " /*.jar" ), " \n " ))
216233end
@@ -424,15 +441,15 @@ local function test_with_profile(test_fn)
424441 },
425442 after_test = function ()
426443 local result = vim
427- .system ({
428- " java" ,
429- " -jar" ,
430- get_async_profiler_cov (),
431- " jfr2flame" ,
432- utils .tmpdir_file (" profile.jfr" ),
433- utils .tmpdir_file (" profile.html" ),
434- })
435- :wait ()
444+ .system ({
445+ " java" ,
446+ " -jar" ,
447+ get_async_profiler_cov (),
448+ " jfr2flame" ,
449+ utils .tmpdir_file (" profile.jfr" ),
450+ utils .tmpdir_file (" profile.html" ),
451+ })
452+ :wait ()
436453 if result .code == 0 then
437454 utils .open_fn (utils .tmpdir_file (" profile.html" ))
438455 end
0 commit comments