From bb71a4323341767b606e2e353bbec64d974fa20b Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 27 May 2025 21:55:23 +0200 Subject: [PATCH 1/2] refactor: default initialize editor list members with .empty --- src/tui/editor.zig | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/tui/editor.zig b/src/tui/editor.zig index ace049b..dc12506 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -273,8 +273,8 @@ pub const Editor = struct { pause_undo: bool = false, pause_undo_root: ?Buffer.Root = null, - cursels: CurSel.List, - cursels_saved: CurSel.List, + cursels: CurSel.List = .empty, + cursels_saved: CurSel.List = .empty, selection_mode: SelectMode = .char, clipboard: ?[]const u8 = null, target_column: ?Cursor = null, @@ -291,7 +291,7 @@ pub const Editor = struct { eol_mode: Buffer.EolMode = .lf, utf8_sanitized: bool = false, } = null, - matches: Match.List, + matches: Match.List = .empty, match_token: usize = 0, match_done_token: usize = 0, last_find_query: ?[]const u8 = null, @@ -339,7 +339,7 @@ pub const Editor = struct { style_cache: ?StyleCache = null, style_cache_theme: []const u8 = "", - diagnostics: std.ArrayListUnmanaged(Diagnostic), + diagnostics: std.ArrayListUnmanaged(Diagnostic) = .empty, diag_errors: usize = 0, diag_warnings: usize = 0, diag_info: usize = 0, @@ -452,12 +452,8 @@ pub const Editor = struct { .animation_lag = get_animation_max_lag(), .animation_frame_rate = frame_rate, .animation_last_time = time.microTimestamp(), - .cursels = .empty, - .cursels_saved = .empty, - .matches = .empty, .enable_terminal_cursor = tui.config().enable_terminal_cursor, .render_whitespace = from_whitespace_mode(tui.config().whitespace_mode), - .diagnostics = .empty, }; } From 17be71042b7c8adfdcda96cf89c96afc050aa785 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 27 May 2025 21:56:30 +0200 Subject: [PATCH 2/2] feat(completion): store received completions in a buffer --- src/tui/editor.zig | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/tui/editor.zig b/src/tui/editor.zig index dc12506..ef7fc73 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -345,6 +345,8 @@ pub const Editor = struct { diag_info: usize = 0, diag_hints: usize = 0, + completions: std.ArrayListUnmanaged(u8) = .empty, + need_save_after_filter: ?struct { then: ?struct { cmd: []const u8, @@ -463,6 +465,7 @@ pub const Editor = struct { if (self.buffer) |_| self.write_state(meta.writer(self.allocator)) catch {}; for (self.diagnostics.items) |*d| d.deinit(self.allocator); self.diagnostics.deinit(self.allocator); + self.completions.deinit(self.allocator); if (self.syntax) |syn| syn.destroy(tui.query_cache()); self.cursels.deinit(self.allocator); self.matches.deinit(self.allocator); @@ -5280,6 +5283,7 @@ pub const Editor = struct { pub fn completion(self: *Self, _: Context) Result { const file_path = self.file_path orelse return; const primary = self.get_primary(); + self.completions.clearRetainingCapacity(); return project_manager.completion(file_path, primary.cursor.row, primary.cursor.col); } pub const completion_meta: Meta = .{ .description = "Language: Show completions at cursor" }; @@ -5477,11 +5481,10 @@ pub const Editor = struct { } pub fn add_completion(self: *Self, row: usize, col: usize, is_incomplete: bool, msg: tp.message) Result { - _ = self; + try self.completions.appendSlice(self.allocator, msg.buf); _ = row; _ = col; _ = is_incomplete; - _ = msg; } pub fn select(self: *Self, ctx: Context) Result {