feat: query project files via git (part 1)

This commit is contained in:
CJ van den Berg 2025-04-21 21:43:29 +02:00
parent 4cb84e25b3
commit f76085325a
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
5 changed files with 75 additions and 21 deletions

View file

@ -7,6 +7,7 @@ const dizzy = @import("dizzy");
const Buffer = @import("Buffer");
const fuzzig = @import("fuzzig");
const tracy = @import("tracy");
const git = @import("git");
const builtin = @import("builtin");
const LSP = @import("LSP.zig");
@ -24,6 +25,9 @@ persistent: bool = false,
logger_lsp: log.Logger,
logger_git: log.Logger,
workspace: ?[]const u8 = null,
branch: ?[]const u8 = null,
const Self = @This();
const OutOfMemoryError = error{OutOfMemory};
@ -67,6 +71,8 @@ pub fn init(allocator: std.mem.Allocator, name: []const u8) OutOfMemoryError!Sel
}
pub fn deinit(self: *Self) void {
if (self.workspace) |p| self.allocator.free(p);
if (self.branch) |p| self.allocator.free(p);
var i_ = self.file_language_server.iterator();
while (i_.next()) |p| {
self.allocator.free(p.key_ptr.*);
@ -1850,3 +1856,26 @@ pub fn get_line(allocator: std.mem.Allocator, buf: []const u8) ![]const u8 {
}
return allocator.dupe(u8, buf);
}
pub fn query_git(self: *Self) void {
git.workspace_path(@intFromPtr(self)) catch {};
git.current_branch(@intFromPtr(self)) catch {};
}
pub fn process_git(self: *Self, m: tp.message) !void {
var value: []const u8 = undefined;
if (try m.match(.{ tp.any, tp.any, "workspace_path", tp.null_ })) {
// no git workspace
} else if (try m.match(.{ tp.any, tp.any, "workspace_path", tp.extract(&value) })) {
if (self.workspace) |p| self.allocator.free(p);
self.workspace = try self.allocator.dupe(u8, value);
git.workspace_files(@intFromPtr(self)) catch {};
} else if (try m.match(.{ tp.any, tp.any, "current_branch", tp.extract(&value) })) {
if (self.branch) |p| self.allocator.free(p);
self.branch = try self.allocator.dupe(u8, value);
} else if (try m.match(.{ tp.any, tp.any, "workspace_files", tp.extract(&value) })) {
// TODO
} else {
self.logger_git.err("git", tp.unexpected(m));
}
}