|
|
@ -436,78 +436,3 @@ impl Editor {
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// end => scopes.pop()
|
|
|
|
// end => scopes.pop()
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
#[test]
|
|
|
|
|
|
|
|
fn test_parser() {
|
|
|
|
|
|
|
|
use helix_core::syntax::{HighlightConfiguration, HighlightEvent, Highlighter};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let source_code = include_str!("../test.rs");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let highlight_names: Vec<String> = [
|
|
|
|
|
|
|
|
"attribute",
|
|
|
|
|
|
|
|
"constant",
|
|
|
|
|
|
|
|
"function.builtin",
|
|
|
|
|
|
|
|
"function",
|
|
|
|
|
|
|
|
"keyword",
|
|
|
|
|
|
|
|
"operator",
|
|
|
|
|
|
|
|
"property",
|
|
|
|
|
|
|
|
"punctuation",
|
|
|
|
|
|
|
|
"punctuation.bracket",
|
|
|
|
|
|
|
|
"punctuation.delimiter",
|
|
|
|
|
|
|
|
"string",
|
|
|
|
|
|
|
|
"string.special",
|
|
|
|
|
|
|
|
"tag",
|
|
|
|
|
|
|
|
"type",
|
|
|
|
|
|
|
|
"type.builtin",
|
|
|
|
|
|
|
|
"variable",
|
|
|
|
|
|
|
|
"variable.builtin",
|
|
|
|
|
|
|
|
"variable.parameter",
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.cloned()
|
|
|
|
|
|
|
|
.map(String::from)
|
|
|
|
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let language = helix_syntax::get_language(&helix_syntax::LANG::Rust);
|
|
|
|
|
|
|
|
// let mut parser = tree_sitter::Parser::new();
|
|
|
|
|
|
|
|
// parser.set_language(language).unwrap();
|
|
|
|
|
|
|
|
// let tree = parser.parse(source_code, None).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut highlighter = Highlighter::new();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut config = HighlightConfiguration::new(
|
|
|
|
|
|
|
|
language,
|
|
|
|
|
|
|
|
&std::fs::read_to_string(
|
|
|
|
|
|
|
|
"../helix-syntax/languages/tree-sitter-rust/queries/highlights.scm",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.unwrap(),
|
|
|
|
|
|
|
|
&std::fs::read_to_string(
|
|
|
|
|
|
|
|
"../helix-syntax/languages/tree-sitter-rust/queries/injections.scm",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.unwrap(),
|
|
|
|
|
|
|
|
"", // locals.scm
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config.configure(&highlight_names);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let highlights = highlighter
|
|
|
|
|
|
|
|
.highlight(&config, source_code.as_bytes(), None, |_| None)
|
|
|
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for event in highlights {
|
|
|
|
|
|
|
|
match event.unwrap() {
|
|
|
|
|
|
|
|
HighlightEvent::Source { start, end } => {
|
|
|
|
|
|
|
|
eprintln!("source: {}-{}", start, end);
|
|
|
|
|
|
|
|
// iterate over range char by char
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
HighlightEvent::HighlightStart(s) => {
|
|
|
|
|
|
|
|
eprintln!("highlight style started: {:?}", highlight_names[s.0]);
|
|
|
|
|
|
|
|
// store/push highlight styles
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
HighlightEvent::HighlightEnd => {
|
|
|
|
|
|
|
|
eprintln!("highlight style ended");
|
|
|
|
|
|
|
|
// pop highlight styles
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|