Use LSP offsets in rename.zig

This commit is contained in:
Alexandros Naskos 2020-07-05 01:40:18 +03:00
parent aac8fc7b0c
commit cbfb316763
2 changed files with 77 additions and 75 deletions

View File

@ -699,7 +699,7 @@ fn renameDefinitionGlobal(arena: *std.heap.ArenaAllocator, id: types.RequestId,
var workspace_edit = types.WorkspaceEdit{
.changes = std.StringHashMap([]types.TextEdit).init(&arena.allocator),
};
try rename.renameSymbol(arena, &document_store, decl, new_name, &workspace_edit.changes.?);
try rename.renameSymbol(arena, &document_store, decl, new_name, &workspace_edit.changes.?, offset_encoding);
try send(arena, types.Response{
.id = id,
.result = .{ .WorkspaceEdit = workspace_edit },
@ -720,7 +720,7 @@ fn renameDefinitionFieldAccess(
var workspace_edit = types.WorkspaceEdit{
.changes = std.StringHashMap([]types.TextEdit).init(&arena.allocator),
};
try rename.renameSymbol(arena, &document_store, decl, new_name, &workspace_edit.changes.?);
try rename.renameSymbol(arena, &document_store, decl, new_name, &workspace_edit.changes.?, offset_encoding);
try send(arena, types.Response{
.id = id,
.result = .{ .WorkspaceEdit = workspace_edit },
@ -733,7 +733,7 @@ fn renameDefinitionLabel(arena: *std.heap.ArenaAllocator, id: types.RequestId, h
var workspace_edit = types.WorkspaceEdit{
.changes = std.StringHashMap([]types.TextEdit).init(&arena.allocator),
};
try rename.renameLabel(arena, decl, new_name, &workspace_edit.changes.?);
try rename.renameLabel(arena, decl, new_name, &workspace_edit.changes.?, offset_encoding);
try send(arena, types.Response{
.id = id,
.result = .{ .WorkspaceEdit = workspace_edit },

View File

@ -2,12 +2,12 @@ const std = @import("std");
const DocumentStore = @import("document_store.zig");
const analysis = @import("analysis.zig");
const types = @import("types.zig");
const offsets = @import("offsets.zig");
const ast = std.zig.ast;
fn renameToken(handle: *DocumentStore.Handle, tok: ast.TokenIndex, new_name: []const u8, edits: *std.ArrayList(types.TextEdit)) !void {
// const handle.tree.tokenLocation(start_index: usize, token: Token.Loc)
const loc = handle.tree.tokenLocation(0, tok);
fn renameToken(handle: *DocumentStore.Handle, tok: ast.TokenIndex, new_name: []const u8, edits: *std.ArrayList(types.TextEdit), encoding: offsets.Encoding) !void {
const loc = offsets.tokenRelativeLocation(handle.tree, 0, tok, encoding) catch return;
(try edits.addOne()).* = .{
.range = .{
.start = .{
@ -16,14 +16,14 @@ fn renameToken(handle: *DocumentStore.Handle, tok: ast.TokenIndex, new_name: []c
},
.end = .{
.line = @intCast(types.Integer, loc.line),
.character = @intCast(types.Integer, loc.column + handle.tree.token_locs[tok].end - handle.tree.token_locs[tok].start),
.character = @intCast(types.Integer, loc.column + offsets.tokenLength(handle.tree, tok, encoding)),
},
},
.newText = new_name,
};
}
pub fn renameLabel(arena: *std.heap.ArenaAllocator, decl: analysis.DeclWithHandle, new_name: []const u8, edits: *std.StringHashMap([]types.TextEdit)) !void {
pub fn renameLabel(arena: *std.heap.ArenaAllocator, decl: analysis.DeclWithHandle, new_name: []const u8, edits: *std.StringHashMap([]types.TextEdit), encoding: offsets.Encoding) !void {
std.debug.assert(decl.decl.* == .label_decl);
const handle = decl.handle;
@ -35,7 +35,7 @@ pub fn renameLabel(arena: *std.heap.ArenaAllocator, decl: analysis.DeclWithHandl
const last_tok = decl.decl.label_decl.lastToken();
// The first token is always going to be the label
try renameToken(handle, first_tok, new_name, &text_edits);
try renameToken(handle, first_tok, new_name, &text_edits, encoding);
var curr_tok = first_tok + 1;
while (curr_tok < last_tok - 2) : (curr_tok += 1) {
@ -44,7 +44,7 @@ pub fn renameLabel(arena: *std.heap.ArenaAllocator, decl: analysis.DeclWithHandl
handle.tree.token_ids[curr_tok + 2] == .Identifier)
{
if (std.mem.eql(u8, handle.tree.tokenSlice(curr_tok + 2), handle.tree.tokenSlice(first_tok))) {
try renameToken(handle, curr_tok + 2, new_name, &text_edits);
try renameToken(handle, curr_tok + 2, new_name, &text_edits, encoding);
}
}
}
@ -59,6 +59,7 @@ fn renameSymbolInternal(
decl: analysis.DeclWithHandle,
new_name: []const u8,
edits: *std.ArrayList(types.TextEdit),
encoding: offsets.Encoding,
) error{OutOfMemory}!void {
const node = node_handle.node;
const handle = node_handle.handle;
@ -67,35 +68,35 @@ fn renameSymbolInternal(
.ContainerDecl, .Root, .Block => {
var idx: usize = 0;
while (node.iterate(idx)) |child| : (idx += 1) {
try renameSymbolInternal(arena, store, .{ .node = child, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = child, .handle = handle }, decl, new_name, edits, encoding);
}
},
.VarDecl => {
const var_decl = node.cast(ast.Node.VarDecl).?;
if (var_decl.type_node) |type_node| {
try renameSymbolInternal(arena, store, .{ .node = type_node, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = type_node, .handle = handle }, decl, new_name, edits, encoding);
}
if (var_decl.init_node) |init_node| {
try renameSymbolInternal(arena, store, .{ .node = init_node, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = init_node, .handle = handle }, decl, new_name, edits, encoding);
}
},
.Use => {
const use = node.cast(ast.Node.Use).?;
try renameSymbolInternal(arena, store, .{ .node = use.expr, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = use.expr, .handle = handle }, decl, new_name, edits, encoding);
},
.ContainerField => {
const field = node.cast(ast.Node.ContainerField).?;
if (field.type_expr) |type_node| {
try renameSymbolInternal(arena, store, .{ .node = type_node, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = type_node, .handle = handle }, decl, new_name, edits, encoding);
}
if (field.value_expr) |init_node| {
try renameSymbolInternal(arena, store, .{ .node = init_node, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = init_node, .handle = handle }, decl, new_name, edits, encoding);
}
},
.Identifier => {
if (try analysis.lookupSymbolGlobal(store, arena, handle, handle.tree.getNodeSource(node), handle.tree.token_locs[node.firstToken()].start)) |child| {
if (std.meta.eql(decl, child)) {
try renameToken(handle, node.firstToken(), new_name, edits);
try renameToken(handle, node.firstToken(), new_name, edits, encoding);
}
}
},
@ -104,90 +105,90 @@ fn renameSymbolInternal(
for (fn_proto.paramsConst()) |param| {
switch (param.param_type) {
.type_expr => |type_node| {
try renameSymbolInternal(arena, store, .{ .node = type_node, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = type_node, .handle = handle }, decl, new_name, edits, encoding);
},
else => {},
}
}
switch (fn_proto.return_type) {
.Explicit, .InferErrorSet => |type_node| {
try renameSymbolInternal(arena, store, .{ .node = type_node, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = type_node, .handle = handle }, decl, new_name, edits, encoding);
},
else => {},
}
if (fn_proto.align_expr) |align_expr| {
try renameSymbolInternal(arena, store, .{ .node = align_expr, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = align_expr, .handle = handle }, decl, new_name, edits, encoding);
}
if (fn_proto.section_expr) |section_expr| {
try renameSymbolInternal(arena, store, .{ .node = section_expr, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = section_expr, .handle = handle }, decl, new_name, edits, encoding);
}
if (fn_proto.callconv_expr) |callconv_expr| {
try renameSymbolInternal(arena, store, .{ .node = callconv_expr, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = callconv_expr, .handle = handle }, decl, new_name, edits, encoding);
}
if (fn_proto.body_node) |body| {
try renameSymbolInternal(arena, store, .{ .node = body, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = body, .handle = handle }, decl, new_name, edits, encoding);
}
},
.AnyFrameType => {
const anyframe_type = node.cast(ast.Node.AnyFrameType).?;
if (anyframe_type.result) |result| {
try renameSymbolInternal(arena, store, .{ .node = result.return_type, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = result.return_type, .handle = handle }, decl, new_name, edits, encoding);
}
},
.Defer => {
const defer_node = node.cast(ast.Node.Defer).?;
try renameSymbolInternal(arena, store, .{ .node = defer_node.expr, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = defer_node.expr, .handle = handle }, decl, new_name, edits, encoding);
},
.Comptime => {
const comptime_node = node.cast(ast.Node.Comptime).?;
try renameSymbolInternal(arena, store, .{ .node = comptime_node.expr, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = comptime_node.expr, .handle = handle }, decl, new_name, edits, encoding);
},
.Nosuspend => {
const nosuspend_node = node.cast(ast.Node.Nosuspend).?;
try renameSymbolInternal(arena, store, .{ .node = nosuspend_node.expr, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = nosuspend_node.expr, .handle = handle }, decl, new_name, edits, encoding);
},
.Switch => {
// TODO When renaming a union(enum) field, also rename switch items that refer to it.
const switch_node = node.cast(ast.Node.Switch).?;
try renameSymbolInternal(arena, store, .{ .node = switch_node.expr, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = switch_node.expr, .handle = handle }, decl, new_name, edits, encoding);
for (switch_node.casesConst()) |case| {
if (case.*.cast(ast.Node.SwitchCase)) |case_node| {
try renameSymbolInternal(arena, store, .{ .node = case_node.expr, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = case_node.expr, .handle = handle }, decl, new_name, edits, encoding);
}
}
},
.While => {
const while_node = node.cast(ast.Node.While).?;
try renameSymbolInternal(arena, store, .{ .node = while_node.condition, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = while_node.condition, .handle = handle }, decl, new_name, edits, encoding);
if (while_node.continue_expr) |cont_expr| {
try renameSymbolInternal(arena, store, .{ .node = cont_expr, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = cont_expr, .handle = handle }, decl, new_name, edits, encoding);
}
try renameSymbolInternal(arena, store, .{ .node = while_node.body, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = while_node.body, .handle = handle }, decl, new_name, edits, encoding);
if (while_node.@"else") |else_node| {
try renameSymbolInternal(arena, store, .{ .node = else_node.body, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = else_node.body, .handle = handle }, decl, new_name, edits, encoding);
}
},
.For => {
const for_node = node.cast(ast.Node.For).?;
try renameSymbolInternal(arena, store, .{ .node = for_node.array_expr, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = for_node.body, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = for_node.array_expr, .handle = handle }, decl, new_name, edits, encoding);
try renameSymbolInternal(arena, store, .{ .node = for_node.body, .handle = handle }, decl, new_name, edits, encoding);
if (for_node.@"else") |else_node| {
try renameSymbolInternal(arena, store, .{ .node = else_node.body, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = else_node.body, .handle = handle }, decl, new_name, edits, encoding);
}
},
.If => {
const if_node = node.cast(ast.Node.If).?;
try renameSymbolInternal(arena, store, .{ .node = if_node.condition, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = if_node.body, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = if_node.condition, .handle = handle }, decl, new_name, edits, encoding);
try renameSymbolInternal(arena, store, .{ .node = if_node.body, .handle = handle }, decl, new_name, edits, encoding);
if (if_node.@"else") |else_node| {
try renameSymbolInternal(arena, store, .{ .node = else_node.body, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = else_node.body, .handle = handle }, decl, new_name, edits, encoding);
}
},
.InfixOp => {
const infix_op = node.cast(ast.Node.InfixOp).?;
switch (infix_op.op) {
.Period => {
try renameSymbolInternal(arena, store, .{ .node = infix_op.lhs, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = infix_op.lhs, .handle = handle }, decl, new_name, edits, encoding);
const rhs_str = analysis.nodeToString(handle.tree, infix_op.rhs) orelse return;
var bound_type_params = analysis.BoundTypeParams.init(&arena.allocator);
@ -214,13 +215,13 @@ fn renameSymbolInternal(
!left_type.type.is_type_val,
)) |child| {
if (std.meta.eql(child, decl)) {
try renameToken(handle, infix_op.rhs.firstToken(), new_name, edits);
try renameToken(handle, infix_op.rhs.firstToken(), new_name, edits, encoding);
}
}
},
else => {
try renameSymbolInternal(arena, store, .{ .node = infix_op.lhs, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = infix_op.rhs, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = infix_op.lhs, .handle = handle }, decl, new_name, edits, encoding);
try renameSymbolInternal(arena, store, .{ .node = infix_op.rhs, .handle = handle }, decl, new_name, edits, encoding);
},
}
},
@ -228,78 +229,78 @@ fn renameSymbolInternal(
const prefix_op = node.cast(ast.Node.PrefixOp).?;
switch (prefix_op.op) {
.ArrayType => |info| {
try renameSymbolInternal(arena, store, .{ .node = info.len_expr, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = info.len_expr, .handle = handle }, decl, new_name, edits, encoding);
if (info.sentinel) |sentinel| {
try renameSymbolInternal(arena, store, .{ .node = sentinel, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = sentinel, .handle = handle }, decl, new_name, edits, encoding);
}
},
.PtrType, .SliceType => |info| {
if (info.align_info) |align_info| {
try renameSymbolInternal(arena, store, .{ .node = align_info.node, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = align_info.node, .handle = handle }, decl, new_name, edits, encoding);
if (align_info.bit_range) |range| {
try renameSymbolInternal(arena, store, .{ .node = range.start, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = range.end, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = range.start, .handle = handle }, decl, new_name, edits, encoding);
try renameSymbolInternal(arena, store, .{ .node = range.end, .handle = handle }, decl, new_name, edits, encoding);
}
}
if (info.sentinel) |sentinel| {
try renameSymbolInternal(arena, store, .{ .node = sentinel, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = sentinel, .handle = handle }, decl, new_name, edits, encoding);
}
},
else => {},
}
try renameSymbolInternal(arena, store, .{ .node = prefix_op.rhs, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = prefix_op.rhs, .handle = handle }, decl, new_name, edits, encoding);
},
.FieldInitializer => {
// TODO Rename field initializer names when needed
const field_init = node.cast(ast.Node.FieldInitializer).?;
try renameSymbolInternal(arena, store, .{ .node = field_init.expr, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = field_init.expr, .handle = handle }, decl, new_name, edits, encoding);
},
.ArrayInitializer => {
const array_init = node.cast(ast.Node.ArrayInitializer).?;
try renameSymbolInternal(arena, store, .{ .node = array_init.lhs, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = array_init.lhs, .handle = handle }, decl, new_name, edits, encoding);
for (array_init.listConst()) |child| {
try renameSymbolInternal(arena, store, .{ .node = child, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = child, .handle = handle }, decl, new_name, edits, encoding);
}
},
.ArrayInitializerDot => {
const array_init = node.cast(ast.Node.ArrayInitializerDot).?;
for (array_init.listConst()) |child| {
try renameSymbolInternal(arena, store, .{ .node = child, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = child, .handle = handle }, decl, new_name, edits, encoding);
}
},
.StructInitializer => {
// TODO Rename field initializer names when needed
const struct_init = node.cast(ast.Node.StructInitializer).?;
try renameSymbolInternal(arena, store, .{ .node = struct_init.lhs, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = struct_init.lhs, .handle = handle }, decl, new_name, edits, encoding);
for (struct_init.listConst()) |child| {
try renameSymbolInternal(arena, store, .{ .node = child, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = child, .handle = handle }, decl, new_name, edits, encoding);
}
},
.StructInitializerDot => {
const struct_init = node.cast(ast.Node.StructInitializerDot).?;
for (struct_init.listConst()) |child| {
try renameSymbolInternal(arena, store, .{ .node = child, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = child, .handle = handle }, decl, new_name, edits, encoding);
}
},
.Call => {
const call = node.cast(ast.Node.Call).?;
try renameSymbolInternal(arena, store, .{ .node = call.lhs, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = call.lhs, .handle = handle }, decl, new_name, edits, encoding);
for (call.paramsConst()) |param| {
try renameSymbolInternal(arena, store, .{ .node = param, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = param, .handle = handle }, decl, new_name, edits, encoding);
}
},
.SuffixOp => {
const suffix_op = node.cast(ast.Node.SuffixOp).?;
try renameSymbolInternal(arena, store, .{ .node = suffix_op.lhs, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = suffix_op.lhs, .handle = handle }, decl, new_name, edits, encoding);
switch (suffix_op.op) {
.ArrayAccess => |acc| try renameSymbolInternal(arena, store, .{ .node = acc, .handle = handle }, decl, new_name, edits),
.ArrayAccess => |acc| try renameSymbolInternal(arena, store, .{ .node = acc, .handle = handle }, decl, new_name, edits, encoding),
.Slice => |sl| {
try renameSymbolInternal(arena, store, .{ .node = sl.start, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = sl.start, .handle = handle }, decl, new_name, edits, encoding);
if (sl.end) |end| {
try renameSymbolInternal(arena, store, .{ .node = end, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = end, .handle = handle }, decl, new_name, edits, encoding);
}
if (sl.sentinel) |sentinel| {
try renameSymbolInternal(arena, store, .{ .node = sentinel, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = sentinel, .handle = handle }, decl, new_name, edits, encoding);
}
},
else => {},
@ -307,30 +308,30 @@ fn renameSymbolInternal(
},
.GroupedExpression => {
const grouped = node.cast(ast.Node.GroupedExpression).?;
try renameSymbolInternal(arena, store, .{ .node = grouped.expr, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = grouped.expr, .handle = handle }, decl, new_name, edits, encoding);
},
.ControlFlowExpression => {
const cfe = node.cast(ast.Node.ControlFlowExpression).?;
if (cfe.rhs) |rhs| {
try renameSymbolInternal(arena, store, .{ .node = rhs, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = rhs, .handle = handle }, decl, new_name, edits, encoding);
}
},
.Suspend => {
const suspend_node = node.cast(ast.Node.Suspend).?;
if (suspend_node.body) |body| {
try renameSymbolInternal(arena, store, .{ .node = body, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = body, .handle = handle }, decl, new_name, edits, encoding);
}
},
.BuiltinCall => {
const builtin_call = node.cast(ast.Node.BuiltinCall).?;
for (builtin_call.paramsConst()) |param| {
try renameSymbolInternal(arena, store, .{ .node = param, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = param, .handle = handle }, decl, new_name, edits, encoding);
}
},
// TODO Inline asm expr
.TestDecl => {
const test_decl = node.cast(ast.Node.TestDecl).?;
try renameSymbolInternal(arena, store, .{ .node = test_decl.body_node, .handle = handle }, decl, new_name, edits);
try renameSymbolInternal(arena, store, .{ .node = test_decl.body_node, .handle = handle }, decl, new_name, edits, encoding);
},
else => {},
}
@ -342,6 +343,7 @@ pub fn renameSymbol(
decl_handle: analysis.DeclWithHandle,
new_name: []const u8,
edits: *std.StringHashMap([]types.TextEdit),
encoding: offsets.Encoding,
) !void {
std.debug.assert(decl_handle.decl.* != .label_decl);
const curr_handle = decl_handle.handle;
@ -356,10 +358,10 @@ pub fn renameSymbol(
for (handles.items) |handle| {
var text_edits = std.ArrayList(types.TextEdit).init(&arena.allocator);
if (handle == curr_handle) {
try renameToken(curr_handle, decl_handle.nameToken(), new_name, &text_edits);
try renameToken(curr_handle, decl_handle.nameToken(), new_name, &text_edits, encoding);
}
try renameSymbolInternal(arena, store, .{ .node = &handle.tree.root_node.base, .handle = handle }, decl_handle, new_name, &text_edits);
try renameSymbolInternal(arena, store, .{ .node = &handle.tree.root_node.base, .handle = handle }, decl_handle, new_name, &text_edits, encoding);
if (text_edits.items.len > 0) {
try edits.putNoClobber(handle.uri(), text_edits.items);
}
@ -368,7 +370,7 @@ pub fn renameSymbol(
.param_decl => |param| {
var curr_doc_text_edits = std.ArrayList(types.TextEdit).init(&arena.allocator);
// Rename the param tok.
try renameToken(curr_handle, decl_handle.nameToken(), new_name, &curr_doc_text_edits);
try renameToken(curr_handle, decl_handle.nameToken(), new_name, &curr_doc_text_edits, encoding);
const fn_node = loop: for (curr_handle.document_scope.scopes) |scope| {
switch (scope.data) {
.function => |proto| {
@ -385,14 +387,14 @@ pub fn renameSymbol(
return;
};
if (fn_node.body_node) |body| {
try renameSymbolInternal(arena, store, .{ .node = body, .handle = curr_handle }, decl_handle, new_name, &curr_doc_text_edits);
try renameSymbolInternal(arena, store, .{ .node = body, .handle = curr_handle }, decl_handle, new_name, &curr_doc_text_edits, encoding);
}
try edits.putNoClobber(curr_handle.uri(), curr_doc_text_edits.items);
},
.pointer_payload, .array_payload, .switch_payload => {
var curr_doc_text_edits = std.ArrayList(types.TextEdit).init(&arena.allocator);
try renameToken(curr_handle, decl_handle.nameToken(), new_name, &curr_doc_text_edits);
try renameSymbolInternal(arena, store, .{ .node = &curr_handle.tree.root_node.base, .handle = curr_handle }, decl_handle, new_name, &curr_doc_text_edits);
try renameToken(curr_handle, decl_handle.nameToken(), new_name, &curr_doc_text_edits, encoding);
try renameSymbolInternal(arena, store, .{ .node = &curr_handle.tree.root_node.base, .handle = curr_handle }, decl_handle, new_name, &curr_doc_text_edits, encoding);
try edits.putNoClobber(curr_handle.uri(), curr_doc_text_edits.items);
},
.label_decl => unreachable,