diff --git a/src/Project.zig b/src/Project.zig index cee242f..997e8aa 100644 --- a/src/Project.zig +++ b/src/Project.zig @@ -795,7 +795,7 @@ pub fn rename_symbol(self: *Self, from: tp.pid_ref, file_path: []const u8, row: const response = lsp.send_request(self.allocator, "textDocument/rename", .{ .textDocument = .{ .uri = uri }, .position = .{ .line = row, .character = col }, - .newName = "foobar", + .newName = "PLACEHOLDER", }) catch return error.LspFailed; defer self.allocator.free(response.buf); var result: []const u8 = undefined; diff --git a/src/tui/editor.zig b/src/tui/editor.zig index 7c54a58..dbd38c5 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -4229,6 +4229,14 @@ pub const Editor = struct { } pub const rename_symbol_meta = .{ .description = "Language: Rename symbol at cursor" }; + pub fn add_rename_symbol_cursor(self: *Self, sel: Selection, first: bool) !void { + if (first) self.cancel_all_selections() else try self.push_cursor(); + const primary = self.get_primary(); + primary.selection = sel; + primary.cursor = sel.end; + self.need_render(); + } + pub fn hover(self: *Self, _: Context) Result { const primary = self.get_primary(); return self.hover_at(primary.cursor.row, primary.cursor.col); @@ -4323,20 +4331,6 @@ pub const Editor = struct { self.need_render(); } - pub fn rename_symbol_item( - self: *Self, - sel: Selection, - new_text: []const u8, - root_prev: *?Buffer.Root, - final: bool, - ) !void { - self.get_primary().selection = sel; - if (root_prev.* == null) root_prev.* = (try self.buf_for_update()).root; - const root = try self.delete_selection(root_prev.*.?, self.get_primary(), self.allocator); - root_prev.* = try self.insert(root, self.get_primary(), new_text, self.allocator); - if (final) try self.update_buf(root_prev.*.?); - } - pub fn select(self: *Self, ctx: Context) Result { var sel: Selection = .{}; if (!try ctx.args.match(.{ tp.extract(&sel.begin.row), tp.extract(&sel.begin.col), tp.extract(&sel.end.row), tp.extract(&sel.end.col) })) diff --git a/src/tui/mainview.zig b/src/tui/mainview.zig index 611cac5..a7e2420 100644 --- a/src/tui/mainview.zig +++ b/src/tui/mainview.zig @@ -555,12 +555,13 @@ const cmds = struct { pub const add_diagnostic_meta = .{ .arguments = &.{ .string, .string, .string, .string, .integer, .integer, .integer, .integer, .integer } }; pub fn rename_symbol_item(self: *Self, ctx: Ctx) Result { + const editor = self.get_active_editor() orelse return; // because the incoming message is an array of Renames, we manuallly // parse instead of using ctx.args.match() which doesn't seem to return // the parsed length needed to correctly advance iter. var iter = ctx.args.buf; var len = try cbor.decodeArrayHeader(&iter); - var mroot: ?@import("Buffer").Root = null; + var first = true; while (len != 0) { len -= 1; std.debug.assert(try cbor.decodeArrayHeader(&iter) == 6); @@ -575,13 +576,14 @@ const cmds = struct { if (!try cbor.matchString(&iter, &new_text)) return error.MissingArgument; 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 "")) { - try editor.rename_symbol_item(sel, new_text, &mroot, len == 0); + if (std.mem.eql(u8, file_path, editor.file_path orelse "")) { + try editor.add_rename_symbol_cursor(sel, first); + first = false; } else { const logger = log.logger("LSP"); defer logger.deinit(); logger.print("TODO perform renames in other files\n", .{}); - }; + } } } pub const rename_symbol_item_meta = .{ .arguments = &.{.array} };