From 91d2eb736e18e33972d20faab389257f578cbd7b Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 4 Oct 2022 16:25:20 +0530 Subject: init --- .gitignore | 4 + Cargo.lock | 804 +++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 6 + flake.lock | 87 ++++++ flake.nix | 68 +++++ tree-viz/.gitignore | 1 + tree-viz/Cargo.toml | 19 ++ tree-viz/src/app.rs | 230 ++++++++++++++ tree-viz/src/config.rs | 24 ++ tree-viz/src/main.rs | 96 ++++++ 10 files changed, 1339 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 tree-viz/.gitignore create mode 100644 tree-viz/Cargo.toml create mode 100644 tree-viz/src/app.rs create mode 100644 tree-viz/src/config.rs create mode 100644 tree-viz/src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fcdcb15 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +target +scope-viz +.direnv +test-files diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..338a791 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,804 @@ +# This file is automatically @generated by Cargo. +# 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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "console" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89eab4d20ce20cea182308bca13088fecea9c05f6776cf287205d41a0ed3c847" +dependencies = [ + "encode_unicode", + "libc", + "once_cell", + "terminal_size", + "unicode-width", + "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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + +[[package]] +name = "filetime" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94a7bbaa59354bc20dd75b67f23e2797b4490e9d6928203fb105c79e448c86c" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff" +dependencies = [ + "bitflags", + "inotify-sys", + "libc", +] + +[[package]] +name = "inotify-sys" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d6112e8f37b59803ac47a42d14f1f3a59bbf72fc6857ffc5be455e28a691f8e" +dependencies = [ + "kqueue-sys", + "libc", +] + +[[package]] +name = "kqueue-sys" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8367585489f01bc55dd27404dcf56b95e6da061a256a666ab23be9ba96a2e587" +dependencies = [ + "bitflags", + "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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "mio" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys", +] + +[[package]] +name = "notify" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2c66da08abae1c024c01d635253e402341b4060a12e99b31c7594063bf490a" +dependencies = [ + "bitflags", + "filetime", + "inotify", + "kqueue", + "libc", + "mio", + "walkdir", + "winapi", +] + +[[package]] +name = "once_cell" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" +dependencies = [ + "libc", + "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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4423c784fe11398ca91e505cdc71356b07b1a924fc8735cfab5333afe3e18bc" +dependencies = [ + "cc", + "regex", +] + +[[package]] +name = "tree-sitter-elm" +version = "5.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22b9408ad250aa27774132baf20c4f107faad16841aa45568c6900a27895093b" +dependencies = [ + "cc", + "tree-sitter", +] + +[[package]] +name = "tree-sitter-go" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71967701c8214be4aa77e0260e98361e6fd71ceec1d9d03abb37a22c9f60d0ff" +dependencies = [ + "cc", + "tree-sitter", +] + +[[package]] +name = "tree-sitter-graph" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18a4875525d5bbb4a27716eac5469f91370b2acb985c6a984c359abb19732e02" +dependencies = [ + "ansi_term", + "log", + "regex", + "serde", + "serde_json", + "smallvec", + "string-interner", + "thiserror", + "tree-sitter", +] + +[[package]] +name = "tree-sitter-highlight" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "042342584c5a7a0b833d9fc4e2bdab3f9868ddc6c4b339a1e01451c6720868bc" +dependencies = [ + "regex", + "thiserror", + "tree-sitter", +] + +[[package]] +name = "tree-sitter-loader" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0b17eef4833c7c139abed66d562dfa23228e97e647597baf246fd56c21bbfaf" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13470fafb7327a3acf96f5bc1013b5539a899a182f01c59b5af53f6b93195717" +dependencies = [ + "cc", + "tree-sitter", +] + +[[package]] +name = "tree-sitter-stack-graphs" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "510004b313ced434bf04faa5d8e6e12e7cd80bb34231c6b132b0284966244f25" +dependencies = [ + "anyhow", + "controlled-option", + "itertools", + "lazy_static", + "log", + "lsp-positions", + "regex", + "stack-graphs", + "thiserror", + "tree-sitter", + "tree-sitter-graph", + "tree-sitter-loader", +] + +[[package]] +name = "tree-sitter-tags" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccb3f1376219530a37a809751ecf65aa35fd8b9c1c4ab6d4faf5f6a9eeda2c05" +dependencies = [ + "memchr", + "regex", + "thiserror", + "tree-sitter", +] + +[[package]] +name = "tree-sitter-typescript" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e8ed0ecb931cdff13c6a13f45ccd615156e2779d9ffb0395864e05505e6e86d" +dependencies = [ + "cc", + "tree-sitter", +] + +[[package]] +name = "tree-viz" +version = "0.1.0" +dependencies = [ + "console", + "notify", + "once_cell", + "tree-sitter", + "tree-sitter-elm", + "tree-sitter-go", + "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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + +[[package]] +name = "walkdir" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +dependencies = [ + "same-file", + "winapi", + "winapi-util", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +dependencies = [ + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" + +[[package]] +name = "windows_i686_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" + +[[package]] +name = "windows_i686_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" + +[[package]] +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 new file mode 100644 index 0000000..b7d2e20 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[workspace] + +members = [ + "scope-viz", + "tree-viz" +] diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a7c083f --- /dev/null +++ b/flake.lock @@ -0,0 +1,87 @@ +{ + "nodes": { + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1645251813, + "narHash": "sha256-cQ66tGjnZclBCS3nD26mZ5fUH+3/HnysGffBiWXUSHk=", + "owner": "nix-community", + "repo": "fenix", + "rev": "9892337b588c38ec59466a1c89befce464aae7f8", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1635165013, + "narHash": "sha256-o/BdVjNwcB6jOmzZjOH703BesSkkS5O7ej3xhyO8hAY=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "5b9e0ff9d3b551234b4f3eb3983744fa354b17f1", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1645013224, + "narHash": "sha256-b7OEC8vwzJv3rsz9pwnTX2LQDkeOWz2DbKypkVvNHXc=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "b66b39216b1fef2d8c33cc7a5c72d8da80b79970", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "fenix": "fenix", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1645205556, + "narHash": "sha256-e4lZW3qRyOEJ+vLKFQP7m2Dxh5P44NrnekZYLxlucww=", + "owner": "rust-analyzer", + "repo": "rust-analyzer", + "rev": "acf5874b39f3dc5262317a6074d9fc7285081161", + "type": "github" + }, + "original": { + "owner": "rust-analyzer", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..861792b --- /dev/null +++ b/flake.nix @@ -0,0 +1,68 @@ +{ + inputs = { + + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + gitignore = { + url = "github:hercules-ci/gitignore.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + }; + + outputs = + { self + , nixpkgs + , fenix + , gitignore + }: + let + inherit (gitignore.lib) gitignoreSource; + + supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + nixpkgsFor = forAllSystems (system: + import nixpkgs { inherit system; }); + + chanspec = { + date = "2022-09-01"; + channel = "nightly"; + sha256 = "tS2IHsewoaEMHn9x8DfcEJefShcW85iDrfBWXOZJa9c="; # set zeros after modifying channel or date + }; + rustChannel = p: (fenix.overlay p p).fenix.toolchainOf chanspec; + + in + { + + + devShell = forAllSystems (system: + let + pkgs = nixpkgsFor."${system}"; + toolchain = (rustChannel pkgs).withComponents [ + "rustc" + "cargo" + "rust-std" + "rustfmt" + "clippy" + "rust-src" + ]; + inherit (fenix.packages."${system}") rust-analyzer; + in + pkgs.mkShell { + nativeBuildInputs = [ + pkgs.cargo-watch + pkgs.bacon + pkgs.cargo-insta + rust-analyzer + toolchain + ]; + RUST_LOG = "info"; + RUST_BACKTRACE = 1; + }); + }; +} diff --git a/tree-viz/.gitignore b/tree-viz/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/tree-viz/.gitignore @@ -0,0 +1 @@ +/target diff --git a/tree-viz/Cargo.toml b/tree-viz/Cargo.toml new file mode 100644 index 0000000..04107d3 --- /dev/null +++ b/tree-viz/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "tree-viz" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tree-sitter-elm = "5.6.3" +tree-sitter-rust = "0.20.1" +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" + +[dependencies.notify] +version = "5.0.0" +default-features = false diff --git a/tree-viz/src/app.rs b/tree-viz/src/app.rs new file mode 100644 index 0000000..68d3641 --- /dev/null +++ b/tree-viz/src/app.rs @@ -0,0 +1,230 @@ +use crate::{config::Config, LANGUAGE}; + +use std::{ + collections::HashMap, + fmt::Write, + path::{Path, PathBuf}, +}; + +use console::{style, Style, Term}; +use tree_sitter::{Node, Parser, Query, QueryCursor, Range, Tree}; + +pub struct App { + config: Config, + path: PathBuf, + query: Option, + query_path: Option, + src: Vec, + tree: Tree, +} + +impl App { + pub fn new<'a, P: AsRef>(src: &'a [u8], path: P, query_path: Option

) -> Self { + let path = path.as_ref().to_owned(); + + let mut parser = Parser::new(); + 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 query_src = std::fs::read_to_string(&p).expect("unable to read query"); + Query::new(*LANGUAGE, &query_src).expect("query parse error") + }); + + Self { + config: Default::default(), + path, + query, + query_path, + src: src.to_owned(), + tree, + } + } + + pub fn draw(&self) { + let term = Term::stdout(); + term.clear_screen().unwrap(); + let mut done = false; + let mut depth = 0; + let mut in_capture: Option = None; + let mut cursor = self.tree.walk(); + + let capture_names = self + .query + .as_ref() + .map(|q| q.capture_names()) + .unwrap_or_default(); + let capture_map = self + .query + .as_ref() + .map(|query| { + QueryCursor::new() + .matches(&query, self.tree.root_node(), self.src.as_slice()) + .flat_map(|match_| match_.captures) + .fold( + HashMap::new(), + |mut map: HashMap>, capture| { + map.entry(capture.node) + .and_modify(|idxs| idxs.push(capture.index)) + .or_insert_with(|| vec![capture.index]); + map + }, + ) + }) + .unwrap_or_default(); + + while !done { + let node = cursor.node(); + let mut tree_string = String::new(); + in_capture = match in_capture { + Some(range) + if !contains(&range, &node.range()) && capture_map.contains_key(&node) => + { + Some(node.range()) + } + Some(range) if !contains(&range, &node.range()) => None, + None if capture_map.contains_key(&node) => Some(node.range()), + i => i, + }; + + write!( + tree_string, + "{}", + (if in_capture.is_some() { + Style::new().on_yellow().on_bright() + } else { + Style::new() + }) + .bright() + .black() + .apply_to( + format!("{}{}", "|", " ".repeat(self.config.indent_level)) + .repeat(depth as usize) + ) + ) + .unwrap(); + + write!( + tree_string, + "{} ", + if node.is_error() { + Style::new().red() + } else if in_capture.is_some() { + Style::new().on_yellow().on_bright() + } else { + Style::new() + } + .apply_to(node.kind()), + ) + .unwrap(); + + if let Some(idxs) = capture_map.get(&node) { + for index in idxs { + write!( + tree_string, + "@{} ", + style(capture_names[*index as usize].as_str()).magenta() + ) + .unwrap(); + } + } + + if self.config.show_ranges { + let range = node.range(); + write!( + tree_string, + " {}", + style(format!("{:?}..{:?}", range.start_byte, range.end_byte,)) + .bright() + .black() + ) + .unwrap(); + } + + if self.config.show_src { + write!( + tree_string, + " {:.?}", + style(node.utf8_text(&self.src).unwrap()).cyan() + ) + .unwrap(); + } + + term.write_line(&tree_string).unwrap(); + term.clear_to_end_of_screen().unwrap(); + + if cursor.goto_first_child() { + depth += 1; + continue; + } + if cursor.goto_next_sibling() { + continue; + } + + loop { + if !cursor.goto_parent() { + done = true; + break; + } else { + depth -= 1; + } + + if cursor.goto_next_sibling() { + break; + } + } + } + + // see https://github.com/console-rs/console/issues/36#issuecomment-624731432 + // for the reasoning behing this hackjob + + term.write_line("\n(>) increase indent").unwrap(); + term.clear_to_end_of_screen().unwrap(); + + term.write_line("(<) decrease indent ").unwrap(); + term.clear_to_end_of_screen().unwrap(); + + term.write_line("(n) toggle ranges").unwrap(); + term.clear_to_end_of_screen().unwrap(); + + term.write_line("(s) toggle source text").unwrap(); + term.clear_to_end_of_screen().unwrap(); + + term.write_line("(r) reload from disk").unwrap(); + term.clear_to_end_of_screen().unwrap(); + + term.write_line("(C-c) quit").unwrap(); + term.clear_to_end_of_screen().unwrap(); + } + + pub fn increase_indent(&mut self) { + self.config.indent_level = self.config.indent_level.saturating_add(1); + } + + pub fn decrease_indent(&mut self) { + self.config.indent_level = self.config.indent_level.saturating_sub(1); + } + + pub fn toggle_ranges(&mut self) { + self.config.show_ranges = !self.config.show_ranges; + } + + pub fn toggle_source(&mut self) { + self.config.show_src = !self.config.show_src; + } + + pub fn reload(&mut self) { + let src = std::fs::read_to_string(&self.path).unwrap(); + let new = Self::new(src.as_bytes(), &self.path, self.query_path.as_ref()); + *self = Self { + config: self.config, + ..new + }; + } +} + +// does a encompass b +fn contains(a: &Range, b: &Range) -> bool { + a.start_byte <= b.start_byte && a.end_byte >= b.end_byte +} diff --git a/tree-viz/src/config.rs b/tree-viz/src/config.rs new file mode 100644 index 0000000..6f34291 --- /dev/null +++ b/tree-viz/src/config.rs @@ -0,0 +1,24 @@ +use std::default::Default; + +#[derive(Clone, Copy)] +pub struct Config { + pub indent_level: usize, + pub show_ranges: bool, + pub show_src: bool, +} + +impl Default for Config { + fn default() -> Self { + Config::new() + } +} + +impl Config { + fn new() -> Self { + Self { + indent_level: 2, + show_ranges: true, + show_src: true, + } + } +} diff --git a/tree-viz/src/main.rs b/tree-viz/src/main.rs new file mode 100644 index 0000000..79964cb --- /dev/null +++ b/tree-viz/src/main.rs @@ -0,0 +1,96 @@ +mod app; +mod config; + +use std::{ + env, fs, + path::Path, + sync::{mpsc, Arc, RwLock}, + thread, + time::Duration, +}; + +use app::App; +use console::{Key, Term}; +use notify::{Event as WatchEvent, EventKind as WatchEventKind, RecursiveMode, Watcher}; +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); + +fn main() { + let mut args = env::args(); + let _ = args.next(); + + let path = args.next().expect("no arg passed"); + let query_path = args.next(); + let src = fs::read_to_string(&path).expect("unable to read file"); + + let app = Arc::new(RwLock::new(App::new( + src.as_bytes(), + &path, + query_path.as_ref(), + ))); + + let watch_fn = |watcher_app: Arc>| { + move |ev| { + if let Ok(WatchEvent { + kind: WatchEventKind::Modify(..), + .. + }) = ev + { + if let Ok(mut locked) = watcher_app.try_write() { + locked.reload(); + locked.draw(); + }; + } + } + }; + + let mut watcher1 = notify::recommended_watcher(watch_fn(Arc::clone(&app))).unwrap(); + watcher1 + .watch(Path::new(&path), RecursiveMode::NonRecursive) + .unwrap(); + + let mut watcher2 = notify::recommended_watcher(watch_fn(Arc::clone(&app))).unwrap(); + if let Some(query_path) = query_path { + watcher2 + .watch(Path::new(&query_path), RecursiveMode::NonRecursive) + .unwrap(); + } + + let (tx, rx) = mpsc::channel(); + let tx0 = tx.clone(); + thread::spawn(move || { + let term = Term::stdout(); + loop { + if let Ok(Key::Char(ev)) = term.read_key() { + tx0.send(ev).unwrap(); + } + } + }); + + if let Ok(locked) = app.try_read() { + locked.draw(); + } + + loop { + match rx.try_recv() { + Ok(ev) => { + if let Ok(mut locked) = app.try_write() { + match ev { + '>' => locked.increase_indent(), + '<' => locked.decrease_indent(), + 'n' => locked.toggle_ranges(), + 's' => locked.toggle_source(), + 'r' => locked.reload(), + _ => (), + } + locked.draw(); + } + } + _ => (), + } + thread::sleep(Duration::from_millis(10)); + } +} -- cgit v1.2.3