feat: store lsp symbols in mainview

This commit is contained in:
Igor Támara 2025-11-13 13:17:25 -05:00 committed by CJ van den Berg
parent 5f49e181ee
commit cc4ef5da2c
2 changed files with 86 additions and 0 deletions

View file

@ -248,6 +248,13 @@ pub fn completion(file_path: []const u8, row: usize, col: usize) (ProjectManager
return send(.{ "completion", project, file_path, row, col });
}
pub fn symbols(file_path: []const u8) (ProjectManagerError || ProjectError)!void {
const project = tp.env.get().str("project");
if (project.len == 0)
return error.NoProject;
return send(.{ "symbols", project, file_path });
}
pub fn rename_symbol(file_path: []const u8, row: usize, col: usize) (ProjectManagerError || ProjectError)!void {
const project = tp.env.get().str("project");
if (project.len == 0)
@ -441,6 +448,9 @@ const Process = struct {
self.references(from, project_directory, path, row, col) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed;
} else if (try cbor.match(m.buf, .{ "highlight_references", tp.extract(&project_directory), tp.extract(&path), tp.extract(&row), tp.extract(&col) })) {
self.highlight_references(from, project_directory, path, row, col) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed;
} else if (try cbor.match(m.buf, .{ "symbols", tp.extract(&project_directory), tp.extract(&path) })) {
self.logger.print("received to continue symbols", .{});
self.symbols(from, project_directory, path) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed;
} else if (try cbor.match(m.buf, .{ "completion", tp.extract(&project_directory), tp.extract(&path), tp.extract(&row), tp.extract(&col) })) {
self.completion(from, project_directory, path, row, col) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed;
} else if (try cbor.match(m.buf, .{ "rename_symbol", tp.extract(&project_directory), tp.extract(&path), tp.extract(&row), tp.extract(&col) })) {
@ -677,6 +687,13 @@ const Process = struct {
return project.highlight_references(from, file_path, row, col);
}
fn symbols(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8) (ProjectError || Project.InvalidMessageError || Project.LspOrClientError || cbor.Error)!void {
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".symbols" });
defer frame.deinit();
const project = self.projects.get(project_directory) orelse return error.NoProject;
return project.symbols(from, file_path);
}
fn completion(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8, row: usize, col: usize) (ProjectError || Project.InvalidMessageError || Project.LspOrClientError || cbor.Error)!void {
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".completion" });
defer frame.deinit();