Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
zig-out/
.zig-cache/
zig-cache/
/zig-pkg
12 changes: 7 additions & 5 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,23 @@ pub fn build(b: *std.Build) void {
});
// Grammar packages ship no build.zig; we compile parser.c ourselves.
const grammar_dep = b.dependency("tree_sitter_zig", .{});

const exe = b.addExecutable(.{
.name = "zide",
.root_source_file = b.path("src/main.zig"),
.root_module = b.createModule(.{.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
.link_libc = true,
})
}
);
exe.root_module.addImport("vaxis", vaxis_dep.module("vaxis"));
exe.root_module.addImport("tree-sitter", ts_dep.module("tree-sitter"));
exe.root_module.addImport("tree-sitter", ts_dep.module("tree_sitter"));
exe.root_module.addCSourceFile(.{
.file = grammar_dep.path("src/parser.c"),
.flags = &.{"-std=c11"},
});
exe.root_module.addIncludePath(grammar_dep.path("src"));
exe.linkLibC();

// Size discipline (nullclaw-style): strip symbols outside Debug and let
// the linker drop unreferenced sections.
Expand Down
8 changes: 4 additions & 4 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
// internet connectivity.
.dependencies = .{
.vaxis = .{
.url = "git+https://github.com/rockorager/libvaxis#cc9154d5f4afa3fdfd289157f195ec67804ef437",
.hash = "vaxis-0.5.1-BWNV_MYNCQDO92x2PTpsfv6GwDHmjL98rf6iL3pbMLj4",
.url = "https://github.com/rockorager/libvaxis/archive/6cab03f8a3faeb58bddf334343889a7f685ba7a7.tar.gz",
.hash = "vaxis-0.6.0-BWNV_FcoCgB3Q_LTiQet_GeS23Bd7e224eHloS8PanKZ",
},
.tree_sitter = .{
.url = "git+https://github.com/tree-sitter/zig-tree-sitter#b4b72c903e69998fc88e27e154a5e3cc9166551b",
.hash = "tree_sitter-0.25.0-8heIf51vAQConvVIgvm-9mVIbqh7yabZYqPXfOpS3YoG",
.url = "git+https://github.com/tree-sitter/zig-tree-sitter#0cf58172e61f6fdd16f681cde42b4acb531a23db",
.hash = "tree_sitter-0.26.0-8heIf3CaAQDeVTQc0DMSBhbQAEx5aF-dTen4_LPxMgrv"
},
.tree_sitter_zig = .{
.url = "https://github.com/tree-sitter-grammars/tree-sitter-zig/archive/refs/tags/v1.1.2.tar.gz",
Expand Down
17 changes: 10 additions & 7 deletions src/buffer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ const lsp = @import("lsp.zig");
/// the lines table is always present, possibly empty, so a trailing newline
/// shows as an empty final line and edit logic needs no special cases.
pub const Buffer = struct {
io: std.Io,
alloc: std.mem.Allocator,
buf: std.ArrayListUnmanaged(u8) = .{},
lines: std.ArrayListUnmanaged(Line) = .{},
buf: std.ArrayListUnmanaged(u8) = .empty,
lines: std.ArrayListUnmanaged(Line) = .empty,
hl: syntax.Highlighter,
/// Owned copy of the path this buffer reads from / writes to.
file_name: []u8,
Expand All @@ -24,7 +25,7 @@ pub const Buffer = struct {

/// Per-line git status vs HEAD (gitsigns-style gutter markers).
/// Refreshed on open/save; may be shorter than `lines` after edits.
git_signs: std.ArrayListUnmanaged(Sign) = .{},
git_signs: std.ArrayListUnmanaged(Sign) = .empty,

/// LSP state. `lsp_version` is the didChange counter; `lsp_dirty` is set by
/// every edit and cleared when the editor flushes a didChange on the poll
Expand All @@ -34,7 +35,7 @@ pub const Buffer = struct {
lsp_version: i32 = 0,
/// Diagnostics from the last publishDiagnostics, sorted by (line, col).
/// May be older than the buffer: line indexes are clamped at use sites.
diags: std.ArrayListUnmanaged(lsp.Lsp.Diag) = .{},
diags: std.ArrayListUnmanaged(lsp.Lsp.Diag) = .empty,

/// a-z vim marks (`m{a-z}`); positions are clamped when jumped to, so
/// stale marks after edits degrade gracefully instead of invalidating.
Expand All @@ -46,8 +47,8 @@ pub const Buffer = struct {
/// Undo history: every replaceRange is recorded here. Edits sharing a
/// `seq` form one undo group (one normal-mode command, or one whole
/// insert-mode session — the editor bumps the group on normal keys).
undo_stack: std.ArrayListUnmanaged(UndoEdit) = .{},
redo_stack: std.ArrayListUnmanaged(UndoEdit) = .{},
undo_stack: std.ArrayListUnmanaged(UndoEdit) = .empty,
redo_stack: std.ArrayListUnmanaged(UndoEdit) = .empty,
undo_seq: u32 = 0,
/// Set by the editor on non-insert keypresses; the next recorded edit
/// starts a fresh group.
Expand All @@ -74,6 +75,7 @@ pub const Buffer = struct {
pub const Line = struct { start: u32, end: u32 };

pub fn init(
io: std.Io,
alloc: std.mem.Allocator,
file_name: []const u8,
contents: []const u8,
Expand All @@ -85,6 +87,7 @@ pub const Buffer = struct {
hl.styles.items[0] = hl.baseStyle(); // style id 0 must match the theme

var self = Buffer{
.io = io,
.alloc = alloc,
.hl = hl,
.file_name = try alloc.dupe(u8, file_name),
Expand Down Expand Up @@ -678,7 +681,7 @@ pub const Buffer = struct {
}

pub fn save(self: *Buffer) !void {
try std.fs.cwd().writeFile(.{ .sub_path = self.file_name, .data = self.buf.items });
try std.Io.Dir.cwd().writeFile(self.io, .{ .sub_path = self.file_name, .data = self.buf.items });
self.dirty = false;
self.saved_seq = self.topSeq();
}
Expand Down
Loading