Skip to content

Commit

Permalink
[zed] Improve sync remote code
Browse files Browse the repository at this point in the history
  • Loading branch information
mantou132 committed Nov 25, 2024
1 parent 2408f3b commit 6de45bd
Show file tree
Hide file tree
Showing 14 changed files with 975 additions and 542 deletions.
885 changes: 884 additions & 1 deletion Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions crates/zed-plugin-gem/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.wasm
languages/typescript
8 changes: 8 additions & 0 deletions crates/zed-plugin-gem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ crate-type = ["cdylib"]

[dependencies]
zed_extension_api = "0.1.0"

[build-dependencies]
anyhow = "1"
tempfile = "3"
fs-more = "0.8.0"
reqwest = { version = "0.12.9", features = ["blocking"] }
flate2 = "1.0.35"
tar = "0.4.43"
59 changes: 59 additions & 0 deletions crates/zed-plugin-gem/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use flate2::read::GzDecoder;
use fs_more::directory::copy_directory;
use reqwest::blocking::Client;
use std::fs::{self, File, OpenOptions};
use std::io::{self, Cursor, Write};
use std::time::Duration;
use tar::Archive;
use tempfile::tempdir;

fn sync_typescript() -> anyhow::Result<()> {
let dir = tempdir()?;
let dir_path = dir.path();
let tar_gz_path = dir_path.join("archive.tar.gz");
let mut tar_gz = File::create(&tar_gz_path)?;
let client = Client::builder()
.timeout(Duration::from_secs(100))
.build()?;
let response = client
.get("https://github.com/zed-industries/zed/tarball/main")
.send()?;
let bytes = &mut response.bytes()?;
let mut cursor = Cursor::new(bytes);
io::copy(&mut cursor, &mut tar_gz)?;

// new file descriptor
let tar_gz = File::open(&tar_gz_path)?;
let gz = GzDecoder::new(tar_gz);
let mut archive = Archive::new(gz);
let dst = dir_path.join("dist");
fs::create_dir(&dst)?;
archive.unpack(&dst)?;
let zed_dir = fs::read_dir(&dst)?.last().unwrap().unwrap().file_name();
copy_directory(
dst.join(zed_dir).join("crates/languages/src/typescript"),
"languages/typescript",
Default::default(),
)?;
Ok(())
}

fn main() -> anyhow::Result<()> {
if !fs::read_to_string("languages/typescript/injections.scm")
.unwrap_or(String::new())
.contains("Gem")
{
sync_typescript()?;

let mut file = OpenOptions::new()
.append(true)
.open("languages/typescript/injections.scm")?;

let append_content = fs::read_to_string("src/injections.scm")?;

writeln!(file)?;
writeln!(file, "{}", append_content)?;
}

Ok(())
}
5 changes: 0 additions & 5 deletions crates/zed-plugin-gem/languages/typescript/brackets.scm

This file was deleted.

19 changes: 0 additions & 19 deletions crates/zed-plugin-gem/languages/typescript/config.toml

This file was deleted.

85 changes: 0 additions & 85 deletions crates/zed-plugin-gem/languages/typescript/embedding.scm

This file was deleted.

Loading

0 comments on commit 6de45bd

Please sign in to comment.