diff options
Diffstat (limited to 'core/Stream.zig')
| -rw-r--r-- | core/Stream.zig | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/core/Stream.zig b/core/Stream.zig index c5069ed5..4691e192 100644 --- a/core/Stream.zig +++ b/core/Stream.zig @@ -67,10 +67,11 @@ pub const Batch = struct { end: ?End = null, /// A parse's own time on the worker (`parse_ns`). took_ns: u64 = 0, - /// A parse's answer (`parseFor`): the declarations of pane `serial`'s - /// text at `revision`. + /// A parse's answer (`parseFor`): the declarations and symbols of pane + /// `serial`'s text at `revision`. parsed: ?struct { serial: u32, revision: u32 } = null, decls: []syntax.ContextDeclaration = &.{}, + symbols: []syntax.Symbol = &.{}, /// A paint's answer (`paintAhead`): the colours of pane `serial`'s text /// at `revision` from byte `start`, one syntax.Syn a byte. painted: ?struct { serial: u32, revision: u32, start: usize } = null, @@ -83,6 +84,7 @@ pub const Batch = struct { pub fn deinit(b: *const Batch, gpa: std.mem.Allocator) void { gpa.free(b.rows); gpa.free(b.decls); + gpa.free(b.symbols); gpa.free(b.styles); } }; @@ -480,9 +482,9 @@ pub fn parseFor(p: *Pardes, id: usize) void { fn parseWork(io: std.Io, job: *TextJob, ctx: ?*anyopaque, sink: Sink) void { const began = std.Io.Clock.awake.now(io); - const decls: []syntax.ContextDeclaration = syntax.declarationsApart(job.out, job.path, job.source, &job.stop) catch @constCast(&[_]syntax.ContextDeclaration{}); + const made: syntax.Context = syntax.contextApart(job.out, job.path, job.source, &job.stop) catch .{}; const took: u64 = @intCast(@max(0, began.durationTo(std.Io.Clock.awake.now(io)).nanoseconds)); - _ = sink(ctx, .{ .gen = job.gen, .decls = decls, .parsed = .{ .serial = job.serial, .revision = job.revision }, .end = .done, .took_ns = took }); + _ = sink(ctx, .{ .gen = job.gen, .decls = made.declarations, .symbols = made.symbols, .parsed = .{ .serial = job.serial, .revision = job.revision }, .end = .done, .took_ns = took }); } fn now() u64 { @@ -717,7 +719,7 @@ pub fn receive(p: *Pardes, b: *const Batch) void { const id = p.paneBySerial(s.target) orelse return; const q = p.panes[id].?.query orelse return; q.capped = s.state == .capped; - panes.Query.take(p, q, s.kind, b.rows); + panes.Query.take(p, q, s.kind, b.rows, ""); } /// A parse's answer: its task joined; the declarations kept as the pane's @@ -732,12 +734,15 @@ fn receiveParse(p: *Pardes, b: *const Batch, serial: u32, revision: u32) void { t.job.deinit(); }; s.parse_ns = b.took_ns; - if (p.paneBySerial(serial)) |id| if (p.panes[id].?.file) |*f| if (f.revision == revision and b.decls.len > 0) { - if (p.tree_sitter_gpa.dupe(syntax.ContextDeclaration, b.decls)) |copy| { - f.context.replace(p.tree_sitter_gpa, copy, revision); - panes.Query.declsArrived(p, serial); - panes.Pick.declsArrived(p, serial); - } else |_| {} + if (p.paneBySerial(serial)) |id| if (p.panes[id].?.file) |*f| if (f.revision == revision and (b.decls.len > 0 or b.symbols.len > 0)) kept: { + const decls = p.tree_sitter_gpa.dupe(syntax.ContextDeclaration, b.decls) catch break :kept; + const symbols = p.tree_sitter_gpa.dupe(syntax.Symbol, b.symbols) catch { + p.tree_sitter_gpa.free(decls); + break :kept; + }; + f.context.replace(p.tree_sitter_gpa, .{ .declarations = decls, .symbols = symbols }, revision); + panes.Query.declsArrived(p, serial); + panes.Pick.declsArrived(p, serial); }; p.needs_frame = true; // A `Churn` waiting on these declarations (jj.zig). |
