-
Notifications
You must be signed in to change notification settings - Fork 54
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
amirabbas-gh
wants to merge
20
commits into
main
Choose a base branch
from
dynamiclink
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(cli): integrate dynamiclink for tree-sitter to reduce CLI size and improve language support #1580
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 3711d25
refactor: use dynamiclink method for native yaml parser
amirabbas-gh a2fa76c
fix: fix failure test about dynamiclink method
amirabbas-gh 8646ccd
feat: add tsx, css, html, kotlin support
amirabbas-gh 995a380
fix: fix lint and format
amirabbas-gh a05f03a
refactor: clean up deps
amirabbas-gh 5f60890
refactor: customize ast-grep dynamic in own crate
amirabbas-gh 2980f22
refactor: clean up codebase from test prints
amirabbas-gh 5527a64
feat: add tsx langauge
amirabbas-gh 0dd9a94
refactor: make tree sitter url more clean
amirabbas-gh 52e3223
fix: fix data races and make dynamic-lang thread-safe
amirabbas-gh 8b6df24
feat: add timeout logic for tree sitter fetch request
amirabbas-gh 5c8613c
feat: add warning when language is not supported
amirabbas-gh b8945b4
feat: add progress bar for downloading tree sitter
amirabbas-gh 8cf0cf0
fix: fix lint
amirabbas-gh d6ed997
refactor: use static base url for tree sitter
amirabbas-gh e8ca1de
fix: move serial_test into dev deps
amirabbas-gh b75231f
refactor: move download progress bar for tree sitter loader into CLI …
amirabbas-gh dfc6564
fix: resolve lint issues at ast-grep/native.rs
amirabbas-gh 2fd7aa3
fix: fix conflicts fixing bugs
amirabbas-gh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: add progress bar for downloading tree sitter
- Loading branch information
commit b8945b4032fdb492664d99cfa275fcfbbf4fb9aa
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mohebifar done