fix jdtls workspace dirs

This commit is contained in:
LordMZTE 2022-10-24 21:50:24 +02:00
parent a2b3afccac
commit 9b6dbe42db
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
2 changed files with 32 additions and 5 deletions

View file

@ -1,15 +1,16 @@
local caps = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())
local mztenv = require "mzte_nv"
local mztenv = require("mzte_nv").jdtls
local bundle_info = mztenv.jdtls.getBundleInfo()
local bundle_info = mztenv.getBundleInfo()
local dirs = mztenv.getDirs()
require("jdtls").start_or_attach {
cmd = {
"jdtls",
"-configuration",
vim.loop.os_homedir() .. "/.cache/jdtls/config",
dirs.config,
"-data",
vim.loop.os_homedir() .. "/.cache/jdtls/workspace",
dirs.workspace,
},
capabilities = caps,
@ -24,7 +25,7 @@ require("jdtls").start_or_attach {
settings = {
java = {
configuration = {
runtimes = mztenv.jdtls.findRuntimes(),
runtimes = mztenv.findRuntimes(),
},
contentProvider = bundle_info.content_provider,
},

View file

@ -9,6 +9,7 @@ pub fn luaPush(l: *c.lua_State) void {
ser.luaPushAny(l, .{
.findRuntimes = ffi.luaFunc(lFindRuntimes),
.getBundleInfo = ffi.luaFunc(lGetBundleInfo),
.getDirs = ffi.luaFunc(lGetDirs),
});
}
@ -134,3 +135,28 @@ fn lGetBundleInfo(l: *c.lua_State) !c_int {
return 1;
}
fn lGetDirs(l: *c.lua_State) !c_int {
const home = std.os.getenv("HOME") orelse return error.HomeNotSet;
var cwd_buf: [256]u8 = undefined;
const cwd_basename = std.fs.path.basename(try std.os.getcwd(&cwd_buf));
const config_path = try std.fs.path.joinZ(
std.heap.c_allocator,
&.{ home, ".cache", "jdtls", "config" },
);
defer std.heap.c_allocator.free(config_path);
const workspace_path = try std.fs.path.joinZ(
std.heap.c_allocator,
&.{ home, ".cache", "jdtls", "workspace", cwd_basename },
);
defer std.heap.c_allocator.free(workspace_path);
ser.luaPushAny(l, .{
.config = config_path,
.workspace = workspace_path,
});
return 1;
}