summaryrefslogtreecommitdiff
path: root/src/lsp/lsp_zls.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/lsp/lsp_zls.zig')
-rw-r--r--src/lsp/lsp_zls.zig26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/lsp/lsp_zls.zig b/src/lsp/lsp_zls.zig
index 76c5594c..bf220c47 100644
--- a/src/lsp/lsp_zls.zig
+++ b/src/lsp/lsp_zls.zig
@@ -1123,9 +1123,9 @@ fn containsIgnoreCase(hay: []const u8, needle: []const u8) bool {
/// milliseconds, on every keypress, and the store's own workspace iteration
/// has the same restriction (it can only see handles that were loaded).
///
-/// `new_name` non-null makes it a rename PREVIEW: the same rows, annotated
-/// with the replacement. The seam returns rows, not edits, so `SPC r` shows
-/// what would change and changes nothing — an honest half of rename.
+/// `new_name` non-null makes it a rename EDIT: the same resolved tokens become
+/// half-open byte ranges. The core owns the replacement text and applies every
+/// range in one undo transaction after checking the source revision.
fn references(
arena: std.mem.Allocator,
analyser: *Analyser,
@@ -1149,10 +1149,10 @@ fn references(
const want = offsets.identifierTokenToNameSlice(decl_tree, name_tok);
if (want.len == 0) return;
- const lines: Lines = try .build(arena, tree.source);
- // every row names THIS file (the walk is this file's tokens), so the path
- // is spelled once rather than per hit
- const path = lsp.rel(base, handle.uri.toFsPath(arena) catch return);
+ // Rename consumes exact byte ranges. Reference rows need the source line
+ // and displayed path; avoid building either for the mutating response.
+ const lines: ?Lines = if (new_name == null) try .build(arena, tree.source) else null;
+ const path = if (new_name == null) lsp.rel(base, handle.uri.toFsPath(arena) catch return) else "";
var n: usize = 0;
for (0..tree.tokens.len) |i| {
if (n >= max_rows) return;
@@ -1163,12 +1163,12 @@ fn references(
const d = (declAt(arena, analyser, handle, at) catch continue) orelse continue;
if (!d.eql(target)) continue;
n += 1;
- const r = offsets.tokenToRange(tree, tok, enc);
- const text = if (new_name) |nn|
- try std.fmt.allocPrint(arena, "{s} -> {s} {s}", .{ want, nn, std.mem.trim(u8, lines.line(r.start.line), " \t") })
- else
- lines.line(r.start.line);
- lsp.spanRow(out, path, r.start.line, r.start.character, r.end.line, r.end.character, text);
+ if (new_name != null) {
+ lsp.edit(out, at, at + want.len);
+ } else {
+ const r = offsets.tokenToRange(tree, tok, enc);
+ lsp.spanRow(out, path, r.start.line, r.start.character, r.end.line, r.end.character, lines.?.line(r.start.line));
+ }
}
}