diff options
author | Akshay <[email protected]> | 2023-07-13 10:52:14 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2023-07-13 10:52:14 +0100 |
commit | f99715d8805a18dc7c16f17275a85a0724e01db9 (patch) | |
tree | 2a9bd5845322a6f65cd5dd4f253b8422189dec48 /tree-viz | |
parent | 91d2eb736e18e33972d20faab389257f578cbd7b (diff) |
add field names to tree, if any
Diffstat (limited to 'tree-viz')
-rw-r--r-- | tree-viz/Cargo.toml | 9 | ||||
-rw-r--r-- | tree-viz/src/app.rs | 17 | ||||
-rw-r--r-- | tree-viz/src/config.rs | 2 | ||||
-rw-r--r-- | tree-viz/src/main.rs | 9 |
4 files changed, 35 insertions, 2 deletions
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" | |||
7 | 7 | ||
8 | [dependencies] | 8 | [dependencies] |
9 | tree-sitter-elm = "5.6.3" | 9 | tree-sitter-elm = "5.6.3" |
10 | tree-sitter-rust = "0.20.1" | 10 | tree-sitter-ruby = "0.20.0" |
11 | tree-sitter-rust = "0.20.3" | ||
11 | tree-sitter = "^0.20.8" | 12 | tree-sitter = "^0.20.8" |
12 | console = "^0.15" | 13 | console = "^0.15" |
13 | once_cell = "1.14.0" | 14 | once_cell = "1.14.0" |
14 | tree-sitter-go = "0.19.1" | 15 | tree-sitter-go = "0.19.1" |
15 | tree-sitter-typescript = "0.20.1" | 16 | tree-sitter-typescript = "0.20.1" |
17 | tree-sitter-javascript = "0.20.0" | ||
18 | tree-sitter-mdx = { git = "https://github.com/jlopezcur/tree-sitter-mdx" } | ||
19 | tree-sitter-json = { git = "https://github.com/tree-sitter/tree-sitter-json" } | ||
20 | tree-sitter-python = "0.20.2" | ||
21 | tree-sitter-r = "0.19.5" | ||
22 | tree-sitter-php = { git = "https://github.com/tree-sitter/tree-sitter-php" } | ||
16 | 23 | ||
17 | [dependencies.notify] | 24 | [dependencies.notify] |
18 | version = "5.0.0" | 25 | 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 { | |||
105 | ) | 105 | ) |
106 | .unwrap(); | 106 | .unwrap(); |
107 | 107 | ||
108 | if self.config.show_field_name { | ||
109 | if let Some(f) = cursor.field_name() { | ||
110 | write!( | ||
111 | tree_string, | ||
112 | "{} ", | ||
113 | if in_capture.is_some() { | ||
114 | Style::new().on_yellow().on_bright() | ||
115 | } else { | ||
116 | Style::new() | ||
117 | } | ||
118 | .yellow() | ||
119 | .apply_to(f) | ||
120 | ) | ||
121 | .unwrap() | ||
122 | } | ||
123 | } | ||
124 | |||
108 | write!( | 125 | write!( |
109 | tree_string, | 126 | tree_string, |
110 | "{} ", | 127 | "{} ", |
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 { | |||
5 | pub indent_level: usize, | 5 | pub indent_level: usize, |
6 | pub show_ranges: bool, | 6 | pub show_ranges: bool, |
7 | pub show_src: bool, | 7 | pub show_src: bool, |
8 | pub show_field_name: bool, | ||
8 | } | 9 | } |
9 | 10 | ||
10 | impl Default for Config { | 11 | impl Default for Config { |
@@ -19,6 +20,7 @@ impl Config { | |||
19 | indent_level: 2, | 20 | indent_level: 2, |
20 | show_ranges: true, | 21 | show_ranges: true, |
21 | show_src: true, | 22 | show_src: true, |
23 | show_field_name: true, | ||
22 | } | 24 | } |
23 | } | 25 | } |
24 | } | 26 | } |
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; | |||
16 | use tree_sitter::Language; | 16 | use tree_sitter::Language; |
17 | 17 | ||
18 | //pub static LANGUAGE: Lazy<Language> = Lazy::new(tree_sitter_rust::language); | 18 | //pub static LANGUAGE: Lazy<Language> = Lazy::new(tree_sitter_rust::language); |
19 | pub static LANGUAGE: Lazy<Language> = Lazy::new(tree_sitter_typescript::language_typescript); | 19 | //pub static LANGUAGE: Lazy<Language> = Lazy::new(tree_sitter_typescript::language_tsx); |
20 | //pub static LANGUAGE: Lazy<Language> = Lazy::new(tree_sitter_javascript::language); | ||
21 | //pub static LANGUAGE: Lazy<Language> = Lazy::new(tree_sitter_mdx::language); | ||
22 | //pub static LANGUAGE: Lazy<Language> = Lazy::new(tree_sitter_json::language); | ||
23 | //pub static LANGUAGE: Lazy<Language> = Lazy::new(tree_sitter_python::language); | ||
24 | //pub static LANGUAGE: Lazy<Language> = Lazy::new(tree_sitter_ruby::language); | ||
25 | //pub static LANGUAGE: Lazy<Language> = Lazy::new(tree_sitter_r::language); | ||
26 | pub static LANGUAGE: Lazy<Language> = Lazy::new(tree_sitter_php::language); | ||
20 | 27 | ||
21 | fn main() { | 28 | fn main() { |
22 | let mut args = env::args(); | 29 | let mut args = env::args(); |