From f99715d8805a18dc7c16f17275a85a0724e01db9 Mon Sep 17 00:00:00 2001 From: Akshay Date: Thu, 13 Jul 2023 15:22:14 +0530 Subject: add field names to tree, if any --- Cargo.lock | 461 +++++-------------------------------------------- Cargo.toml | 1 - tree-viz/Cargo.toml | 9 +- tree-viz/src/app.rs | 17 ++ tree-viz/src/config.rs | 2 + tree-viz/src/main.rs | 9 +- 6 files changed, 82 insertions(+), 417 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 338a791..ff68afe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,12 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e" - [[package]] name = "aho-corasick" version = "0.7.19" @@ -17,51 +11,12 @@ dependencies = [ "memchr", ] -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - -[[package]] -name = "anyhow" -version = "1.0.65" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "bitvec" -version = "0.22.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5237f00a8c86130a0cc317830e558b966dd7850d48a953d998c813f01a41b527" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - -[[package]] -name = "byteorder" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" - [[package]] name = "cc" version = "1.0.73" @@ -88,52 +43,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "controlled-option" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95abc95db25411571f40a8b0af30a3c386f3927fe6f1460c70e1f49f01bac3ac" -dependencies = [ - "controlled-option-macros", -] - -[[package]] -name = "controlled-option-macros" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "305024255a6c456333e130da2559b7aedd5c2e15388f51dae69f7507517cfbfb" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "dirs" -version = "3.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30baa043103c9d0c2a57cf537cc2f35623889dc0d405e6c3cccfadbc81c71309" -dependencies = [ - "dirs-sys", -] - -[[package]] -name = "dirs-sys" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" -dependencies = [ - "libc", - "redox_users", - "winapi", -] - -[[package]] -name = "either" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" - [[package]] name = "encode_unicode" version = "0.3.6" @@ -152,57 +61,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "funty" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1847abb9cb65d566acd5942e94aea9c8f547ad02c98e1649326fc0e8910b8b1e" - -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", -] - -[[package]] -name = "getrandom" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "hashbrown" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" -dependencies = [ - "ahash", -] - -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - -[[package]] -name = "indexmap" -version = "1.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" -dependencies = [ - "autocfg", - "hashbrown 0.12.3", -] - [[package]] name = "inotify" version = "0.9.6" @@ -223,21 +81,6 @@ dependencies = [ "libc", ] -[[package]] -name = "itertools" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8bf247779e67a9082a4790b45e71ac7cfd1321331a5c856a74a9faebdab78d0" -dependencies = [ - "either", -] - -[[package]] -name = "itoa" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" - [[package]] name = "kqueue" version = "1.0.6" @@ -258,28 +101,12 @@ dependencies = [ "libc", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libc" version = "0.2.132" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" -[[package]] -name = "libloading" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" -dependencies = [ - "cfg-if", - "winapi", -] - [[package]] name = "log" version = "0.4.17" @@ -289,17 +116,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "lsp-positions" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce95baee2c4668ed42b67ae7f931abe06169fcef8e853815ffaf53b56ac7f0c" -dependencies = [ - "memchr", - "tree-sitter", - "unicode-segmentation", -] - [[package]] name = "memchr" version = "2.5.0" @@ -340,30 +156,6 @@ version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0" -[[package]] -name = "proc-macro2" -version = "1.0.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "radium" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "643f8f41a8ebc4c5dc4515c82bb8abd397b527fc20fd681b7c011c2aee5d44fb" - [[package]] name = "redox_syscall" version = "0.2.16" @@ -373,17 +165,6 @@ dependencies = [ "bitflags", ] -[[package]] -name = "redox_users" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" -dependencies = [ - "getrandom", - "redox_syscall", - "thiserror", -] - [[package]] name = "regex" version = "1.6.0" @@ -401,12 +182,6 @@ version = "0.6.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" -[[package]] -name = "ryu" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" - [[package]] name = "same-file" version = "1.0.6" @@ -416,102 +191,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "scope-viz" -version = "0.1.0" -dependencies = [ - "stack-graphs", - "tree-sitter", - "tree-sitter-elm", - "tree-sitter-graph", - "tree-sitter-rust", - "tree-sitter-stack-graphs", -] - -[[package]] -name = "serde" -version = "1.0.144" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.144" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.85" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" -dependencies = [ - "indexmap", - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "smallvec" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" - -[[package]] -name = "stack-graphs" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c4fdc37ccc4f64bea4bc3ffa3f94be605342e7e8b9b928e203bbd4bfd313949" -dependencies = [ - "bitvec", - "controlled-option", - "either", - "fxhash", - "itertools", - "libc", - "lsp-positions", - "serde", - "serde_json", - "smallvec", - "thiserror", -] - -[[package]] -name = "string-interner" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "383196d1876517ee6f9f0864d1fc1070331b803335d3c6daaa04bbcccd823c08" -dependencies = [ - "cfg-if", - "hashbrown 0.9.1", -] - -[[package]] -name = "syn" -version = "1.0.100" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52205623b1b0f064a4e71182c3b18ae902267282930c6d5462c91b859668426e" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "terminal_size" version = "0.1.17" @@ -522,26 +201,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "thiserror" -version = "1.0.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c53f98874615aea268107765aa1ed8f6116782501d18e53d08b471733bea6c85" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8b463991b4eab2d801e724172285ec4195c650e8ec79b149e6c2a8e6dd3f783" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "tree-sitter" version = "0.20.9" @@ -573,91 +232,79 @@ dependencies = [ ] [[package]] -name = "tree-sitter-graph" -version = "0.6.1" +name = "tree-sitter-javascript" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a4875525d5bbb4a27716eac5469f91370b2acb985c6a984c359abb19732e02" +checksum = "2490fab08630b2c8943c320f7b63473cbf65511c8d83aec551beb9b4375906ed" dependencies = [ - "ansi_term", - "log", - "regex", - "serde", - "serde_json", - "smallvec", - "string-interner", - "thiserror", + "cc", "tree-sitter", ] [[package]] -name = "tree-sitter-highlight" -version = "0.20.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "042342584c5a7a0b833d9fc4e2bdab3f9868ddc6c4b339a1e01451c6720868bc" +name = "tree-sitter-json" +version = "0.20.0" +source = "git+https://github.com/tree-sitter/tree-sitter-json#73076754005a460947cafe8e03a8cf5fa4fa2938" dependencies = [ - "regex", - "thiserror", + "cc", "tree-sitter", ] [[package]] -name = "tree-sitter-loader" -version = "0.20.0" +name = "tree-sitter-mdx" +version = "0.0.1" +source = "git+https://github.com/jlopezcur/tree-sitter-mdx#df43681bff333228fa60b69c09a1e7a6f9ed1610" +dependencies = [ + "cc", + "tree-sitter", +] + +[[package]] +name = "tree-sitter-php" +version = "0.19.1" +source = "git+https://github.com/tree-sitter/tree-sitter-php#d43130fd1525301e9826f420c5393a4d169819fc" +dependencies = [ + "cc", + "tree-sitter", +] + +[[package]] +name = "tree-sitter-python" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0b17eef4833c7c139abed66d562dfa23228e97e647597baf246fd56c21bbfaf" +checksum = "dda114f58048f5059dcf158aff691dffb8e113e6d2b50d94263fd68711975287" dependencies = [ - "anyhow", "cc", - "dirs", - "libloading", - "once_cell", - "regex", - "serde", - "serde_json", "tree-sitter", - "tree-sitter-highlight", - "tree-sitter-tags", ] [[package]] -name = "tree-sitter-rust" -version = "0.20.1" +name = "tree-sitter-r" +version = "0.19.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13470fafb7327a3acf96f5bc1013b5539a899a182f01c59b5af53f6b93195717" +checksum = "522c13f4cc46213148b19d4ad40a988ffabd51fd90eb7de759844fbde49bda0c" dependencies = [ "cc", "tree-sitter", ] [[package]] -name = "tree-sitter-stack-graphs" -version = "0.3.1" +name = "tree-sitter-ruby" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "510004b313ced434bf04faa5d8e6e12e7cd80bb34231c6b132b0284966244f25" +checksum = "0ac30cbb1560363ae76e1ccde543d6d99087421e228cc47afcec004b86bb711a" dependencies = [ - "anyhow", - "controlled-option", - "itertools", - "lazy_static", - "log", - "lsp-positions", - "regex", - "stack-graphs", - "thiserror", + "cc", "tree-sitter", - "tree-sitter-graph", - "tree-sitter-loader", ] [[package]] -name = "tree-sitter-tags" -version = "0.20.2" +name = "tree-sitter-rust" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccb3f1376219530a37a809751ecf65aa35fd8b9c1c4ab6d4faf5f6a9eeda2c05" +checksum = "797842733e252dc11ae5d403a18060bf337b822fc2ae5ddfaa6ff4d9cc20bda6" dependencies = [ - "memchr", - "regex", - "thiserror", + "cc", "tree-sitter", ] @@ -681,22 +328,17 @@ dependencies = [ "tree-sitter", "tree-sitter-elm", "tree-sitter-go", + "tree-sitter-javascript", + "tree-sitter-json", + "tree-sitter-mdx", + "tree-sitter-php", + "tree-sitter-python", + "tree-sitter-r", + "tree-sitter-ruby", "tree-sitter-rust", "tree-sitter-typescript", ] -[[package]] -name = "unicode-ident" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" - -[[package]] -name = "unicode-segmentation" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a" - [[package]] name = "unicode-width" version = "0.1.10" @@ -793,12 +435,3 @@ name = "windows_x86_64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" - -[[package]] -name = "wyz" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "129e027ad65ce1453680623c3fb5163cbf7107bfe1aa32257e7d0e63f9ced188" -dependencies = [ - "tap", -] diff --git a/Cargo.toml b/Cargo.toml index b7d2e20..d9cd8e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,5 @@ [workspace] members = [ - "scope-viz", "tree-viz" ] diff --git a/tree-viz/Cargo.toml b/tree-viz/Cargo.toml index 04107d3..ddac4f8 100644 --- a/tree-viz/Cargo.toml +++ b/tree-viz/Cargo.toml @@ -7,12 +7,19 @@ edition = "2021" [dependencies] tree-sitter-elm = "5.6.3" -tree-sitter-rust = "0.20.1" +tree-sitter-ruby = "0.20.0" +tree-sitter-rust = "0.20.3" tree-sitter = "^0.20.8" console = "^0.15" once_cell = "1.14.0" tree-sitter-go = "0.19.1" tree-sitter-typescript = "0.20.1" +tree-sitter-javascript = "0.20.0" +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.20.2" +tree-sitter-r = "0.19.5" +tree-sitter-php = { git = "https://github.com/tree-sitter/tree-sitter-php" } [dependencies.notify] version = "5.0.0" diff --git a/tree-viz/src/app.rs b/tree-viz/src/app.rs index 68d3641..8581084 100644 --- a/tree-viz/src/app.rs +++ b/tree-viz/src/app.rs @@ -105,6 +105,23 @@ impl App { ) .unwrap(); + if self.config.show_field_name { + if let Some(f) = cursor.field_name() { + write!( + tree_string, + "{} ", + if in_capture.is_some() { + Style::new().on_yellow().on_bright() + } else { + Style::new() + } + .yellow() + .apply_to(f) + ) + .unwrap() + } + } + write!( tree_string, "{} ", diff --git a/tree-viz/src/config.rs b/tree-viz/src/config.rs index 6f34291..18ed5cc 100644 --- a/tree-viz/src/config.rs +++ b/tree-viz/src/config.rs @@ -5,6 +5,7 @@ pub struct Config { pub indent_level: usize, pub show_ranges: bool, pub show_src: bool, + pub show_field_name: bool, } impl Default for Config { @@ -19,6 +20,7 @@ impl Config { indent_level: 2, show_ranges: true, show_src: true, + show_field_name: true, } } } diff --git a/tree-viz/src/main.rs b/tree-viz/src/main.rs index 79964cb..9c73062 100644 --- a/tree-viz/src/main.rs +++ b/tree-viz/src/main.rs @@ -16,7 +16,14 @@ use once_cell::sync::Lazy; use tree_sitter::Language; //pub static LANGUAGE: Lazy = Lazy::new(tree_sitter_rust::language); -pub static LANGUAGE: Lazy = Lazy::new(tree_sitter_typescript::language_typescript); +//pub static LANGUAGE: Lazy = Lazy::new(tree_sitter_typescript::language_tsx); +//pub static LANGUAGE: Lazy = Lazy::new(tree_sitter_javascript::language); +//pub static LANGUAGE: Lazy = Lazy::new(tree_sitter_mdx::language); +//pub static LANGUAGE: Lazy = Lazy::new(tree_sitter_json::language); +//pub static LANGUAGE: Lazy = Lazy::new(tree_sitter_python::language); +//pub static LANGUAGE: Lazy = Lazy::new(tree_sitter_ruby::language); +//pub static LANGUAGE: Lazy = Lazy::new(tree_sitter_r::language); +pub static LANGUAGE: Lazy = Lazy::new(tree_sitter_php::language); fn main() { let mut args = env::args(); -- cgit v1.2.3