From 3a16d7fe50064f579b7b8bc86f9b8889be9bdaed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20T=C3=A1mara?= Date: Fri, 13 Mar 2026 13:32:25 -0500 Subject: [PATCH] Add indentation according to depth in symbol palette --- src/Project.zig | 7 ++++--- src/tui/mainview.zig | 1 + src/tui/mode/overlay/completion_dropdown.zig | 1 + src/tui/mode/overlay/completion_palette.zig | 1 + src/tui/mode/overlay/symbol_palette.zig | 17 ++++++++++------- src/tui/tui.zig | 4 ++++ 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/Project.zig b/src/Project.zig index 817ada8..e30f5ab 100644 --- a/src/Project.zig +++ b/src/Project.zig @@ -1417,7 +1417,7 @@ fn send_symbol_items(to: tp.pid_ref, file_path: []const u8, items: []const u8) ( var node_count: usize = 0; while (len > 0) : (len -= 1) { if (!(try cbor.matchValue(&iter, cbor.extract_cbor(&item)))) return error.InvalidSymbolInformationArray; - node_count += try send_symbol_information(to, file_path, item, ""); + node_count += try send_symbol_information(to, file_path, item, "", 0); } return to.send(.{ "cmd", "add_document_symbol_done", .{file_path} }) catch |e| { std.log.err("send add_document_symbol_done failed: {t}", .{e}); @@ -1484,7 +1484,7 @@ pub const SymbolInformationError = error{ InvalidSymbolInformationField, InvalidTargetURI, } || LocationLinkError || cbor.Error; -fn send_symbol_information(to: tp.pid_ref, file_path: []const u8, item: []const u8, parent_name: []const u8) SymbolInformationError!usize { +fn send_symbol_information(to: tp.pid_ref, file_path: []const u8, item: []const u8, parent_name: []const u8, depth: u8) SymbolInformationError!usize { var name: []const u8 = ""; var detail: ?[]const u8 = ""; var kind: usize = 0; @@ -1537,7 +1537,7 @@ fn send_symbol_information(to: tp.pid_ref, file_path: []const u8, item: []const var descendant: []const u8 = ""; while (len_ > 0) : (len_ -= 1) { if (!(try cbor.matchValue(&iter, cbor.extract_cbor(&descendant)))) return error.InvalidSymbolInformationField; - descendant_count += try send_symbol_information(to, file_path, descendant, name); + descendant_count += try send_symbol_information(to, file_path, descendant, name, depth + 1); } } else if (std.mem.eql(u8, field_name, "location")) {} else if (std.mem.eql(u8, field_name, "location")) { var location_: []const u8 = undefined; @@ -1569,6 +1569,7 @@ fn send_symbol_information(to: tp.pid_ref, file_path: []const u8, item: []const selectionRange.end.character, deprecated, detail, + depth, } }) catch |e| { std.log.err("send add_document_symbol failed: {t}", .{e}); return 0; diff --git a/src/tui/mainview.zig b/src/tui/mainview.zig index 178f7e5..fa07775 100644 --- a/src/tui/mainview.zig +++ b/src/tui/mainview.zig @@ -1206,6 +1206,7 @@ const cmds = struct { .integer, // selectionRange.end.col .boolean, // deprecated .string, //detail + .integer, //depth }, }; diff --git a/src/tui/mode/overlay/completion_dropdown.zig b/src/tui/mode/overlay/completion_dropdown.zig index d9beb30..ceb7a34 100644 --- a/src/tui/mode/overlay/completion_dropdown.zig +++ b/src/tui/mode/overlay/completion_dropdown.zig @@ -209,6 +209,7 @@ pub fn on_render_menu(self: *Type, button: *Type.ButtonType, theme: *const Widge }; return tui.render_symbol( &button.plane, + 0, values.label, icon_, color, diff --git a/src/tui/mode/overlay/completion_palette.zig b/src/tui/mode/overlay/completion_palette.zig index 57219fa..ae8f9d2 100644 --- a/src/tui/mode/overlay/completion_palette.zig +++ b/src/tui/mode/overlay/completion_palette.zig @@ -116,6 +116,7 @@ pub fn on_render_menu(_: *Type, button: *Type.ButtonType, theme: *const Widget.T return tui.render_symbol( &button.plane, + 0, values.label, icon_, color, diff --git a/src/tui/mode/overlay/symbol_palette.zig b/src/tui/mode/overlay/symbol_palette.zig index 2bbfb51..b02dc4b 100644 --- a/src/tui/mode/overlay/symbol_palette.zig +++ b/src/tui/mode/overlay/symbol_palette.zig @@ -45,7 +45,7 @@ pub fn load_entries(palette: *Type) !usize { while (iter.len > 0) { var cbor_item: []const u8 = undefined; if (!try cbor.matchValue(&iter, cbor.extract_cbor(&cbor_item))) return error.BadCompletion; - const label_, _, _, const sel = get_values(cbor_item); + const label_, _, _, const sel, _ = get_values(cbor_item); const label_len_ = tui.egc_chunk_width(label_, 0, 1); (try palette.entries.addOne(palette.allocator)).* = .{ .cbor = cbor_item, .label = label_, .range = sel }; @@ -89,11 +89,12 @@ pub fn on_render_menu(_: *Type, button: *Type.ButtonType, theme: *const Widget.T if (!(cbor.matchValue(&iter, cbor.extract_cbor(&item_cbor)) catch false)) return false; if (!(cbor.matchValue(&iter, cbor.extract_cbor(&matches_cbor)) catch false)) return false; - const label_, const container, const kind, _ = get_values(item_cbor); + const label_, const container, const kind, _, const indent = get_values(item_cbor); const icon_: []const u8 = kind.icon(); const color: u24 = 0x0; return tui.render_symbol( &button.plane, + indent, label_, icon_, color, @@ -110,10 +111,11 @@ pub fn on_render_menu(_: *Type, button: *Type.ButtonType, theme: *const Widget.T ); } -fn get_values(item_cbor: []const u8) struct { []const u8, []const u8, SymbolKind, ed.Selection } { +fn get_values(item_cbor: []const u8) struct { []const u8, []const u8, SymbolKind, ed.Selection, u8 } { var label_: []const u8 = ""; var container: []const u8 = ""; var kind: u8 = 0; + var depth: u8 = 0; var range: ed.Selection = .{}; _ = cbor.match(item_cbor, .{ cbor.any, // file_path @@ -131,8 +133,9 @@ fn get_values(item_cbor: []const u8) struct { []const u8, []const u8, SymbolKind cbor.any, // selectionRange.end.col cbor.any, // deprecated cbor.any, // detail + cbor.extract(&depth), // number of ancestors }) catch false; - return .{ label_, container, @enumFromInt(kind), range }; + return .{ label_, container, @enumFromInt(kind), range, depth }; } fn find_closest(palette: *Type) ?usize { @@ -140,7 +143,7 @@ fn find_closest(palette: *Type) ?usize { const cursor = editor.get_primary().cursor; var previous: usize = 0; for (palette.entries.items, 0..) |entry, idx| { - _, _, _, const sel = get_values(entry.cbor); + _, _, _, const sel, _ = get_values(entry.cbor); if (cursor.row < sel.begin.row) return previous + 1; previous = idx; } @@ -151,7 +154,7 @@ fn select(menu: **Type.MenuType, button: *Type.ButtonType, _: Type.Pos) void { const self = menu.*.opts.ctx; const editor = tui.get_active_editor() orelse return; editor.clear_matches(); - _, _, _, const sel = get_values(button.opts.label); + _, _, _, const sel, _ = get_values(button.opts.label); tp.self_pid().send(.{ "cmd", "exit_overlay_mode" }) catch |e| menu.*.opts.ctx.logger.err(module_name, e); switch (self.activate) { .normal => tp.self_pid().send(.{ "cmd", "goto_line_and_column", .{ @@ -169,7 +172,7 @@ fn select(menu: **Type.MenuType, button: *Type.ButtonType, _: Type.Pos) void { pub fn updated(palette: *Type, button_: ?*Type.ButtonType) !void { const button = button_ orelse return cancel(palette); - _, _, _, const sel = get_values(button.opts.label); + _, _, _, const sel, _ = get_values(button.opts.label); tp.self_pid().send(.{ "cmd", "focus_on_range", .{ sel.begin.row, sel.begin.col, sel.end.row, sel.end.col } }) catch {}; } diff --git a/src/tui/tui.zig b/src/tui/tui.zig index fa425da..fa2e8a7 100644 --- a/src/tui/tui.zig +++ b/src/tui/tui.zig @@ -2365,6 +2365,7 @@ pub fn render_file_vcs_item_cbor(self: *renderer.Plane, file_item_cbor: []const pub fn render_symbol( self: *renderer.Plane, + indent: u8, symbol: []const u8, icon: []const u8, color: u24, @@ -2398,6 +2399,9 @@ pub fn render_symbol( const icon_width = render_file_icon(self, icon, color); self.set_style(style_symbol); + + for (0..indent) |_| _ = self.print(" ", .{}) catch {}; + _ = self.print("{s}", .{symbol}) catch {}; self.set_style(style_detail);