summaryrefslogtreecommitdiff
path: root/src/Editor.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 07:24:58 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commitf233d87376bbdfde3918f803e31b52a214ea9bdb (patch)
treef62cc8df1c9c4ad3c635b189631bbda08f9086ae /src/Editor.zig
parent946e96c0ec793d6b546da8ebef19555d639ccda6 (diff)
downloadpardes-f233d87376bbdfde3918f803e31b52a214ea9bdb.tar.gz
pardes-f233d87376bbdfde3918f803e31b52a214ea9bdb.zip
+171 -73 lib: the tree-sitter walks run in the library on a parse its caller hands in (docs/next-editor.md): `key(a, syn, k)` and `run(a, syn, act)` take a `?*Syntax`, which keeps the grammar it parses in, the tree, made on the first walk after the text changes, and helix's object_selections (Alt-o's history, for Alt-i to go back the way it came) in the page allocator; with one, Alt-o, Alt-i, Alt-n, Alt-p, Alt-a, Alt-I, Alt-e, Alt-b and `]f` and kin run in the library, and `mif` and kin find the grammar's textobjects; without, they come back as actions, as before; normal.nodeTree is the parse they read, a file's (fileTree) in pardes and the one handed in in the library, `Editor.Tree` its tree, path and history, so nodeSelect and objectJump take the editor's context and are textAction's, textRole saying the walks are the text's with a parse at hand, and edit.textobjectSelect reads it too; NodeStep moves to Editor.zig (File.zig names it); nothing a pane does changes; hxlib hands each case a parse with no grammar (a case's text has none): 538 of 658 compared with 0 mismatches (expand_node's one case moved from the caller's), --parity 618 of 738 with 0 mismatches; test/lib: Alt-o and Alt-i on C, back the way they came, `maf` from a textobjects query handed in, and Alt-o without a parse the caller's; core-test 811 of 950, shell-test 990 of 993, hxdiff 658 / parity 738 / hxgolf 124 with 0 mismatches, replicas pass, lib-test pass
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'src/Editor.zig')
-rw-r--r--src/Editor.zig13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/Editor.zig b/src/Editor.zig
index 014d1923..b7c7057d 100644
--- a/src/Editor.zig
+++ b/src/Editor.zig
@@ -12,9 +12,18 @@ const Registers = @import("Registers.zig");
/// on this at compile time, so the library never compiles the core.
pub const lib = @import("pardes_config").lib;
const Pardes = if (lib) void else @import("Core.zig");
+const Syntax = if (lib) @import("lib_editor.zig").Syntax else void;
+const modal = @import("modal.zig");
const Editor = @This();
+/// A text's parse as the tree-sitter walks read it (normal.nodeTree): the
+/// tree, a path its grammar's queries are found by, and helix's
+/// object_selections, what Alt-o grew from for Alt-i to go back to, its
+/// ranges in `gpa`. Dropped with the tree when the text changes.
+pub const Tree = struct { root: *anyopaque, path: []const u8, history: *std.ArrayList(NodeStep), gpa: std.mem.Allocator };
+pub const NodeStep = struct { ranges: []modal.Selection, primary: usize };
+
gpa: std.mem.Allocator,
/// What an edit makes and drops: the update's scratch.
scratch: std.mem.Allocator,
@@ -39,6 +48,9 @@ p: if (lib) void else *Pardes,
/// The library's: an edit failed (its allocator ran out) and the key is
/// refused.
failed: if (lib) *bool else void,
+/// The library's: the parse its caller handed in, which the tree-sitter
+/// walks read; null, and they are the caller's (`textRole`).
+syntax: if (lib) ?*Syntax else void,
pub fn of(p: *Pardes) Editor {
return .{
@@ -53,6 +65,7 @@ pub fn of(p: *Pardes) Editor {
.retired_edit = &p.retired_edit,
.p = p,
.failed = {},
+ .syntax = {},
};
}