@@ -216,3 +216,118 @@ impl Editor {
220+// TODO: language configs:
221+// tabSize, fileExtension etc, mapping to tree sitter parser
223+// map tree sitter highlights to color values
225+// TODO: expand highlight thing so we're able to render only viewport range
226+// TODO: async: maybe pre-cache scopes as empty so we render all graphemes initially as regular
227+////text until calc finishes
228+// TODO: scope matching: biggest union match? [string] & [html, string], [string, html] & [ string, html]
229+// can do this by sorting our theme matches based on array len (longest first) then stopping at the
230+// first rule that matches (rule.all(|scope| scopes.contains(scope)))
234+// for span in spans {
235+// start(scope) => scopes.push(scope)
237+// let text = rope.slice(span.start..span.end);
238+// let style = calculate_style(scopes);
239+// for each grapheme in text.graphemes() {
240+// // if newline += lines, continue
242+// if state.selection.ranges().any(|range| range.contains(char_index)) {
243+// if exactly on cursor {
245+// if on primary cursor? {
247+// modify style temporarily
252+// // if tab, draw tab width
253+// // draw(visual_x, line, grapheme, style)
254+// // increment visual_x by grapheme_width(grapheme)
255+// // increment char_index by grapheme.len_chars()
257+// end => scopes.pop()
261+ use tree_sitter_highlight::{HighlightConfiguration, HighlightEvent, Highlighter};
263+ let source_code = include_str!("./main.rs");
265+ let highlight_names: Vec<String> = [
274+ "punctuation.bracket",
275+ "punctuation.delimiter",
283+ "variable.parameter",
290+ let language = helix_syntax::get_language(&helix_syntax::LANG::Rust);
291+ // let mut parser = tree_sitter::Parser::new();
292+ // parser.set_language(language).unwrap();
293+ // let tree = parser.parse(source_code, None).unwrap();
295+ let mut highlighter = Highlighter::new();
297+ let mut config = HighlightConfiguration::new(
299+ &std::fs::read_to_string(
300+ "../helix-syntax/languages/tree-sitter-rust/queries/highlights.scm",
303+ &std::fs::read_to_string(
304+ "../helix-syntax/languages/tree-sitter-rust/queries/injections.scm",
311+ config.configure(&highlight_names);
313+ let highlights = highlighter
314+ .highlight(&config, source_code.as_bytes(), None, |_| None)
317+ for event in highlights {
318+ match event.unwrap() {
319+ HighlightEvent::Source { start, end } => {
320+ eprintln!("source: {}-{}", start, end);
321+ // iterate over range char by char
323+ HighlightEvent::HighlightStart(s) => {
324+ eprintln!("highlight style started: {:?}", highlight_names[s.0]);
325+ // store/push highlight styles
327+ HighlightEvent::HighlightEnd => {
328+ eprintln!("highlight style ended");
329+ // pop highlight styles