🏡 index : ~doyle/rgit.git

author Jordan Doyle <jordan@doyle.la> 2024-09-30 4:21:52.0 +04:00:00
committer Jordan Doyle <jordan@doyle.la> 2024-09-30 4:21:52.0 +04:00:00
commit
50523442c15afc9d0b459eef243dcd1630287063 [patch]
tree
208c6fc939a6019b81e947da948f744281bbfb6e
parent
d8bd2fb032935269f6b27987924a18acfbc82fb1
download
50523442c15afc9d0b459eef243dcd1630287063.tar.gz

Add highlighting timeout



Diff

 src/syntax_highlight.rs | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/syntax_highlight.rs b/src/syntax_highlight.rs
index 139e598..065194d 100644
--- a/src/syntax_highlight.rs
+++ a/src/syntax_highlight.rs
@@ -8,7 +8,7 @@
};

use comrak::adapters::SyntaxHighlighterAdapter;
use tracing::debug;
use tracing::{debug, error};
use tree_sitter_grammar_repository::{Grammar, Language};
use tree_sitter_highlight::{HighlightConfiguration, HighlightEvent, Highlighter};

@@ -194,10 +194,30 @@
    };

    HIGHLIGHTER.with_borrow_mut(|highlighter| {
        let mut spans = highlighter.highlight(config, content.as_bytes(), None, |injection| {
        highlighter.parser().reset();

        let spans = highlighter.highlight(config, content.as_bytes(), None, |injection| {
            debug!(injection, "Highlighter switch requested");
            fetch_highlighter_config_by_token(injection)
        })?;
        });

        let mut spans = match spans {
            Ok(v) => v,
            Err(error) => {
                error!(
                    ?error,
                    "Failed to run highlighter, falling back to plaintext"
                );

                for line in content.lines() {
                    out.push_str(line_prefix);
                    v_htmlescape::b_escape(line.as_bytes(), out);
                    out.push_str(line_suffix);
                }

                return Ok(());
            }
        };

        let mut tag_open = true;
        out.push_str(line_prefix);