From 3ba4e8debabbcf4a82a60860a658a30292a86a04 Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 23 Jul 2024 09:57:01 +0100 Subject: add query-errors to UI, revert to ts 0.20 --- src/app.rs | 22 ++++++++++++++++++---- src/main.rs | 1 + 2 files changed, 19 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/app.rs b/src/app.rs index 285034b..e299ef8 100644 --- a/src/app.rs +++ b/src/app.rs @@ -15,6 +15,7 @@ pub struct App { path: PathBuf, query: Option, query_path: Option, + query_error: Option, src: Vec, tree: Tree, } @@ -29,13 +30,20 @@ impl App { let path = path.as_ref().to_owned(); let mut parser = Parser::new(); - parser.set_language(&language).unwrap(); + parser.set_language(language).unwrap(); let tree = parser.parse(&src, None).unwrap(); let query_path = query_path.map(|q| q.as_ref().to_owned()); - let query = query_path.as_ref().map(|p| { + let mut query_error = None; + let query = query_path.as_ref().and_then(|p| { let query_src = std::fs::read_to_string(&p).expect("unable to read query"); - Query::new(&language, &query_src).expect("query parse error") + match Query::new(language, &query_src) { + Ok(q) => Some(q), + Err(e) => { + query_error = Some(e.to_string()); + None + } + } }); Self { @@ -43,6 +51,7 @@ impl App { path, query, query_path, + query_error, src: src.to_owned(), tree, language, @@ -148,7 +157,7 @@ impl App { write!( tree_string, "@{} ", - style(capture_names[*index as usize]).magenta() + style(&capture_names[*index as usize]).magenta() ) .unwrap(); } @@ -219,6 +228,11 @@ impl App { term.clear_to_end_of_screen().unwrap(); term.write_line("(C-c) quit").unwrap(); + + if let Some(err) = self.query_error.as_ref() { + term.write_line(&format!("{}: {err}", style("query error").red())) + .unwrap(); + } term.clear_to_end_of_screen().unwrap(); } diff --git a/src/main.rs b/src/main.rs index ce7c84c..9d51fc3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,7 @@ fn main() { let language = match args.next().as_ref().map(|s| s.as_str()) { Some("rust") => tree_sitter_rust::language(), + Some("go") => tree_sitter_go::language(), Some("tsx") | Some("typescript") => tree_sitter_typescript::language_tsx(), Some("javascript") => tree_sitter_javascript::language(), Some("python") => tree_sitter_python::language(), -- cgit v1.2.3