feat: only use partial tree-sitter reparsing if parsing take more than 5ms
This commit is contained in:
parent
e9a7d681f2
commit
efc5546488
1 changed files with 9 additions and 0 deletions
|
@ -36,6 +36,8 @@ const scroll_step_small = 3;
|
|||
const scroll_cursor_min_border_distance = 5;
|
||||
|
||||
const double_click_time_ms = 350;
|
||||
const syntax_refresh_update_time = 5; // ms
|
||||
|
||||
pub const max_matches = if (builtin.mode == std.builtin.OptimizeMode.Debug) 10_000 else 100_000;
|
||||
pub const max_match_lines = 15;
|
||||
pub const max_match_batch = if (builtin.mode == std.builtin.OptimizeMode.Debug) 100 else 1000;
|
||||
|
@ -248,6 +250,7 @@ pub const Editor = struct {
|
|||
syntax: ?*syntax = null,
|
||||
syntax_refresh_full: bool = false,
|
||||
syntax_token: usize = 0,
|
||||
syntax_refresh_update: bool = false,
|
||||
|
||||
style_cache: ?StyleCache = null,
|
||||
style_cache_theme: []const u8 = "",
|
||||
|
@ -3062,12 +3065,18 @@ pub const Editor = struct {
|
|||
if (self.syntax_token == token)
|
||||
return;
|
||||
if (self.syntax) |syn| {
|
||||
if (!self.syntax_refresh_update)
|
||||
self.syntax_refresh_full = true;
|
||||
if (self.syntax_refresh_full) {
|
||||
const start_time = std.time.milliTimestamp();
|
||||
var content = std.ArrayList(u8).init(self.allocator);
|
||||
defer content.deinit();
|
||||
try root.store(content.writer(), eol_mode);
|
||||
try syn.refresh_full(content.items);
|
||||
self.syntax_refresh_full = false;
|
||||
const end_time = std.time.milliTimestamp();
|
||||
if (end_time - start_time > syntax_refresh_update_time)
|
||||
self.syntax_refresh_update = true;
|
||||
} else {
|
||||
try syn.refresh_from_buffer(root, self.metrics);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue