From cfb208f3d873557a032c5708fc125f7fa688934d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20T=C3=A1mara?= Date: Thu, 13 Nov 2025 16:23:00 -0500 Subject: [PATCH] feat: lsp symbols with parent in mainview --- src/Project.zig | 15 ++++++--------- src/tui/mainview.zig | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Project.zig b/src/Project.zig index db32b8c..fbb13d0 100644 --- a/src/Project.zig +++ b/src/Project.zig @@ -1229,7 +1229,7 @@ fn send_symbol_information(to: tp.pid_ref, file_path: []const u8, item: []const var location: ?Location = null; var containerName: ?[]const u8 = ""; var len_tags_: usize = 0; - var children_count: usize = 0; + var descendant_count: usize = 0; var symbolKind: SymbolType = undefined; const logger_t = log.logger("lsp"); defer logger_t.deinit(); @@ -1239,10 +1239,8 @@ fn send_symbol_information(to: tp.pid_ref, file_path: []const u8, item: []const while (len > 0) : (len -= 1) { var field_name: []const u8 = undefined; if (!(try cbor.matchString(&iter, &field_name))) return error.InvalidMessage; - logger_t.print("{s}", .{field_name}); if (std.mem.eql(u8, field_name, "name")) { if (!(try cbor.matchValue(&iter, cbor.extract(&name)))) return invalid_field("name"); - logger_t.print("->> {s}", .{name}); } else if (std.mem.eql(u8, field_name, "detail")) { if (!(try cbor.matchValue(&iter, cbor.extract(&detail)))) return invalid_field("detail"); } else if (std.mem.eql(u8, field_name, "kind")) { @@ -1271,12 +1269,11 @@ fn send_symbol_information(to: tp.pid_ref, file_path: []const u8, item: []const selectionRange = try read_range(range_); } else if (std.mem.eql(u8, field_name, "children")) { var len_ = cbor.decodeArrayHeader(&iter) catch return 0; + var descendant: []const u8 = ""; while (len_ > 0) : (len_ -= 1) { - children_count += try send_symbol_information(to, file_path, iter, name); + if (!(try cbor.matchValue(&iter, cbor.extract_cbor(&descendant)))) return error.InvalidMessageField; + descendant_count += try send_symbol_information(to, file_path, descendant, name); } - logger_t.print("children: {d}", .{len_}); - try cbor.skipValue(&iter); - logger_t.print("Skipped thing: {d}", .{len_}); } else if (std.mem.eql(u8, field_name, "location")) {} else if (std.mem.eql(u8, field_name, "location")) { var location_: []const u8 = undefined; if (!(try cbor.matchValue(&iter, cbor.extract_cbor(&location_)))) return invalid_field("selectionRange"); @@ -1288,7 +1285,7 @@ fn send_symbol_information(to: tp.pid_ref, file_path: []const u8, item: []const try cbor.skipValue(&iter); } } - logger_t.print("Processed: {s}", .{name}); + logger_t.print("Processed: {s} with {d} descendants", .{ name, descendant_count }); try switch (symbolKind) { SymbolType.document_symbol => { @@ -1309,7 +1306,7 @@ fn send_symbol_information(to: tp.pid_ref, file_path: []const u8, item: []const deprecated, detail, } }) catch return error.ClientFailed; - return children_count + 1; + return descendant_count + 1; }, SymbolType.symbol_information => { var fp = file_path; diff --git a/src/tui/mainview.zig b/src/tui/mainview.zig index 928ff7a..36e36f7 100644 --- a/src/tui/mainview.zig +++ b/src/tui/mainview.zig @@ -985,7 +985,7 @@ const cmds = struct { })) return error.InvalidAddDiagnosticArgument; file_path = project_manager.normalize_file_path(file_path); if (self.get_active_editor()) |editor| if (std.mem.eql(u8, file_path, editor.file_path orelse "")) { - logger.print("received symbol '{s}'", .{name}); + logger.print("received symbol '{s}', '{s}'", .{ name, parent }); self.symbols_complete = false; try self.symbols.appendSlice(self.allocator, ctx.args.buf); };