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 --- Cargo.lock | 42 +++++++++++++++++++++--------------------- Cargo.toml | 16 ++++++++-------- src/app.rs | 22 ++++++++++++++++++---- src/main.rs | 1 + 4 files changed, 48 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a3ecfa2..54ef78d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -231,9 +231,9 @@ dependencies = [ [[package]] name = "tree-sitter-go" -version = "0.19.1" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71967701c8214be4aa77e0260e98361e6fd71ceec1d9d03abb37a22c9f60d0ff" +checksum = "1ad6d11f19441b961af2fda7f12f5d0dac325f6d6de83836a1d3750018cc5114" dependencies = [ "cc", "tree-sitter 0.20.10", @@ -241,12 +241,12 @@ dependencies = [ [[package]] name = "tree-sitter-javascript" -version = "0.21.4" +version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8710a71bc6779e33811a8067bdda3ed08bed1733296ff915e44faf60f8c533d7" +checksum = "d015c02ea98b62c806f7329ff71c383286dfc3a7a7da0cc484f6e42922f73c2c" dependencies = [ "cc", - "tree-sitter 0.21.0", + "tree-sitter 0.20.10", ] [[package]] @@ -260,12 +260,12 @@ dependencies = [ [[package]] name = "tree-sitter-md" -version = "0.2.3" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9c3cfd068f2527250bbd8ff407431164e12b17863e7eafb76e311dd3f96965a" +checksum = "3c20d3ef8d202430b644a307e6299d84bf8ed87fa1b796e4638f8805a595060c" dependencies = [ "cc", - "tree-sitter 0.21.0", + "tree-sitter 0.20.10", ] [[package]] @@ -279,42 +279,42 @@ dependencies = [ [[package]] name = "tree-sitter-python" -version = "0.21.0" +version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4066c6cf678f962f8c2c4561f205945c84834cce73d981e71392624fdc390a9" +checksum = "e6c93b1b1fbd0d399db3445f51fd3058e43d0b4dcff62ddbdb46e66550978aa5" dependencies = [ "cc", - "tree-sitter 0.21.0", + "tree-sitter 0.20.10", ] [[package]] name = "tree-sitter-ruby" -version = "0.21.0" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0031f687c0772f2dad7b77104c43428611099a1804c81244ada21560f41f0b1" +checksum = "44d50ef383469df8485f024c5fb01faced8cb90368192a7ba02605b43b2427fe" dependencies = [ "cc", - "tree-sitter 0.21.0", + "tree-sitter 0.20.10", ] [[package]] name = "tree-sitter-rust" -version = "0.21.2" +version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "277690f420bf90741dea984f3da038ace46c4fe6047cba57a66822226cde1c93" +checksum = "b0832309b0b2b6d33760ce5c0e818cb47e1d72b468516bfe4134408926fa7594" dependencies = [ "cc", - "tree-sitter 0.21.0", + "tree-sitter 0.20.10", ] [[package]] name = "tree-sitter-typescript" -version = "0.21.2" +version = "0.20.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecb35d98a688378e56c18c9c159824fd16f730ccbea19aacf4f206e5d5438ed9" +checksum = "c8bc1d2c24276a48ef097a71b56888ac9db63717e8f8d0b324668a27fd619670" dependencies = [ "cc", - "tree-sitter 0.21.0", + "tree-sitter 0.20.10", ] [[package]] @@ -323,7 +323,7 @@ version = "0.1.0" dependencies = [ "console", "notify", - "tree-sitter 0.21.0", + "tree-sitter 0.20.10", "tree-sitter-elm", "tree-sitter-go", "tree-sitter-javascript", diff --git a/Cargo.toml b/Cargo.toml index 73ec928..b8fd1b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,17 +7,17 @@ edition = "2021" [dependencies] tree-sitter-elm = "5.6.3" -tree-sitter-ruby = "0.21" -tree-sitter-rust = "0.21" -tree-sitter = "0.21" +tree-sitter-ruby = "0.20" +tree-sitter-rust = "0.20" +tree-sitter = "0.20" console = "^0.15" -tree-sitter-go = "0.19.1" -tree-sitter-typescript = "0.21" -tree-sitter-javascript = "0.21" +tree-sitter-go = "0.20" +tree-sitter-typescript = "0.20" +tree-sitter-javascript = "0.20" tree-sitter-mdx = { git = "https://github.com/jlopezcur/tree-sitter-mdx" } tree-sitter-json = { git = "https://github.com/tree-sitter/tree-sitter-json" } -tree-sitter-python = "0.21" -tree-sitter-md = "0.2.3" +tree-sitter-python = "0.20" +tree-sitter-md = "0.1" # tree-sitter-cobol = { path = "../../tree-sitter-cobol/" } [dependencies.notify] 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