dynamically resolve lldb server binary

This commit is contained in:
LordMZTE 2022-11-14 16:26:12 +01:00
parent aa91f80604
commit d82ddc4e95
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
3 changed files with 48 additions and 4 deletions

View file

@ -1,4 +1,6 @@
local map = vim.api.nvim_set_keymap
local mztenv = require "mzte_nv"
local dap = require "dap"
local dapui = require "dapui"
@ -6,9 +8,7 @@ dapui.setup {}
dap.adapters.lldb = {
type = "executable",
-- TODO: hardcoding the path here is total dog shit
-- I should implement a dap module in mzte-nv that resolves this.
command = "/usr/bin/lldb-vscode", -- included in lldb package
command = mztenv.utils.findInPath "lldb-vscode", -- included in lldb package
name = "lldb",
}

View file

@ -3,11 +3,12 @@ const ffi = @import("ffi.zig");
const ser = @import("ser.zig");
const c = ffi.c;
pub const version = "0.2.0";
pub const version = "0.3.0";
const modules = struct {
const cmp = @import("modules/cmp.zig");
const jdtls = @import("modules/jdtls.zig");
const utils = @import("modules/utils.zig");
};
export fn luaopen_mzte_nv(l_: ?*c.lua_State) c_int {
@ -16,6 +17,7 @@ export fn luaopen_mzte_nv(l_: ?*c.lua_State) c_int {
.onInit = ffi.luaFunc(lOnInit),
.cmp = modules.cmp,
.jdtls = modules.jdtls,
.utils = modules.utils,
});
return 1;
}

View file

@ -0,0 +1,42 @@
const std = @import("std");
const ser = @import("../ser.zig");
const ffi = @import("../ffi.zig");
const c = ffi.c;
pub fn luaPush(l: *c.lua_State) void {
ser.luaPushAny(l, .{
.findInPath = ffi.luaFunc(lFindInPath),
});
}
/// This is basically a reimplementation of `which`.
fn lFindInPath(l: *c.lua_State) !c_int {
const path = std.os.getenv("PATH") orelse return error.PathNotSet;
const bin = c.luaL_checklstring(l, 1, null);
var splits = std.mem.split(u8, path, ":");
while (splits.next()) |p| {
const trimmed = std.mem.trim(u8, p, " \n\r");
if (trimmed.len == 0)
continue;
const joined = try std.fs.path.joinZ(
std.heap.c_allocator,
&.{ trimmed, std.mem.span(bin) },
);
defer std.heap.c_allocator.free(joined);
_ = std.fs.cwd().statFile(joined) catch |e| {
if (e == error.FileNotFound)
continue;
return e;
};
c.lua_pushstring(l, joined.ptr);
return 1;
}
c.lua_pushnil(l);
return 1;
}