feat: add find all references LSP command

This commit is contained in:
CJ van den Berg 2024-08-16 00:02:42 +02:00
parent d1a79ea8b1
commit 78489e31f6
4 changed files with 99 additions and 0 deletions

View file

@ -98,6 +98,13 @@ pub fn goto_definition(file_path: []const u8, row: usize, col: usize) !void {
return (try get()).pid.send(.{ "goto_definition", project, file_path, row, col });
}
pub fn references(file_path: []const u8, row: usize, col: usize) !void {
const project = tp.env.get().str("project");
if (project.len == 0)
return tp.exit("No project");
return (try get()).pid.send(.{ "references", project, file_path, row, col });
}
pub fn completion(file_path: []const u8, row: usize, col: usize) !void {
const project = tp.env.get().str("project");
if (project.len == 0)
@ -227,6 +234,8 @@ const Process = struct {
self.did_close(project_directory, path) catch |e| return from.forward_error(e, @errorReturnTrace());
} else if (try m.match(.{ "goto_definition", tp.extract(&project_directory), tp.extract(&path), tp.extract(&row), tp.extract(&col) })) {
self.goto_definition(from, project_directory, path, row, col) catch |e| return from.forward_error(e, @errorReturnTrace());
} else if (try m.match(.{ "references", tp.extract(&project_directory), tp.extract(&path), tp.extract(&row), tp.extract(&col) })) {
self.references(from, project_directory, path, row, col) catch |e| return from.forward_error(e, @errorReturnTrace());
} else if (try m.match(.{ "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());
} else if (try m.match(.{ "get_mru_position", tp.extract(&project_directory), tp.extract(&path) })) {
@ -317,6 +326,13 @@ const Process = struct {
return project.goto_definition(from, file_path, row, col);
}
fn references(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8, row: usize, col: usize) !void {
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".references" });
defer frame.deinit();
const project = if (self.projects.get(project_directory)) |p| p else return tp.exit("No project");
return project.references(from, file_path, row, col);
}
fn completion(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8, row: usize, col: usize) !void {
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".completion" });
defer frame.deinit();