summaryrefslogtreecommitdiff
path: root/core/lsp/Ask.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-23 12:11:43 -0300
committerGabriel Schneider <[email protected]>2026-11-23 14:57:18 -0300
commit3728b4704962672688f0b4461d20481263378165 (patch)
treed5be8ea4c729ac54a60d02412cd218b57940fde8 /core/lsp/Ask.zig
parent62c6caf414fd5a2be556f76eb21d1d6d8d3beadb (diff)
downloadpardes-3728b4704962672688f0b4461d20481263378165.tar.gz
pardes-3728b4704962672688f0b4461d20481263378165.zip
the Changes layer's lines are the pane's text, read-only, and nothing is cut (the user's rulings of 2026-11-23: "all text is regular text", "the ghost line should be regular text too ... but I cant edit them", "don't cut them ... break them following the regular softwrap"; the coordinator's model P71): while a pane's layer is shown, a line a change took away, a changed line's old text and each change's description (`id title author age`, its whole title and its whole author) are lines of the pane's buffer, and the buffer carries their places (`File.State.read_only`, `File.ReadOnly`, whose layer `File.State.layer`), so every motion, selection, search, text object, count, yank, B2 and B3 works on them because they are text, and they wrap by the pane's soft wrap; ONE check where every edit passes (`File.edit`'s `readOnly`: a file at a revision is its whole text, the layer's lines each one; an edit that changes a byte of one, puts any in at its start or inside it, or leaves one on the end of the line above is refused whole, in words on the notice line), edit.zig's second revision check deleted; THE FILE'S TEXT by one function (`File.fileText`, `FileParts`, `fileHash`, `fileEql`, `fileLen`: the buffer itself with no layer, a file with none pays nothing) and two maps (`fileOffset`/`bufferOffset`, `fileRow`/`bufferRow`: a place in one of the layer's lines is after the file line above it), read by every sink: Save and Save-as (Effect.zig), `body`, `addr`, `data`, `xdata`, `sel` and `dot` over 9P (ninep/pane.zig `bodyOf` is the file's text, `fileDot`/`setFileDot`, a 9P write is `File.replaceFile`, a read of a pane with the layer a copy, never a region of the buffer), the dirty checks, Get and a disk reread (`File.load`: the layer out and back), Edit (sam over the file's text, its result a load, its `w` the file's), the language server (its source, the offset asked at, its edits, its places), the syntax parse (`highlightLayered`: the file's text parsed, its colours laid around the layer's lines; context declarations; a worker's parse; query rows' colours and line numbers), jj's own provenance and churn, `Look :N` and `path:N` (the file's line N), the undo journal (an edit journaled in the file's offsets, an undo taken with the layer out; `Journal.record` takes the removed bytes); the layer in and out by `jj.showLayer`/`jj.hideLayer` through `File.relayer` (an edit of kind `.layer` that nothing reading the file hears of, every view's cursor, selection and top line kept by the file's offsets); the layer is the pane's: shown in every view of it and of its twins (`jj.setLanes`); when the editor's whole new text's shortest splice runs into a read-only line where an equal splice does not, that one is taken (`File.clearOfReadOnly`, never back across a read-only line); deleted: `File.fillBody`'s ghost branch, `File.hasGhosts`, `File.bodyWidth`, `jj.fitted`, `jj.row_max`, `jj.showGhosts`, `jj.wordAt`, `Pane.ghosts`/`ghost_text` and `wrapAt`'s `ghost`, Core's per-step sync; the gutter numbers the file's lines; `]g`/`[g` land on a layer's line as on any; the arrow keeps the user's bend (`╰─→`, as nmwnvrow); WIRE 34 (a file pane's `read_only` and `layer`, a description ghost's `author` in the dump and the digest; a clean file's text is dumped while the layer's lines are in its buffer; a dump of 31 loads, a pane whose view showed the layer showing it again: `jj.loaded`); tests (core/jj.zig): the layer's lines as text, read-only (terminal and window), THE FILE'S TEXT (every sink with the layer off and on, byte for byte), the undo across hide and show, 9P in the file's offsets, a client replaying them and a join loading them, a wire-31 dump, a description whole and wrapped in 50 columns, and the old tests of the per-view rows made the pane's; its gate (.scratch/sketch/reorg/pardes-layers-8/g8a, loads 3-7): core-test 942/1108 (166 skipped; the base 936/1102) and shell-test 1150/1153 (3 skipped; the base 1144/1147) in Debug and in ReleaseSafe, behaviour-test 276/276 and --replay, pane-test 182/183, the soak --clients 5 (diverged 0, unequal 0, unlisted 0 at 30/80/207 ms, the corpus 22 of 22, no leak), the gui unit-test 1747/1751 (the known BaselineHarnessMismatch alone), the frame gate 77/77 frames, 0 differ; the perf counts against tree6 40 of 121 over 0.1% where the base's own gate (merge63-g) has 33: against the base this adds body-appends +0.42%, client-key-down +0.18%, terminal on all +0.155%, client-delete-undo +0.14%, deep-sel +0.12%, client-edit-char +0.11% (cause not found yet)
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/lsp/Ask.zig')
-rw-r--r--core/lsp/Ask.zig33
1 files changed, 20 insertions, 13 deletions
diff --git a/core/lsp/Ask.zig b/core/lsp/Ask.zig
index 500f02b5..4d57f21e 100644
--- a/core/lsp/Ask.zig
+++ b/core/lsp/Ask.zig
@@ -62,15 +62,18 @@ pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg_in: []const u8)
(!zig_buf and std.mem.indexOfAny(u8, arg, " \t\r\n\"\\") != null))
return p.reportFailure(id, said.print("Rename: {s} is no name", .{arg}));
}
- var off = if (pane.file) |f| modal.offsetAt(f.content, .{
+ // A place in the file's text, as the server has it (File.fileText: the
+ // `Changes` layer's lines are none of it; one in them is after the file
+ // line above).
+ var off = if (pane.file) |*f| panes.File.fileOffset(f, modal.offsetAt(f.content, .{
.row = @intCast(@max(0, pane.body.cur_row)),
.col = @intCast(@max(0, pane.body.cur_col)),
- }) else 0;
+ })) else 0;
// Def or Refs given a symbol (a 2-1 chord's selection) asks at its
// occurrence nearest the cursor, which a sweep leaves at one end of
// what it selected; the server is asked at a place, never a name.
if ((kind == .definition or kind == .references) and arg.len > 0) {
- const content = pane.file.?.content;
+ const content = panes.File.fileText(&pane.file.?, p.scratch.allocator()) catch |err| return p.reportError(.at(id), lspWord(kind), err);
var nearest: ?usize = null;
var best: usize = 0;
var from: usize = 0;
@@ -188,48 +191,51 @@ fn mapLspEditOffset(edits: []const LspEdit, old: usize) usize {
return new_at + (old - old_at);
}
+/// The server's edits, of the file's text (its offsets; the `Changes`
+/// layer's lines are none of it), made as the file's new text (File.load).
fn applyLspEdits(p: *Pardes, pane: *Pane, revision: u32, edits: []const LspEdit) bool {
const f = if (pane.file) |*file| file else return false;
if (f.revision != revision) return false;
+ const text = panes.File.fileText(f, p.scratch.allocator()) catch return false;
var removed: usize = 0;
var added: usize = 0;
var previous_end: usize = 0;
var same = true;
for (edits) |e| {
- if (e.start < previous_end or e.start > e.end or e.end > f.content.len) return false;
+ if (e.start < previous_end or e.start > e.end or e.end > text.len) return false;
if (e.start == e.end and e.text.len == 0) return false; // an empty insert is a malformed record
removed = std.math.add(usize, removed, e.end - e.start) catch return false;
added = std.math.add(usize, added, e.text.len) catch return false;
previous_end = e.end;
- if (same and !std.mem.eql(u8, f.content[e.start..e.end], e.text)) same = false;
+ if (same and !std.mem.eql(u8, text[e.start..e.end], e.text)) same = false;
}
if (same) return false; // a no-op response earns no undo entry
- const final_len = std.math.add(usize, f.content.len - removed, added) catch return false;
+ const final_len = std.math.add(usize, text.len - removed, added) catch return false;
const replacement = p.gpa.alloc(u8, final_len) catch return false;
- const old_cursor = modal.offsetAt(f.content, .{
+ const old_cursor = panes.File.fileOffset(f, modal.offsetAt(f.content, .{
.row = @intCast(@max(0, pane.body.cur_row)),
.col = @intCast(@max(0, pane.body.cur_col)),
- });
+ }));
const mapped_cursor = mapLspEditOffset(edits, old_cursor);
var read_at: usize = 0;
var write_at: usize = 0;
for (edits) |e| {
- @memcpy(replacement[write_at .. write_at + (e.start - read_at)], f.content[read_at..e.start]);
+ @memcpy(replacement[write_at .. write_at + (e.start - read_at)], text[read_at..e.start]);
write_at += e.start - read_at;
@memcpy(replacement[write_at .. write_at + e.text.len], e.text);
write_at += e.text.len;
read_at = e.end;
}
- @memcpy(replacement[write_at..], f.content[read_at..]);
+ @memcpy(replacement[write_at..], text[read_at..]);
edit.pushUndo(p.editor(), &pane.body) catch {
p.gpa.free(replacement);
return false;
};
- panes.File.setContent(p, f, replacement);
- const cursor = modal.positionAt(f.content, mapped_cursor);
+ panes.File.load(p, f, replacement);
+ const cursor = modal.positionAt(f.content, panes.File.bufferOffset(f, mapped_cursor, false));
pane.body.cur_row = @intCast(cursor.row);
pane.body.cur_col = @intCast(cursor.col);
pane.body.vsel.active = false;
@@ -336,7 +342,8 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void {
// and n and N step it.
const spot = look.parsePathLine(place);
if (!p.look_missed and spot.at.line > 0) if (p.panes[v.active]) |there| if (there.file) |*tf| if (spot.at.line <= panes.File.nlines(p.gpa, tf)) {
- const ls = panes.File.lineStart(p.gpa, tf, spot.at.line - 1);
+ // The server's line is the file's (File.bufferRow).
+ const ls = panes.File.lineStart(p.gpa, tf, panes.File.bufferRow(tf, spot.at.line - 1));
const line = tf.content[ls .. std.mem.indexOfScalarPos(u8, tf.content, ls, '\n') orelse tf.content.len];
const col = @min(spot.at.col -| 1, line.len);
// To its end when the server said it, else the word there.