diff options
-rw-r--r-- | Cargo.lock | 42 | ||||
-rw-r--r-- | Cargo.toml | 16 | ||||
-rw-r--r-- | src/app.rs | 22 | ||||
-rw-r--r-- | src/main.rs | 1 |
4 files changed, 48 insertions, 33 deletions
@@ -231,9 +231,9 @@ dependencies = [ | |||
231 | 231 | ||
232 | [[package]] | 232 | [[package]] |
233 | name = "tree-sitter-go" | 233 | name = "tree-sitter-go" |
234 | version = "0.19.1" | 234 | version = "0.20.0" |
235 | source = "registry+https://github.com/rust-lang/crates.io-index" | 235 | source = "registry+https://github.com/rust-lang/crates.io-index" |
236 | checksum = "71967701c8214be4aa77e0260e98361e6fd71ceec1d9d03abb37a22c9f60d0ff" | 236 | checksum = "1ad6d11f19441b961af2fda7f12f5d0dac325f6d6de83836a1d3750018cc5114" |
237 | dependencies = [ | 237 | dependencies = [ |
238 | "cc", | 238 | "cc", |
239 | "tree-sitter 0.20.10", | 239 | "tree-sitter 0.20.10", |
@@ -241,12 +241,12 @@ dependencies = [ | |||
241 | 241 | ||
242 | [[package]] | 242 | [[package]] |
243 | name = "tree-sitter-javascript" | 243 | name = "tree-sitter-javascript" |
244 | version = "0.21.4" | 244 | version = "0.20.4" |
245 | source = "registry+https://github.com/rust-lang/crates.io-index" | 245 | source = "registry+https://github.com/rust-lang/crates.io-index" |
246 | checksum = "8710a71bc6779e33811a8067bdda3ed08bed1733296ff915e44faf60f8c533d7" | 246 | checksum = "d015c02ea98b62c806f7329ff71c383286dfc3a7a7da0cc484f6e42922f73c2c" |
247 | dependencies = [ | 247 | dependencies = [ |
248 | "cc", | 248 | "cc", |
249 | "tree-sitter 0.21.0", | 249 | "tree-sitter 0.20.10", |
250 | ] | 250 | ] |
251 | 251 | ||
252 | [[package]] | 252 | [[package]] |
@@ -260,12 +260,12 @@ dependencies = [ | |||
260 | 260 | ||
261 | [[package]] | 261 | [[package]] |
262 | name = "tree-sitter-md" | 262 | name = "tree-sitter-md" |
263 | version = "0.2.3" | 263 | version = "0.1.7" |
264 | source = "registry+https://github.com/rust-lang/crates.io-index" | 264 | source = "registry+https://github.com/rust-lang/crates.io-index" |
265 | checksum = "d9c3cfd068f2527250bbd8ff407431164e12b17863e7eafb76e311dd3f96965a" | 265 | checksum = "3c20d3ef8d202430b644a307e6299d84bf8ed87fa1b796e4638f8805a595060c" |
266 | dependencies = [ | 266 | dependencies = [ |
267 | "cc", | 267 | "cc", |
268 | "tree-sitter 0.21.0", | 268 | "tree-sitter 0.20.10", |
269 | ] | 269 | ] |
270 | 270 | ||
271 | [[package]] | 271 | [[package]] |
@@ -279,42 +279,42 @@ dependencies = [ | |||
279 | 279 | ||
280 | [[package]] | 280 | [[package]] |
281 | name = "tree-sitter-python" | 281 | name = "tree-sitter-python" |
282 | version = "0.21.0" | 282 | version = "0.20.4" |
283 | source = "registry+https://github.com/rust-lang/crates.io-index" | 283 | source = "registry+https://github.com/rust-lang/crates.io-index" |
284 | checksum = "b4066c6cf678f962f8c2c4561f205945c84834cce73d981e71392624fdc390a9" | 284 | checksum = "e6c93b1b1fbd0d399db3445f51fd3058e43d0b4dcff62ddbdb46e66550978aa5" |
285 | dependencies = [ | 285 | dependencies = [ |
286 | "cc", | 286 | "cc", |
287 | "tree-sitter 0.21.0", | 287 | "tree-sitter 0.20.10", |
288 | ] | 288 | ] |
289 | 289 | ||
290 | [[package]] | 290 | [[package]] |
291 | name = "tree-sitter-ruby" | 291 | name = "tree-sitter-ruby" |
292 | version = "0.21.0" | 292 | version = "0.20.1" |
293 | source = "registry+https://github.com/rust-lang/crates.io-index" | 293 | source = "registry+https://github.com/rust-lang/crates.io-index" |
294 | checksum = "c0031f687c0772f2dad7b77104c43428611099a1804c81244ada21560f41f0b1" | 294 | checksum = "44d50ef383469df8485f024c5fb01faced8cb90368192a7ba02605b43b2427fe" |
295 | dependencies = [ | 295 | dependencies = [ |
296 | "cc", | 296 | "cc", |
297 | "tree-sitter 0.21.0", | 297 | "tree-sitter 0.20.10", |
298 | ] | 298 | ] |
299 | 299 | ||
300 | [[package]] | 300 | [[package]] |
301 | name = "tree-sitter-rust" | 301 | name = "tree-sitter-rust" |
302 | version = "0.21.2" | 302 | version = "0.20.4" |
303 | source = "registry+https://github.com/rust-lang/crates.io-index" | 303 | source = "registry+https://github.com/rust-lang/crates.io-index" |
304 | checksum = "277690f420bf90741dea984f3da038ace46c4fe6047cba57a66822226cde1c93" | 304 | checksum = "b0832309b0b2b6d33760ce5c0e818cb47e1d72b468516bfe4134408926fa7594" |
305 | dependencies = [ | 305 | dependencies = [ |
306 | "cc", | 306 | "cc", |
307 | "tree-sitter 0.21.0", | 307 | "tree-sitter 0.20.10", |
308 | ] | 308 | ] |
309 | 309 | ||
310 | [[package]] | 310 | [[package]] |
311 | name = "tree-sitter-typescript" | 311 | name = "tree-sitter-typescript" |
312 | version = "0.21.2" | 312 | version = "0.20.5" |
313 | source = "registry+https://github.com/rust-lang/crates.io-index" | 313 | source = "registry+https://github.com/rust-lang/crates.io-index" |
314 | checksum = "ecb35d98a688378e56c18c9c159824fd16f730ccbea19aacf4f206e5d5438ed9" | 314 | checksum = "c8bc1d2c24276a48ef097a71b56888ac9db63717e8f8d0b324668a27fd619670" |
315 | dependencies = [ | 315 | dependencies = [ |
316 | "cc", | 316 | "cc", |
317 | "tree-sitter 0.21.0", | 317 | "tree-sitter 0.20.10", |
318 | ] | 318 | ] |
319 | 319 | ||
320 | [[package]] | 320 | [[package]] |
@@ -323,7 +323,7 @@ version = "0.1.0" | |||
323 | dependencies = [ | 323 | dependencies = [ |
324 | "console", | 324 | "console", |
325 | "notify", | 325 | "notify", |
326 | "tree-sitter 0.21.0", | 326 | "tree-sitter 0.20.10", |
327 | "tree-sitter-elm", | 327 | "tree-sitter-elm", |
328 | "tree-sitter-go", | 328 | "tree-sitter-go", |
329 | "tree-sitter-javascript", | 329 | "tree-sitter-javascript", |
@@ -7,17 +7,17 @@ edition = "2021" | |||
7 | 7 | ||
8 | [dependencies] | 8 | [dependencies] |
9 | tree-sitter-elm = "5.6.3" | 9 | tree-sitter-elm = "5.6.3" |
10 | tree-sitter-ruby = "0.21" | 10 | tree-sitter-ruby = "0.20" |
11 | tree-sitter-rust = "0.21" | 11 | tree-sitter-rust = "0.20" |
12 | tree-sitter = "0.21" | 12 | tree-sitter = "0.20" |
13 | console = "^0.15" | 13 | console = "^0.15" |
14 | tree-sitter-go = "0.19.1" | 14 | tree-sitter-go = "0.20" |
15 | tree-sitter-typescript = "0.21" | 15 | tree-sitter-typescript = "0.20" |
16 | tree-sitter-javascript = "0.21" | 16 | tree-sitter-javascript = "0.20" |
17 | tree-sitter-mdx = { git = "https://github.com/jlopezcur/tree-sitter-mdx" } | 17 | tree-sitter-mdx = { git = "https://github.com/jlopezcur/tree-sitter-mdx" } |
18 | tree-sitter-json = { git = "https://github.com/tree-sitter/tree-sitter-json" } | 18 | tree-sitter-json = { git = "https://github.com/tree-sitter/tree-sitter-json" } |
19 | tree-sitter-python = "0.21" | 19 | tree-sitter-python = "0.20" |
20 | tree-sitter-md = "0.2.3" | 20 | tree-sitter-md = "0.1" |
21 | # tree-sitter-cobol = { path = "../../tree-sitter-cobol/" } | 21 | # tree-sitter-cobol = { path = "../../tree-sitter-cobol/" } |
22 | 22 | ||
23 | [dependencies.notify] | 23 | [dependencies.notify] |
@@ -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(), |