fix: windows jdtls support
This commit is contained in:
@@ -2,25 +2,38 @@ function IsDirectoryExist(dirname)
|
||||
return os.rename(dirname, dirname) and true or false
|
||||
end
|
||||
|
||||
function Path2Windows(path)
|
||||
return (string.gsub(path, "/", "\\"))
|
||||
end
|
||||
|
||||
local jdtls = require("jdtls")
|
||||
local root_markers = { ".git", "mvnw", "gradlew", "pom.xml", "build.gradle" }
|
||||
local root_dir = require("jdtls.setup").find_root(root_markers)
|
||||
if root_dir == "" then
|
||||
return
|
||||
end
|
||||
|
||||
local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t")
|
||||
local home = os.getenv("HOME")
|
||||
local jdtls_home = home .. "/.jdtls"
|
||||
local plugins_home = jdtls_home .. "/plugins"
|
||||
local workspace = jdtls_home .. "/workspace/" .. project_name
|
||||
local launcher = plugins_home .. "/org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar"
|
||||
local configuration = jdtls_home .. "/config_linux"
|
||||
|
||||
if vim.loop.os_uname().sysname == "Windows" then
|
||||
jdtls_home = Path2Windows(jdtls_home)
|
||||
plugins_home = Path2Windows(plugins_home)
|
||||
workspace = Path2Windows(workspace)
|
||||
launcher = Path2Windows(launcher)
|
||||
configuration = jdtls_home .. "\\config_win"
|
||||
end
|
||||
|
||||
-- create when workspace not exist
|
||||
if not IsDirectoryExist(workspace) then
|
||||
os.execute("mkdir " .. workspace)
|
||||
end
|
||||
|
||||
local launcher = plugins_home .. "/org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar"
|
||||
local configuration = jdtls_home .. "/config_linux"
|
||||
if vim.loop.os_uname().sysname == "Windows" then
|
||||
configuration = jdtls_home .. "\\config_win"
|
||||
end
|
||||
@@ -44,6 +57,7 @@ local config = {
|
||||
"--add-opens",
|
||||
"java.base/java.lang=ALL-UNNAMED",
|
||||
"-javaagent:" .. jdtls_home .. "/bin/lombok.jar",
|
||||
"-Xbootclasspath/a:" .. jdtls_home .. "/bin/lombok.jar",
|
||||
"-jar",
|
||||
launcher,
|
||||
"-configuration",
|
||||
@@ -113,7 +127,6 @@ local config = {
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
init_options = {
|
||||
bundles = {},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user