diff options
Diffstat (limited to 'src/File.zig')
| -rw-r--r-- | src/File.zig | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/File.zig b/src/File.zig index cf44c69a..798e3e84 100644 --- a/src/File.zig +++ b/src/File.zig @@ -18,6 +18,7 @@ const limits = @import("memory.zig").limits; const locations = @import("locations.zig"); const Colors = @import("colors.zig"); const Tables = @import("Tables.zig"); +const Stream = @import("Stream.zig"); const Pane = panes.Pane; const Output = panes.Output; const Mini = panes.mini; @@ -1730,10 +1731,22 @@ pub fn refreshHighlights(p: *Pardes) void { need_end <= f.highlight_start + f.highlights.len) { f.syntax_dirty = false; + if (!f.tree_context and pane.colorAlgo() == .source) paintAhead(p, pane, f); continue; } const slack: usize = if (f.highlights.len == 0) 0 else pane.rows; const whole = pane.colorAlgo() == .locations or f.tree_context; + // Painted ahead on a worker (Stream.paintAhead): taken, no parse. + if (!whole and pane.colorAlgo() == .source) if (Stream.takeAhead(p, pane.serial, f.revision, need_start, need_end)) |got| { + if (f.highlights.len > 0) p.tree_sitter_gpa.free(f.highlights); + f.highlights = got.styles; + f.highlight_start = got.start; + f.syntax_dirty = false; + p.stream.painted_ahead += 1; + paintAhead(p, pane, f); + continue; + }; + if (pane.colorAlgo() == .source and !whole) p.stream.painted_on_loop += 1; const start = if (whole) 0 else lineStart(p.gpa, f, f.scroll -| slack); const end = if (whole) f.content.len @@ -1755,9 +1768,28 @@ pub fn refreshHighlights(p: *Pardes) void { f.highlights = new_highlights; f.highlight_start = if (f.highlights.len > 0) start else 0; f.syntax_dirty = false; + if (!whole and pane.colorAlgo() == .source) paintAhead(p, pane, f); } } +/// The stretch a scroll of `pane` is heading into, two views on the way it +/// last went, asked of a worker (Stream.paintAhead) so it is painted by the +/// time the view gets there. +fn paintAhead(p: *Pardes, pane: *Pane, f: *State) void { + const seen = &p.stream.ahead_seen; + if (seen.serial == pane.serial and f.scroll != seen.scroll) seen.dir = if (f.scroll > seen.scroll) 1 else -1; + if (seen.serial != pane.serial) seen.dir = 1; + seen.serial = pane.serial; + seen.scroll = f.scroll; + const rows: usize = pane.rows; + const view = if (seen.dir > 0) f.scroll + 2 * rows else f.scroll -| 2 * rows; + const start = lineStart(p.gpa, f, view -| rows); + const end = @max(start, lineStart(p.gpa, f, view + 2 * rows + SYNTAX_CONTEXT_AFTER_ROWS)); + // Painted already, as far as that goes. + if (f.highlights.len > 0 and start >= f.highlight_start and end <= f.highlight_start + f.highlights.len) return; + Stream.paintAhead(p, pane.serial, f.revision, f.path, f.content, start, end); +} + pub fn supportsContext(pane: *const Pane) bool { const file = pane.file orelse return false; return file.output == null and file.mini == null and syntax.supportsPath(file.path); |
