aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay <[email protected]>2024-07-23 09:57:01 +0100
committerAkshay <[email protected]>2024-07-23 09:57:01 +0100
commit3ba4e8debabbcf4a82a60860a658a30292a86a04 (patch)
tree65f44636911d1a6bf1c9e489a94fc830c3cce1fd
parentb3ecf2945b56c56783ade714b96ba031b7f1e243 (diff)
add query-errors to UI, revert to ts 0.20HEADmaster
-rw-r--r--Cargo.lock42
-rw-r--r--Cargo.toml16
-rw-r--r--src/app.rs22
-rw-r--r--src/main.rs1
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 = [
231 231
232[[package]] 232[[package]]
233name = "tree-sitter-go" 233name = "tree-sitter-go"
234version = "0.19.1" 234version = "0.20.0"
235source = "registry+https://github.com/rust-lang/crates.io-index" 235source = "registry+https://github.com/rust-lang/crates.io-index"
236checksum = "71967701c8214be4aa77e0260e98361e6fd71ceec1d9d03abb37a22c9f60d0ff" 236checksum = "1ad6d11f19441b961af2fda7f12f5d0dac325f6d6de83836a1d3750018cc5114"
237dependencies = [ 237dependencies = [
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]]
243name = "tree-sitter-javascript" 243name = "tree-sitter-javascript"
244version = "0.21.4" 244version = "0.20.4"
245source = "registry+https://github.com/rust-lang/crates.io-index" 245source = "registry+https://github.com/rust-lang/crates.io-index"
246checksum = "8710a71bc6779e33811a8067bdda3ed08bed1733296ff915e44faf60f8c533d7" 246checksum = "d015c02ea98b62c806f7329ff71c383286dfc3a7a7da0cc484f6e42922f73c2c"
247dependencies = [ 247dependencies = [
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]]
262name = "tree-sitter-md" 262name = "tree-sitter-md"
263version = "0.2.3" 263version = "0.1.7"
264source = "registry+https://github.com/rust-lang/crates.io-index" 264source = "registry+https://github.com/rust-lang/crates.io-index"
265checksum = "d9c3cfd068f2527250bbd8ff407431164e12b17863e7eafb76e311dd3f96965a" 265checksum = "3c20d3ef8d202430b644a307e6299d84bf8ed87fa1b796e4638f8805a595060c"
266dependencies = [ 266dependencies = [
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]]
281name = "tree-sitter-python" 281name = "tree-sitter-python"
282version = "0.21.0" 282version = "0.20.4"
283source = "registry+https://github.com/rust-lang/crates.io-index" 283source = "registry+https://github.com/rust-lang/crates.io-index"
284checksum = "b4066c6cf678f962f8c2c4561f205945c84834cce73d981e71392624fdc390a9" 284checksum = "e6c93b1b1fbd0d399db3445f51fd3058e43d0b4dcff62ddbdb46e66550978aa5"
285dependencies = [ 285dependencies = [
286 "cc", 286 "cc",
287 "tree-sitter 0.21.0", 287 "tree-sitter 0.20.10",
288] 288]
289 289
290[[package]] 290[[package]]
291name = "tree-sitter-ruby" 291name = "tree-sitter-ruby"
292version = "0.21.0" 292version = "0.20.1"
293source = "registry+https://github.com/rust-lang/crates.io-index" 293source = "registry+https://github.com/rust-lang/crates.io-index"
294checksum = "c0031f687c0772f2dad7b77104c43428611099a1804c81244ada21560f41f0b1" 294checksum = "44d50ef383469df8485f024c5fb01faced8cb90368192a7ba02605b43b2427fe"
295dependencies = [ 295dependencies = [
296 "cc", 296 "cc",
297 "tree-sitter 0.21.0", 297 "tree-sitter 0.20.10",
298] 298]
299 299
300[[package]] 300[[package]]
301name = "tree-sitter-rust" 301name = "tree-sitter-rust"
302version = "0.21.2" 302version = "0.20.4"
303source = "registry+https://github.com/rust-lang/crates.io-index" 303source = "registry+https://github.com/rust-lang/crates.io-index"
304checksum = "277690f420bf90741dea984f3da038ace46c4fe6047cba57a66822226cde1c93" 304checksum = "b0832309b0b2b6d33760ce5c0e818cb47e1d72b468516bfe4134408926fa7594"
305dependencies = [ 305dependencies = [
306 "cc", 306 "cc",
307 "tree-sitter 0.21.0", 307 "tree-sitter 0.20.10",
308] 308]
309 309
310[[package]] 310[[package]]
311name = "tree-sitter-typescript" 311name = "tree-sitter-typescript"
312version = "0.21.2" 312version = "0.20.5"
313source = "registry+https://github.com/rust-lang/crates.io-index" 313source = "registry+https://github.com/rust-lang/crates.io-index"
314checksum = "ecb35d98a688378e56c18c9c159824fd16f730ccbea19aacf4f206e5d5438ed9" 314checksum = "c8bc1d2c24276a48ef097a71b56888ac9db63717e8f8d0b324668a27fd619670"
315dependencies = [ 315dependencies = [
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"
323dependencies = [ 323dependencies = [
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",
diff --git a/Cargo.toml b/Cargo.toml
index 73ec928..b8fd1b7 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,17 +7,17 @@ edition = "2021"
7 7
8[dependencies] 8[dependencies]
9tree-sitter-elm = "5.6.3" 9tree-sitter-elm = "5.6.3"
10tree-sitter-ruby = "0.21" 10tree-sitter-ruby = "0.20"
11tree-sitter-rust = "0.21" 11tree-sitter-rust = "0.20"
12tree-sitter = "0.21" 12tree-sitter = "0.20"
13console = "^0.15" 13console = "^0.15"
14tree-sitter-go = "0.19.1" 14tree-sitter-go = "0.20"
15tree-sitter-typescript = "0.21" 15tree-sitter-typescript = "0.20"
16tree-sitter-javascript = "0.21" 16tree-sitter-javascript = "0.20"
17tree-sitter-mdx = { git = "https://github.com/jlopezcur/tree-sitter-mdx" } 17tree-sitter-mdx = { git = "https://github.com/jlopezcur/tree-sitter-mdx" }
18tree-sitter-json = { git = "https://github.com/tree-sitter/tree-sitter-json" } 18tree-sitter-json = { git = "https://github.com/tree-sitter/tree-sitter-json" }
19tree-sitter-python = "0.21" 19tree-sitter-python = "0.20"
20tree-sitter-md = "0.2.3" 20tree-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]
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
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(),