feat: improve language server not found errors

This commit is contained in:
CJ van den Berg 2024-12-16 23:14:24 +01:00
parent 11215b21ad
commit 047c9bbb99
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 13 additions and 7 deletions

View file

@ -192,19 +192,14 @@ const Process = struct {
try self.term(); try self.term();
} else if (try cbor.match(m.buf, .{ self.sp_tag, "stdout", tp.extract(&bytes) })) { } else if (try cbor.match(m.buf, .{ self.sp_tag, "stdout", tp.extract(&bytes) })) {
try self.handle_output(bytes); try self.handle_output(bytes);
} else if (try cbor.match(m.buf, .{ self.sp_tag, "term", "error.FileNotFound", 1 })) {
try self.handle_not_found();
} else if (try cbor.match(m.buf, .{ self.sp_tag, "term", tp.extract(&err), tp.extract(&code) })) { } else if (try cbor.match(m.buf, .{ self.sp_tag, "term", tp.extract(&err), tp.extract(&code) })) {
try self.handle_terminated(err, code); try self.handle_terminated(err, code);
} else if (try cbor.match(m.buf, .{ self.sp_tag, "stderr", tp.extract(&bytes) })) { } else if (try cbor.match(m.buf, .{ self.sp_tag, "stderr", tp.extract(&bytes) })) {
self.write_log("{s}\n", .{bytes}); self.write_log("{s}\n", .{bytes});
} else if (try cbor.match(m.buf, .{ "exit", "normal" })) { } else if (try cbor.match(m.buf, .{ "exit", "normal" })) {
// self.write_log("### exit normal ###\n", .{}); // self.write_log("### exit normal ###\n", .{});
} else if (try cbor.match(m.buf, .{ "exit", "error.FileNotFound" })) {
self.write_log("### LSP not found ###\n", .{});
const logger = log.logger("LSP");
defer logger.deinit();
var buf: [1024]u8 = undefined;
logger.print_err("init", "executable not found: {s}", .{self.cmd.to_json(&buf) catch "{command too large}"});
return error.FileNotFound;
} else { } else {
tp.unexpected(m) catch {}; tp.unexpected(m) catch {};
self.write_log("{s}\n", .{tp.error_text()}); self.write_log("{s}\n", .{tp.error_text()});
@ -273,6 +268,15 @@ const Process = struct {
}; };
} }
fn handle_not_found(self: *Process) error{ExitNormal}!void {
const logger = log.logger("LSP");
defer logger.deinit();
logger.print_err("init", "'{s}' executable not found", .{self.tag});
self.write_log("### '{s}' executable not found ###\n", .{self.tag});
self.parent.send(.{ sp_tag, self.tag, "not found" }) catch {};
return error.ExitNormal;
}
fn handle_terminated(self: *Process, err: []const u8, code: u32) error{ExitNormal}!void { fn handle_terminated(self: *Process, err: []const u8, code: u32) error{ExitNormal}!void {
const logger = log.logger("LSP"); const logger = log.logger("LSP");
defer logger.deinit(); defer logger.deinit();

View file

@ -302,6 +302,8 @@ const Process = struct {
self.dispatch_notify(project_directory, language_server, method, params_cb) catch |e| return self.logger.err("lsp-handling", e); self.dispatch_notify(project_directory, language_server, method, params_cb) catch |e| return self.logger.err("lsp-handling", e);
} else if (try cbor.match(m.buf, .{ "child", tp.extract(&project_directory), tp.extract(&language_server), "request", tp.extract(&method), tp.extract_cbor(&cbor_id), tp.extract_cbor(&params_cb) })) { } else if (try cbor.match(m.buf, .{ "child", tp.extract(&project_directory), tp.extract(&language_server), "request", tp.extract(&method), tp.extract_cbor(&cbor_id), tp.extract_cbor(&params_cb) })) {
self.dispatch_request(from, project_directory, language_server, method, cbor_id, params_cb) catch |e| return self.logger.err("lsp-handling", e); self.dispatch_request(from, project_directory, language_server, method, cbor_id, params_cb) catch |e| return self.logger.err("lsp-handling", e);
} else if (try cbor.match(m.buf, .{ "child", tp.extract(&path), "not found" })) {
self.logger.print("executable '{s}' not found", .{path});
} else if (try cbor.match(m.buf, .{ "child", tp.extract(&path), "done" })) { } else if (try cbor.match(m.buf, .{ "child", tp.extract(&path), "done" })) {
self.logger.print_err("lsp-handling", "child '{s}' terminated", .{path}); self.logger.print_err("lsp-handling", "child '{s}' terminated", .{path});
} else if (try cbor.match(m.buf, .{ "open", tp.extract(&project_directory) })) { } else if (try cbor.match(m.buf, .{ "open", tp.extract(&project_directory) })) {