fix(lsp): rename_symbol: convert columns to byte offsets and back

This commit is contained in:
CJ van den Berg 2025-01-17 15:56:46 +01:00
parent 61d9f583a8
commit 04b77b4d28
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -4224,13 +4224,26 @@ pub const Editor = struct {
pub fn rename_symbol(self: *Self, _: Context) Result {
const file_path = self.file_path orelse return;
const root = self.buf_root() catch return;
const primary = self.get_primary();
return project_manager.rename_symbol(file_path, primary.cursor.row, primary.cursor.col);
const col = try root.get_line_width_to_pos(primary.cursor.row, primary.cursor.col, self.metrics);
return project_manager.rename_symbol(file_path, primary.cursor.row, col);
}
pub const rename_symbol_meta = .{ .description = "Language: Rename symbol at cursor" };
pub fn add_rename_symbol_cursor(self: *Self, sel: Selection, first: bool) !void {
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 root = self.buf_root() catch return;
const sel: Selection = .{
.begin = .{
.row = sel_.begin.row,
.col = try root.pos_to_width(sel_.begin.row, sel_.begin.col, self.metrics),
},
.end = .{
.row = sel_.end.row,
.col = try root.pos_to_width(sel_.end.row, sel_.end.col, self.metrics),
},
};
const primary = self.get_primary();
primary.selection = sel;
primary.cursor = sel.end;