Skip to content

Commit

Permalink
feat: performance upgrade on syntasx highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
wllfaria committed May 9, 2024
1 parent 6c110d2 commit feea9c3
Show file tree
Hide file tree
Showing 15 changed files with 343 additions and 57 deletions.
81 changes: 81 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ reqwest = { version = "0.12", features = ["json"] }
ratatui = { version = "0.26.1", features = ["all-widgets", "crossterm"] }
tree-sitter = "0.22.5"
tree-sitter-json = "0.21"
divan = "0.1.14"
lazy_static = "1.4"
2 changes: 1 addition & 1 deletion reqtui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ serde_json.workspace = true
ratatui.workspace = true
tree-sitter.workspace = true
tree-sitter-json.workspace = true
lazy_static.workspace = true

ropey = "1.6.1"
lazy_static = "1.4"

[build-dependencies]
cc="*"
12 changes: 8 additions & 4 deletions reqtui/src/syntax/highlighter.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use lazy_static::lazy_static;
use ratatui::style::Style;

use std::{collections::HashMap, fmt::Debug, sync::RwLock};
use std::{
collections::{HashMap, VecDeque},
fmt::Debug,
sync::RwLock,
};

use tree_sitter::{Parser, Query, QueryCursor, Tree};

Expand Down Expand Up @@ -52,8 +56,8 @@ impl Highlighter {
buffer: &str,
tree: Option<&Tree>,
tokens: &HashMap<String, Style>,
) -> Vec<ColorInfo> {
let mut colors = Vec::new();
) -> VecDeque<ColorInfo> {
let mut colors = VecDeque::new();

if let Some(tree) = tree {
let mut cursor = QueryCursor::new();
Expand All @@ -66,7 +70,7 @@ impl Highlighter {
let end = node.end_byte();
let capture_name = self.query.capture_names()[cap.index as usize];
if let Some(style) = tokens.get(capture_name) {
colors.push(ColorInfo {
colors.push_back(ColorInfo {
start,
end,
style: *style,
Expand Down
3 changes: 0 additions & 3 deletions reqtui/src/syntax/queries/json/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
"}"
] @punctuation.bracket

("\"" @conceal
(#set! conceal ""))

(escape_sequence) @string.escape

((escape_sequence) @conceal
Expand Down
4 changes: 4 additions & 0 deletions reqtui/src/text_object/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ impl Cursor {
self.snapback_col = col;
}

pub fn move_to_row(&mut self, row: usize) {
self.row = row;
}

pub fn row(&self) -> usize {
self.row
}
Expand Down
6 changes: 6 additions & 0 deletions tui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ reqwest.workspace = true
serde_json.workspace = true
ratatui.workspace = true
tree-sitter.workspace = true
divan.workspace = true
lazy_static.workspace = true

futures = "0.3.30"
tui-big-text = { version = "0.4.3" }
Expand All @@ -31,3 +33,7 @@ name = "rqt"
test = false
bench = false
path = "src/main.rs"

[[bench]]
name = "api_explorer"
harness = false
Loading

0 comments on commit feea9c3

Please sign in to comment.