Skip to content

feat(cli): integrate dynamiclink for tree-sitter to reduce CLI size and improve language support #1580

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

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
81ea8c7
feat: add dynamiclink logic for tree sitter at js ast-grep codemods f…
amirabbas-gh Jul 4, 2025
3711d25
refactor: use dynamiclink method for native yaml parser
amirabbas-gh Jul 4, 2025
a2fa76c
fix: fix failure test about dynamiclink method
amirabbas-gh Jul 5, 2025
8646ccd
feat: add tsx, css, html, kotlin support
amirabbas-gh Jul 5, 2025
995a380
fix: fix lint and format
amirabbas-gh Jul 5, 2025
a05f03a
refactor: clean up deps
amirabbas-gh Jul 5, 2025
5f60890
refactor: customize ast-grep dynamic in own crate
amirabbas-gh Jul 9, 2025
2980f22
refactor: clean up codebase from test prints
amirabbas-gh Jul 9, 2025
5527a64
feat: add tsx langauge
amirabbas-gh Jul 11, 2025
0dd9a94
refactor: make tree sitter url more clean
amirabbas-gh Jul 11, 2025
52e3223
fix: fix data races and make dynamic-lang thread-safe
amirabbas-gh Jul 14, 2025
8b6df24
feat: add timeout logic for tree sitter fetch request
amirabbas-gh Jul 14, 2025
5c8613c
feat: add warning when language is not supported
amirabbas-gh Jul 14, 2025
b8945b4
feat: add progress bar for downloading tree sitter
amirabbas-gh Jul 14, 2025
8cf0cf0
fix: fix lint
amirabbas-gh Jul 14, 2025
d6ed997
refactor: use static base url for tree sitter
amirabbas-gh Jul 18, 2025
e8ca1de
fix: move serial_test into dev deps
amirabbas-gh Jul 18, 2025
b75231f
refactor: move download progress bar for tree sitter loader into CLI …
amirabbas-gh Jul 18, 2025
dfc6564
fix: resolve lint issues at ast-grep/native.rs
amirabbas-gh Jul 18, 2025
2fd7aa3
fix: fix conflicts fixing bugs
amirabbas-gh Jul 21, 2025
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
Prev Previous commit
Next Next commit
feat: add progress bar for downloading tree sitter
  • Loading branch information
amirabbas-gh committed Jul 21, 2025
commit b8945b4032fdb492664d99cfa275fcfbbf4fb9aa
101 changes: 96 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ futures = "0.3"
ignore = { version = "0.4.23" }
log = "0.4"
regex = "1.10"
reqwest = { version = "0.12", features = ["json"] }
reqwest = { version = "0.12", features = ["json", "stream"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_yaml = "0.9"
Expand Down
2 changes: 2 additions & 0 deletions crates/codemod-sandbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ dirs.workspace = true
reqwest.workspace = true
serial_test = "3.2.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not a dev dependency?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mohebifar done

ast-grep-codemod-dynamic-lang = { version = "1.0.0-rc.6", path = "../ast-grep-codemod-dynamic-lang" }
indicatif = "0.18.0"
tokio-stream = "0.1.17"

[dev-dependencies]
tempfile = { workspace = true }
Expand Down
51 changes: 47 additions & 4 deletions crates/codemod-sandbox/src/tree_sitter/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use ast_grep_codemod_dynamic_lang::{DynamicLang, Registration};
use dirs::data_local_dir;
use indicatif::{ProgressBar, ProgressState, ProgressStyle};
use reqwest;
use reqwest::header::CONTENT_LENGTH;
use serde::{Deserialize, Serialize};
use std::{collections::HashSet, env, fmt, path::PathBuf, str::FromStr};
use tokio::io::AsyncWriteExt;
use tokio_stream::StreamExt;

use crate::sandbox::engine::language_data::get_extensions_for_language;

Expand Down Expand Up @@ -54,20 +58,59 @@ pub async fn load_tree_sitter(languages: &[SupportedLanguage]) -> Result<Vec<Dyn
"https://tree-sitter-parsers.s3.us-east-1.amazonaws.com".to_string()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use env!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

});
let url = format!("{base_url}/tree-sitter/parsers/tree-sitter-{language}/latest/{os}-{arch}.{extension}");

let client = reqwest::Client::builder()
.timeout(std::time::Duration::from_secs(30))
.build()
.map_err(|e| format!("Failed to build HTTP client: {e}"))?;

let head_response = client
.head(&url)
.send()
.await
.map_err(|e| format!("Failed to get header from {url}: {e}"))?;

let total_size = head_response
.headers()
.get(CONTENT_LENGTH)
.and_then(|val| val.to_str().ok()?.parse().ok())
.unwrap_or(0);

let progress_bar = ProgressBar::new(total_size);
progress_bar.set_style(
ProgressStyle::with_template(
"{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({eta})"
)
.unwrap()
.with_key("eta", |state: &ProgressState, w: &mut dyn std::fmt::Write| {
write!(w, "{:.1}s", state.eta().as_secs_f64()).unwrap()
})
.progress_chars("#>-")
);

let response = client
.get(&url)
.send()
.await
.map_err(|e| format!("Failed to download from {url}: {e}"))?;
let body = response
.bytes()

let mut stream = response.bytes_stream();
let mut file = tokio::fs::File::create(&lib_path)
.await
.map_err(|e| format!("Failed to create file: {e}"))?;

while let Some(chunk) = stream.next().await {
let chunk = chunk.map_err(|e| format!("Stream error from {url}: {e}"))?;
file.write_all(&chunk)
.await
.map_err(|e| format!("Write error: {e}"))?;
progress_bar.inc(chunk.len() as u64);
}

file.flush()
.await
.map_err(|e| format!("Failed to read response from {url}: {e}"))?;
std::fs::write(&lib_path, body).map_err(|e| format!("Failed to write file: {e}"))?;
.map_err(|e| format!("Flush error: {e}"))?;
progress_bar.finish_with_message("Downloaded successfully");
}
ready_langs.insert(ReadyLang {
language: *language,
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy