From ee7fb21cee40fe84875a886748b0057aaf96677a Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Thu, 19 Sep 2024 22:03:27 +0200 Subject: [PATCH] fix: add missing error set --- src/Project.zig | 12 +++++++----- src/project_manager.zig | 8 ++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Project.zig b/src/Project.zig index 73076e4..44fb516 100644 --- a/src/Project.zig +++ b/src/Project.zig @@ -21,6 +21,12 @@ file_language_server: std.StringHashMap(LSP), const Self = @This(); +const OutOfMemoryError = error{OutOfMemory}; +const SendError = error{SendFailed}; +const CallError = tp.CallError; +const SpawnError = (OutOfMemoryError || error{ThespianSpawnFailed}); +pub const InvalidMessageError = error{ InvalidMessage, InvalidMessageField, InvalidTargetURI }; + const File = struct { path: []const u8, mtime: i128, @@ -450,10 +456,6 @@ fn send_goto_request(self: *Self, from: tp.pid_ref, file_path: []const u8, row: } } -const OutOfMemoryError = error{OutOfMemory}; -pub const SendError = error{SendFailed}; -pub const InvalidMessageError = error{ InvalidMessage, InvalidMessageField, InvalidTargetURI }; - fn navigate_to_location_link(_: *Self, from: tp.pid_ref, location_link: []const u8) (SendError || InvalidMessageError || cbor.Error)!void { var iter = location_link; var targetUri: ?[]const u8 = null; @@ -882,7 +884,7 @@ pub fn send_lsp_response(self: *Self, from: tp.pid_ref, id: i32, result: anytype from.send(.{ "RSP", id, cb.items }) catch return error.SendFailed; } -fn send_lsp_init_request(self: *Self, lsp: LSP, project_path: []const u8, project_basename: []const u8, project_uri: []const u8) (OutOfMemoryError || SendError)!tp.message { +fn send_lsp_init_request(self: *Self, lsp: LSP, project_path: []const u8, project_basename: []const u8, project_uri: []const u8) (OutOfMemoryError || SpawnError || CallError)!tp.message { return lsp.send_request(self.allocator, "initialize", .{ .processId = if (builtin.os.tag == .linux) std.os.linux.getpid() else null, .rootPath = project_path, diff --git a/src/project_manager.zig b/src/project_manager.zig index c576a68..aa15d9d 100644 --- a/src/project_manager.zig +++ b/src/project_manager.zig @@ -465,21 +465,21 @@ const Process = struct { 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) (ProjectError || Project.SendError || Project.GetFileLspError)!void { + fn completion(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8, row: usize, col: usize) (ProjectError || SendError || Project.GetFileLspError)!void { const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".completion" }); defer frame.deinit(); const project = self.projects.get(project_directory) orelse return error.NoProject; return project.completion(from, file_path, row, col); } - fn hover(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8, row: usize, col: usize) (ProjectError || Project.SendError || Project.InvalidMessageError || Project.GetFileLspError || cbor.Error)!void { + fn hover(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8, row: usize, col: usize) (ProjectError || SendError || Project.InvalidMessageError || Project.GetFileLspError || cbor.Error)!void { const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".hover" }); defer frame.deinit(); const project = self.projects.get(project_directory) orelse return error.NoProject; return project.hover(from, file_path, row, col); } - fn get_mru_position(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8) (ProjectError || Project.SendError)!void { + fn get_mru_position(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8) (ProjectError || SendError)!void { const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".get_mru_position" }); defer frame.deinit(); const project = self.projects.get(project_directory) orelse return error.NoProject; @@ -491,7 +491,7 @@ const Process = struct { return project.update_mru(file_path, row, col); } - fn dispatch_notify(self: *Process, project_directory: []const u8, language_server: []const u8, method: []const u8, params_cb: []const u8) (ProjectError || Project.InvalidMessageError || Project.SendError || cbor.Error || cbor.JsonEncodeError)!void { + fn dispatch_notify(self: *Process, project_directory: []const u8, language_server: []const u8, method: []const u8, params_cb: []const u8) (ProjectError || Project.InvalidMessageError || SendError || cbor.Error || cbor.JsonEncodeError)!void { _ = language_server; const project = self.projects.get(project_directory) orelse return error.NoProject; return if (std.mem.eql(u8, method, "textDocument/publishDiagnostics"))