refactor: output LSP client messages to log
Regular message only if lsp_output "verbose".
This commit is contained in:
parent
69ea495495
commit
21bd1e58a8
2 changed files with 16 additions and 6 deletions
|
@ -1562,6 +1562,13 @@ fn show_or_log_message(self: *Self, operation: enum { show, log }, params_cb: []
|
||||||
self.logger_lsp.print("{s}: {s}", .{ @tagName(operation), msg });
|
self.logger_lsp.print("{s}: {s}", .{ @tagName(operation), msg });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn show_notification(self: *Self, method: []const u8, params_cb: []const u8) !void {
|
||||||
|
if (!tp.env.get().is("lsp_verbose")) return;
|
||||||
|
const params = try cbor.toJsonAlloc(self.allocator, params_cb);
|
||||||
|
defer self.allocator.free(params);
|
||||||
|
self.logger_lsp.print("LSP notification: {s} -> {s}", .{ method, params });
|
||||||
|
}
|
||||||
|
|
||||||
pub fn register_capability(self: *Self, from: tp.pid_ref, cbor_id: []const u8, params_cb: []const u8) ClientError!void {
|
pub fn register_capability(self: *Self, from: tp.pid_ref, cbor_id: []const u8, params_cb: []const u8) ClientError!void {
|
||||||
_ = params_cb;
|
_ = params_cb;
|
||||||
return LSP.send_response(self.allocator, from, cbor_id, null) catch error.ClientFailed;
|
return LSP.send_response(self.allocator, from, cbor_id, null) catch error.ClientFailed;
|
||||||
|
|
|
@ -333,6 +333,8 @@ const Process = struct {
|
||||||
var n: usize = 0;
|
var n: usize = 0;
|
||||||
var task: []const u8 = undefined;
|
var task: []const u8 = undefined;
|
||||||
var context: usize = undefined;
|
var context: usize = undefined;
|
||||||
|
var tag: []const u8 = undefined;
|
||||||
|
var message: []const u8 = undefined;
|
||||||
|
|
||||||
var eol_mode: Buffer.EolModeTag = @intFromEnum(Buffer.EolMode.lf);
|
var eol_mode: Buffer.EolModeTag = @intFromEnum(Buffer.EolMode.lf);
|
||||||
|
|
||||||
|
@ -405,6 +407,11 @@ const Process = struct {
|
||||||
self.hover(from, project_directory, path, row, col) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed;
|
self.hover(from, project_directory, path, row, col) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed;
|
||||||
} else if (try cbor.match(m.buf, .{ "get_mru_position", tp.extract(&project_directory), tp.extract(&path) })) {
|
} else if (try cbor.match(m.buf, .{ "get_mru_position", tp.extract(&project_directory), tp.extract(&path) })) {
|
||||||
self.get_mru_position(from, project_directory, path) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed;
|
self.get_mru_position(from, project_directory, path) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed;
|
||||||
|
} else if (try cbor.match(m.buf, .{ "lsp", "msg", tp.extract(&tag), tp.extract(&message) })) {
|
||||||
|
if (tp.env.get().is("lsp_verbose"))
|
||||||
|
self.logger.print("{s}: {s}", .{ tag, message });
|
||||||
|
} else if (try cbor.match(m.buf, .{ "lsp", "err", tp.extract(&tag), tp.extract(&message) })) {
|
||||||
|
self.logger.print("{s} error: {s}", .{ tag, message });
|
||||||
} else if (try cbor.match(m.buf, .{"shutdown"})) {
|
} else if (try cbor.match(m.buf, .{"shutdown"})) {
|
||||||
self.persist_projects();
|
self.persist_projects();
|
||||||
from.send(.{ "project_manager", "shutdown" }) catch return error.ClientFailed;
|
from.send(.{ "project_manager", "shutdown" }) catch return error.ClientFailed;
|
||||||
|
@ -611,12 +618,8 @@ const Process = struct {
|
||||||
project.show_message(params_cb)
|
project.show_message(params_cb)
|
||||||
else if (std.mem.eql(u8, method, "window/logMessage"))
|
else if (std.mem.eql(u8, method, "window/logMessage"))
|
||||||
project.log_message(params_cb)
|
project.log_message(params_cb)
|
||||||
else {
|
else
|
||||||
if (!tp.env.get().is("lsp_verbose")) return;
|
project.show_notification(method, params_cb);
|
||||||
const params = try cbor.toJsonAlloc(self.allocator, params_cb);
|
|
||||||
defer self.allocator.free(params);
|
|
||||||
self.logger.print("LSP notification: {s} -> {s}", .{ method, params });
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_request(self: *Process, from: tp.pid_ref, project_directory: []const u8, language_server: []const u8, method: []const u8, cbor_id: []const u8, params_cb: []const u8) (ProjectError || Project.ClientError || cbor.Error || cbor.JsonEncodeError || UnsupportedError)!void {
|
fn dispatch_request(self: *Process, from: tp.pid_ref, project_directory: []const u8, language_server: []const u8, method: []const u8, cbor_id: []const u8, params_cb: []const u8) (ProjectError || Project.ClientError || cbor.Error || cbor.JsonEncodeError || UnsupportedError)!void {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue