2020-06-27 07:18:05 +01:00
|
|
|
const std = @import("std");
|
2021-10-02 21:25:49 +01:00
|
|
|
const DocumentStore = @import("./DocumentStore.zig");
|
2021-10-01 01:48:40 +01:00
|
|
|
const analysis = @import("./analysis.zig");
|
|
|
|
const references = @import("./references.zig");
|
|
|
|
const types = @import("./types.zig");
|
|
|
|
const offsets = @import("./offsets.zig");
|
2020-06-27 13:29:45 +01:00
|
|
|
|
2020-07-05 22:56:41 +01:00
|
|
|
// TODO Use a map to array lists and collect at the end instead?
|
2020-07-05 22:35:52 +01:00
|
|
|
const RefHandlerContext = struct {
|
|
|
|
edits: *std.StringHashMap([]types.TextEdit),
|
|
|
|
allocator: *std.mem.Allocator,
|
|
|
|
new_name: []const u8,
|
|
|
|
};
|
2020-06-27 07:18:05 +01:00
|
|
|
|
2020-07-05 22:35:52 +01:00
|
|
|
fn refHandler(context: RefHandlerContext, loc: types.Location) !void {
|
2020-07-05 22:56:41 +01:00
|
|
|
var text_edits = if (context.edits.get(loc.uri)) |slice|
|
2020-07-05 22:35:52 +01:00
|
|
|
std.ArrayList(types.TextEdit).fromOwnedSlice(context.allocator, slice)
|
|
|
|
else
|
|
|
|
std.ArrayList(types.TextEdit).init(context.allocator);
|
2020-06-27 07:18:05 +01:00
|
|
|
|
2020-07-05 22:35:52 +01:00
|
|
|
(try text_edits.addOne()).* = .{
|
|
|
|
.range = loc.range,
|
|
|
|
.newText = context.new_name,
|
|
|
|
};
|
2020-07-05 22:56:41 +01:00
|
|
|
try context.edits.put(loc.uri, text_edits.toOwnedSlice());
|
2020-06-27 07:18:05 +01:00
|
|
|
}
|
2020-06-27 13:29:45 +01:00
|
|
|
|
2021-10-01 01:51:51 +01:00
|
|
|
pub fn renameSymbol(arena: *std.heap.ArenaAllocator, store: *DocumentStore, decl_handle: analysis.DeclWithHandle, new_name: []const u8, edits: *std.StringHashMap([]types.TextEdit), encoding: offsets.Encoding) !void {
|
2020-07-05 22:35:52 +01:00
|
|
|
std.debug.assert(decl_handle.decl.* != .label_decl);
|
|
|
|
try references.symbolReferences(arena, store, decl_handle, encoding, true, RefHandlerContext{
|
|
|
|
.edits = edits,
|
|
|
|
.allocator = &arena.allocator,
|
|
|
|
.new_name = new_name,
|
2021-03-06 19:55:59 +00:00
|
|
|
}, refHandler, true);
|
2020-06-27 13:29:45 +01:00
|
|
|
}
|
|
|
|
|
2021-10-01 01:51:51 +01:00
|
|
|
pub fn renameLabel(arena: *std.heap.ArenaAllocator, decl_handle: analysis.DeclWithHandle, new_name: []const u8, edits: *std.StringHashMap([]types.TextEdit), encoding: offsets.Encoding) !void {
|
2020-07-05 22:35:52 +01:00
|
|
|
std.debug.assert(decl_handle.decl.* == .label_decl);
|
|
|
|
try references.labelReferences(arena, decl_handle, encoding, true, RefHandlerContext{
|
|
|
|
.edits = edits,
|
|
|
|
.allocator = &arena.allocator,
|
|
|
|
.new_name = new_name,
|
|
|
|
}, refHandler);
|
2020-06-27 13:29:45 +01:00
|
|
|
}
|