aboutsummaryrefslogtreecommitdiff
path: root/src/app.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/app.rs')
-rw-r--r--src/app.rs22
1 files changed, 18 insertions, 4 deletions
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 {
15 path: PathBuf, 15 path: PathBuf,
16 query: Option<Query>, 16 query: Option<Query>,
17 query_path: Option<PathBuf>, 17 query_path: Option<PathBuf>,
18 query_error: Option<String>,
18 src: Vec<u8>, 19 src: Vec<u8>,
19 tree: Tree, 20 tree: Tree,
20} 21}
@@ -29,13 +30,20 @@ impl App {
29 let path = path.as_ref().to_owned(); 30 let path = path.as_ref().to_owned();
30 31
31 let mut parser = Parser::new(); 32 let mut parser = Parser::new();
32 parser.set_language(&language).unwrap(); 33 parser.set_language(language).unwrap();
33 34
34 let tree = parser.parse(&src, None).unwrap(); 35 let tree = parser.parse(&src, None).unwrap();
35 let query_path = query_path.map(|q| q.as_ref().to_owned()); 36 let query_path = query_path.map(|q| q.as_ref().to_owned());
36 let query = query_path.as_ref().map(|p| { 37 let mut query_error = None;
38 let query = query_path.as_ref().and_then(|p| {
37 let query_src = std::fs::read_to_string(&p).expect("unable to read query"); 39 let query_src = std::fs::read_to_string(&p).expect("unable to read query");
38 Query::new(&language, &query_src).expect("query parse error") 40 match Query::new(language, &query_src) {
41 Ok(q) => Some(q),
42 Err(e) => {
43 query_error = Some(e.to_string());
44 None
45 }
46 }
39 }); 47 });
40 48
41 Self { 49 Self {
@@ -43,6 +51,7 @@ impl App {
43 path, 51 path,
44 query, 52 query,
45 query_path, 53 query_path,
54 query_error,
46 src: src.to_owned(), 55 src: src.to_owned(),
47 tree, 56 tree,
48 language, 57 language,
@@ -148,7 +157,7 @@ impl App {
148 write!( 157 write!(
149 tree_string, 158 tree_string,
150 "@{} ", 159 "@{} ",
151 style(capture_names[*index as usize]).magenta() 160 style(&capture_names[*index as usize]).magenta()
152 ) 161 )
153 .unwrap(); 162 .unwrap();
154 } 163 }
@@ -219,6 +228,11 @@ impl App {
219 term.clear_to_end_of_screen().unwrap(); 228 term.clear_to_end_of_screen().unwrap();
220 229
221 term.write_line("(C-c) quit").unwrap(); 230 term.write_line("(C-c) quit").unwrap();
231
232 if let Some(err) = self.query_error.as_ref() {
233 term.write_line(&format!("{}: {err}", style("query error").red()))
234 .unwrap();
235 }
222 term.clear_to_end_of_screen().unwrap(); 236 term.clear_to_end_of_screen().unwrap();
223 } 237 }
224 238