Skip to content

Commit 9726b4f

Browse files
committed
支持配制本地编译 LSP
1 parent edd42b5 commit 9726b4f

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

lua/kide/lsp/jdtls.lua

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,12 @@ local function get_jdtls_path()
110110
return env.JDTLS_HOME or vscode.find_one("/redhat.java-*/server")
111111
end
112112

113+
local mason, _ = pcall(require, "mason-registry")
114+
113115
local 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
163165
local bundles = {}
164166
-- This bundles definition is the same as in the previous section (java-debug installation)
165167

168+
166169
local 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"]
174178
end)()
175179
if 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"]
192197
end)()
193198
if 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
202207
end
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)()
206217
if java_decoompiler_path then
207218
vim.list_extend(bundles, vim.split(vim.fn.glob(java_decoompiler_path .. "/*.jar"), "\n"))
208219
end
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)()
214231
if java_dependency_path then
215232
vim.list_extend(bundles, vim.split(vim.fn.glob(java_dependency_path .. "/*.jar"), "\n"))
216233
end
@@ -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

lua/kide/tools/vscode.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ M.find_one = function(extension_path)
1919
end
2020
end
2121

22+
local mason, _ = pcall(require, "mason-registry")
2223
M.get_lombok_jar = function()
2324
local lombok_jar = nil
2425
if env.LOMBOK_ENABLE == "Y" then
2526
lombok_jar = M.find_one("/redhat.java-*/lombok/lombok-*.jar")
26-
if lombok_jar == nil and require("mason-registry").has_package("jdtls") then
27+
if lombok_jar == nil and mason and require("mason-registry").has_package("jdtls") then
2728
lombok_jar = require("mason-registry").get_package("jdtls"):get_install_path() .. "/lombok.jar"
2829
end
2930
end

0 commit comments

Comments
 (0)