fix: windows jdtls support
This commit is contained in:
parent
27b6726aea
commit
3391a6d60a
@ -2,25 +2,38 @@ function IsDirectoryExist(dirname)
|
|||||||
return os.rename(dirname, dirname) and true or false
|
return os.rename(dirname, dirname) and true or false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Path2Windows(path)
|
||||||
|
return (string.gsub(path, "/", "\\"))
|
||||||
|
end
|
||||||
|
|
||||||
local jdtls = require("jdtls")
|
local jdtls = require("jdtls")
|
||||||
local root_markers = { ".git", "mvnw", "gradlew", "pom.xml", "build.gradle" }
|
local root_markers = { ".git", "mvnw", "gradlew", "pom.xml", "build.gradle" }
|
||||||
local root_dir = require("jdtls.setup").find_root(root_markers)
|
local root_dir = require("jdtls.setup").find_root(root_markers)
|
||||||
if root_dir == "" then
|
if root_dir == "" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t")
|
local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t")
|
||||||
local home = os.getenv("HOME")
|
local home = os.getenv("HOME")
|
||||||
local jdtls_home = home .. "/.jdtls"
|
local jdtls_home = home .. "/.jdtls"
|
||||||
local plugins_home = jdtls_home .. "/plugins"
|
local plugins_home = jdtls_home .. "/plugins"
|
||||||
local workspace = jdtls_home .. "/workspace/" .. project_name
|
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
|
-- create when workspace not exist
|
||||||
if not IsDirectoryExist(workspace) then
|
if not IsDirectoryExist(workspace) then
|
||||||
os.execute("mkdir " .. workspace)
|
os.execute("mkdir " .. workspace)
|
||||||
end
|
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
|
if vim.loop.os_uname().sysname == "Windows" then
|
||||||
configuration = jdtls_home .. "\\config_win"
|
configuration = jdtls_home .. "\\config_win"
|
||||||
end
|
end
|
||||||
@ -44,6 +57,7 @@ local config = {
|
|||||||
"--add-opens",
|
"--add-opens",
|
||||||
"java.base/java.lang=ALL-UNNAMED",
|
"java.base/java.lang=ALL-UNNAMED",
|
||||||
"-javaagent:" .. jdtls_home .. "/bin/lombok.jar",
|
"-javaagent:" .. jdtls_home .. "/bin/lombok.jar",
|
||||||
|
"-Xbootclasspath/a:" .. jdtls_home .. "/bin/lombok.jar",
|
||||||
"-jar",
|
"-jar",
|
||||||
launcher,
|
launcher,
|
||||||
"-configuration",
|
"-configuration",
|
||||||
@ -113,7 +127,6 @@ local config = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
init_options = {
|
init_options = {
|
||||||
bundles = {},
|
bundles = {},
|
||||||
},
|
},
|
||||||
|
@ -8,13 +8,36 @@ function IsFileExist(filename)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function IsWindows()
|
||||||
|
local delimeter = package.config.sub(1, 1)
|
||||||
|
if delimeter == "/" then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function Path2Windows(path)
|
||||||
|
return (string.gsub(path, "/", "\\"))
|
||||||
|
end
|
||||||
|
|
||||||
function IsDirectoryExist(dirname)
|
function IsDirectoryExist(dirname)
|
||||||
return os.rename(dirname, dirname) and true or false
|
return os.rename(dirname, dirname) and true or false
|
||||||
end
|
end
|
||||||
|
|
||||||
local jdtlspath = os.getenv("HOME") .. "/.jdtls"
|
local homepage = os.getenv("HOME")
|
||||||
if vim.loop.os_uname().sysname == "Windows" then
|
if IsWindows() then
|
||||||
jdtlspath = os.getenv("HOME") .. "\\.jdtls"
|
homepage = os.getenv("USERPROFILE")
|
||||||
|
end
|
||||||
|
|
||||||
|
local jdtlspath = homepage .. "/.jdtls"
|
||||||
|
local jdtls_bin = jdtlspath .. "/bin/jdtls"
|
||||||
|
local lombok_jar = jdtlspath .. "/bin/lombok.jar"
|
||||||
|
local temp_download = os.getenv("TEMP")
|
||||||
|
|
||||||
|
if IsWindows() then
|
||||||
|
jdtlspath = Path2Windows(jdtlspath)
|
||||||
|
jdtls_bin = Path2Windows(jdtls_bin)
|
||||||
|
lombok_jar = Path2Windows(lombok_jar)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 创建目录
|
-- 创建目录
|
||||||
@ -23,29 +46,35 @@ if not IsFileExist(jdtlspath) then
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- 检测文件存在否
|
-- 检测文件存在否
|
||||||
if not IsDirectoryExist(jdtlspath .. "/bin/jdtls") then
|
if not IsDirectoryExist(jdtls_bin) then
|
||||||
print("download jdtls binary")
|
print("download jdtls binary")
|
||||||
local download_ret = os.execute(
|
local download_ret = os.execute(
|
||||||
"wget https://download.eclipse.org/jdtls/milestones/1.23.0/jdt-language-server-1.23.0-202304271346.tar.gz -P /tmp"
|
"curl --create-dirs -O --output-dir "
|
||||||
|
.. temp_download
|
||||||
|
.. " https://download.eclipse.org/jdtls/milestones/1.23.0/jdt-language-server-1.23.0-202304271346.tar.gz"
|
||||||
)
|
)
|
||||||
if download_ret ~= 0 then
|
if download_ret ~= 0 then
|
||||||
vim.notify("download jdtls binary failed")
|
vim.notify("download jdtls binary failed")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
vim.notify("download jdtls success")
|
vim.notify("download jdtls success")
|
||||||
local tar_ret = os.execute("tar xvzf /tmp/jdt-language-server-1.23.0-202304271346.tar.gz -C " .. jdtlspath)
|
local tar_ret =
|
||||||
|
os.execute("tar xvzf " .. temp_download .. "/jdt-language-server-1.23.0-202304271346.tar.gz -C " .. jdtlspath)
|
||||||
if tar_ret ~= 0 then
|
if tar_ret ~= 0 then
|
||||||
vim.notify("extract jdtls file failed")
|
vim.notify("extract jdtls file failed")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
vim.notify("install jdtls success")
|
||||||
end
|
end
|
||||||
|
|
||||||
local lombok_path = jdtlspath .. "/bin/lombok.jar"
|
|
||||||
-- 下载lombok
|
-- 下载lombok
|
||||||
if not IsFileExist(jdtlspath .. "/bin/lombok.jar") then
|
if not IsFileExist(lombok_jar) then
|
||||||
vim.notify("download lombok.jar")
|
vim.notify("download lombok.jar")
|
||||||
local download_ret = os.execute("wget https://projectlombok.org/downloads/lombok.jar -P " .. jdtlspath .. "/bin")
|
local download_ret = os.execute(
|
||||||
|
"curl --create-dirs -O --output-dir " .. jdtlspath .. "/bin https://projectlombok.org/downloads/lombok.jar"
|
||||||
|
)
|
||||||
if download_ret ~= 0 then
|
if download_ret ~= 0 then
|
||||||
vim.notify("download lombok failed")
|
vim.notify("download lombok failed")
|
||||||
end
|
end
|
||||||
|
vim.notify("download lombok.jar success")
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user