diff options
| author | Gabriel Schneider <[email protected]> | 2026-08-10 09:14:05 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-08-10 09:17:07 -0300 |
| commit | 38e9919a9ea9055538409b388d580c4e4c838434 (patch) | |
| tree | a51ad778189cf007857f0d207f804d59228a023e /src/lsp/lsp_zls.zig | |
| parent | 0d66575a3c888498c7929e2ec345133628c5d63d (diff) | |
| download | pardes-38e9919a9ea9055538409b388d580c4e4c838434.tar.gz pardes-38e9919a9ea9055538409b388d580c4e4c838434.zip | |
fixed lsp rename
Diffstat (limited to 'src/lsp/lsp_zls.zig')
| -rw-r--r-- | src/lsp/lsp_zls.zig | 26 |
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)); + } } } |
