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 --- tree-viz/Cargo.toml | 9 ++++++++- tree-viz/src/app.rs | 17 +++++++++++++++++ tree-viz/src/config.rs | 2 ++ tree-viz/src/main.rs | 9 ++++++++- 4 files changed, 35 insertions(+), 2 deletions(-) (limited to '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