diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/app.rs | 22 | ||||
-rw-r--r-- | src/main.rs | 1 |
2 files changed, 19 insertions, 4 deletions
@@ -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 | ||
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() { | |||
19 | 19 | ||
20 | let language = match args.next().as_ref().map(|s| s.as_str()) { | 20 | let language = match args.next().as_ref().map(|s| s.as_str()) { |
21 | Some("rust") => tree_sitter_rust::language(), | 21 | Some("rust") => tree_sitter_rust::language(), |
22 | Some("go") => tree_sitter_go::language(), | ||
22 | Some("tsx") | Some("typescript") => tree_sitter_typescript::language_tsx(), | 23 | Some("tsx") | Some("typescript") => tree_sitter_typescript::language_tsx(), |
23 | Some("javascript") => tree_sitter_javascript::language(), | 24 | Some("javascript") => tree_sitter_javascript::language(), |
24 | Some("python") => tree_sitter_python::language(), | 25 | Some("python") => tree_sitter_python::language(), |