Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit ea70811

Browse files
author
Hendrik van Antwerpen
authored
Merge pull request #433 from github/add-tsx-to-cli
Always enable both TS & TSX in CLI
2 parents 051c82e + 36f83ea commit ea70811

File tree

3 files changed

+25
-41
lines changed

3 files changed

+25
-41
lines changed

languages/tree-sitter-stack-graphs-typescript/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## v0.3.0 -- unreleased
9+
10+
### Added
11+
12+
- Support for TSX. A new language configuration for TSX is available, and TSX is enabled in the CLI next to TypeScript.
13+
814
## v0.2.0 -- 2024-03-06
915

1016
The `tree-sitter-stack-graphs` is updated to `v0.8`.

languages/tree-sitter-stack-graphs-typescript/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[package]
22
name = "tree-sitter-stack-graphs-typescript"
3-
version = "0.2.0"
4-
description = "Stack graphs definition for TypeScript using tree-sitter-typescript"
3+
version = "0.3.0"
4+
description = "Stack graphs definition for TypeScript & TSX using tree-sitter-typescript"
55
readme = "README.md"
6-
keywords = ["tree-sitter", "stack-graphs", "typescript"]
6+
keywords = ["tree-sitter", "stack-graphs", "typescript", "tsx"]
77
authors = ["Hendrik van Antwerpen <[email protected]>"]
88
license = "MIT OR Apache-2.0"
99
edition = "2018"

languages/tree-sitter-stack-graphs-typescript/rust/bin.rs

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,34 @@
66
// ------------------------------------------------------------------------------------------------
77

88
use anyhow::anyhow;
9-
use clap::{Parser, ValueEnum};
9+
use clap::Parser;
1010
use tree_sitter_stack_graphs::cli::database::default_user_database_path_for_crate;
1111
use tree_sitter_stack_graphs::cli::provided_languages::Subcommands;
12-
use tree_sitter_stack_graphs::loader::{LanguageConfiguration, LoadError};
1312
use tree_sitter_stack_graphs::NoCancellation;
1413

15-
/// Flag to select the dialect of the language
16-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
17-
pub enum Dialect {
18-
Typescript,
19-
TSX,
20-
}
21-
2214
fn main() -> anyhow::Result<()> {
2315
let cli = Cli::parse();
24-
let lc = match language_configuration(cli.dialect) {
25-
Ok(lc) => lc,
26-
Err(err) => {
27-
eprintln!("{}", err.display_pretty());
28-
return Err(anyhow!("Language configuration error"));
29-
}
30-
};
31-
let default_db_path = default_user_database_path_for_crate(env!("CARGO_PKG_NAME"))?;
32-
cli.subcommand.run(default_db_path, vec![lc])
33-
}
34-
35-
fn language_configuration<'a>(dialect: Dialect) -> Result<LanguageConfiguration, LoadError<'a>> {
36-
match dialect {
37-
Dialect::Typescript => {
38-
tree_sitter_stack_graphs_typescript::try_language_configuration_typescript(
39-
&NoCancellation,
40-
)
41-
}
42-
Dialect::TSX => {
43-
tree_sitter_stack_graphs_typescript::try_language_configuration_tsx(&NoCancellation)
44-
}
16+
let mut lcs = Vec::new();
17+
for r in [
18+
tree_sitter_stack_graphs_typescript::try_language_configuration_typescript(&NoCancellation),
19+
tree_sitter_stack_graphs_typescript::try_language_configuration_tsx(&NoCancellation),
20+
] {
21+
let lc = match r {
22+
Ok(lc) => lc,
23+
Err(err) => {
24+
eprintln!("{}", err.display_pretty());
25+
return Err(anyhow!("Language configuration error"));
26+
}
27+
};
28+
lcs.push(lc);
4529
}
30+
let default_db_path = default_user_database_path_for_crate(env!("CARGO_PKG_NAME"))?;
31+
cli.subcommand.run(default_db_path, lcs)
4632
}
4733

4834
#[derive(Parser)]
4935
#[clap(about, version)]
5036
pub struct Cli {
51-
#[clap(
52-
short,
53-
long,
54-
value_enum,
55-
default_value_t = Dialect::Typescript,
56-
)]
57-
dialect: Dialect,
58-
5937
#[clap(subcommand)]
6038
subcommand: Subcommands,
6139
}

0 commit comments

Comments
 (0)