Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always enable both TS & TSX in CLI #433

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions languages/tree-sitter-stack-graphs-typescript/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## v0.3.0 -- unreleased

### Added

- Support for TSX. A new language configuration for TSX is available, and TSX is enabled in the CLI next to TypeScript.

## v0.2.0 -- 2024-03-06

The `tree-sitter-stack-graphs` is updated to `v0.8`.
Expand Down
6 changes: 3 additions & 3 deletions languages/tree-sitter-stack-graphs-typescript/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "tree-sitter-stack-graphs-typescript"
version = "0.2.0"
description = "Stack graphs definition for TypeScript using tree-sitter-typescript"
version = "0.3.0"
description = "Stack graphs definition for TypeScript & TSX using tree-sitter-typescript"
readme = "README.md"
keywords = ["tree-sitter", "stack-graphs", "typescript"]
keywords = ["tree-sitter", "stack-graphs", "typescript", "tsx"]
authors = ["Hendrik van Antwerpen <[email protected]>"]
license = "MIT OR Apache-2.0"
edition = "2018"
Expand Down
54 changes: 16 additions & 38 deletions languages/tree-sitter-stack-graphs-typescript/rust/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,34 @@
// ------------------------------------------------------------------------------------------------

use anyhow::anyhow;
use clap::{Parser, ValueEnum};
use clap::Parser;
use tree_sitter_stack_graphs::cli::database::default_user_database_path_for_crate;
use tree_sitter_stack_graphs::cli::provided_languages::Subcommands;
use tree_sitter_stack_graphs::loader::{LanguageConfiguration, LoadError};
use tree_sitter_stack_graphs::NoCancellation;

/// Flag to select the dialect of the language
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
pub enum Dialect {
Typescript,
TSX,
}

fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
let lc = match language_configuration(cli.dialect) {
Ok(lc) => lc,
Err(err) => {
eprintln!("{}", err.display_pretty());
return Err(anyhow!("Language configuration error"));
}
};
let default_db_path = default_user_database_path_for_crate(env!("CARGO_PKG_NAME"))?;
cli.subcommand.run(default_db_path, vec![lc])
}

fn language_configuration<'a>(dialect: Dialect) -> Result<LanguageConfiguration, LoadError<'a>> {
match dialect {
Dialect::Typescript => {
tree_sitter_stack_graphs_typescript::try_language_configuration_typescript(
&NoCancellation,
)
}
Dialect::TSX => {
tree_sitter_stack_graphs_typescript::try_language_configuration_tsx(&NoCancellation)
}
let mut lcs = Vec::new();
for r in [
tree_sitter_stack_graphs_typescript::try_language_configuration_typescript(&NoCancellation),
tree_sitter_stack_graphs_typescript::try_language_configuration_tsx(&NoCancellation),
] {
let lc = match r {
Ok(lc) => lc,
Err(err) => {
eprintln!("{}", err.display_pretty());
return Err(anyhow!("Language configuration error"));
}
};
lcs.push(lc);
}
let default_db_path = default_user_database_path_for_crate(env!("CARGO_PKG_NAME"))?;
cli.subcommand.run(default_db_path, lcs)
}

#[derive(Parser)]
#[clap(about, version)]
pub struct Cli {
#[clap(
short,
long,
value_enum,
default_value_t = Dialect::Typescript,
)]
dialect: Dialect,

#[clap(subcommand)]
subcommand: Subcommands,
}
Loading