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/src/app.rs | 17 +++++++++++++++++ tree-viz/src/config.rs | 2 ++ tree-viz/src/main.rs | 9 ++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) (limited to 'tree-viz/src') 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