Move Wasi to async, validate timeslicing, using async in traits still WIP
This commit is contained in:
parent
e9b87f3dc3
commit
8bce35d1e9
5 changed files with 144 additions and 115 deletions
|
@ -17,6 +17,13 @@ extern "C" {
|
|||
|
||||
// }
|
||||
|
||||
// #[no_mangle]
|
||||
// pub extern "C" fn very_unique_name_of_course() -> impl std::future::Future<Output = u32> {
|
||||
// async move {
|
||||
// std::fs::read_to_string("heck.txt").unwrap().len() as u32
|
||||
// }
|
||||
// }
|
||||
|
||||
const BIN_PATH: &'static str =
|
||||
"node_modules/vscode-json-languageserver/bin/vscode-json-languageserver";
|
||||
|
||||
|
@ -34,52 +41,52 @@ pub fn server_args() -> Vec<String> {
|
|||
vec!["--stdio".into()]
|
||||
}
|
||||
|
||||
#[bind]
|
||||
pub fn fetch_latest_server_version() -> Option<String> {
|
||||
#[derive(Deserialize)]
|
||||
struct NpmInfo {
|
||||
versions: Vec<String>,
|
||||
}
|
||||
// #[bind]
|
||||
// pub fn fetch_latest_server_version() -> Option<String> {
|
||||
// #[derive(Deserialize)]
|
||||
// struct NpmInfo {
|
||||
// versions: Vec<String>,
|
||||
// }
|
||||
|
||||
let output = command("npm info vscode-json-languageserver --json")?;
|
||||
if !output.status.success() {
|
||||
return None;
|
||||
}
|
||||
// let output = command("npm info vscode-json-languageserver --json")?;
|
||||
// if !output.status.success() {
|
||||
// return None;
|
||||
// }
|
||||
|
||||
let mut info: NpmInfo = serde_json::from_slice(&output.stdout)?;
|
||||
info.versions.pop()
|
||||
}
|
||||
// let mut info: NpmInfo = serde_json::from_slice(&output.stdout)?;
|
||||
// info.versions.pop()
|
||||
// }
|
||||
|
||||
#[bind]
|
||||
pub fn fetch_server_binary(container_dir: PathBuf, version: String) -> Result<PathBuf, String> {
|
||||
let version_dir = container_dir.join(version.as_str());
|
||||
fs::create_dir_all(&version_dir)
|
||||
.or_or_else(|| "failed to create version directory".to_string())?;
|
||||
let binary_path = version_dir.join(Self::BIN_PATH);
|
||||
// #[bind]
|
||||
// pub fn fetch_server_binary(container_dir: PathBuf, version: String) -> Result<PathBuf, String> {
|
||||
// let version_dir = container_dir.join(version.as_str());
|
||||
// fs::create_dir_all(&version_dir)
|
||||
// .or_or_else(|| "failed to create version directory".to_string())?;
|
||||
// let binary_path = version_dir.join(Self::BIN_PATH);
|
||||
|
||||
if fs::metadata(&binary_path).await.is_err() {
|
||||
let output = command(format!(
|
||||
"npm install vscode-json-languageserver@{}",
|
||||
version
|
||||
));
|
||||
if !output.status.success() {
|
||||
Err(anyhow!("failed to install vscode-json-languageserver"))?;
|
||||
}
|
||||
// if fs::metadata(&binary_path).await.is_err() {
|
||||
// let output = command(format!(
|
||||
// "npm install vscode-json-languageserver@{}",
|
||||
// version
|
||||
// ));
|
||||
// if !output.status.success() {
|
||||
// Err(anyhow!("failed to install vscode-json-languageserver"))?;
|
||||
// }
|
||||
|
||||
if let Some(mut entries) = fs::read_dir(&container_dir).await.log_err() {
|
||||
while let Some(entry) = entries.next().await {
|
||||
if let Some(entry) = entry.log_err() {
|
||||
let entry_path = entry.path();
|
||||
if entry_path.as_path() != version_dir {
|
||||
fs::remove_dir_all(&entry_path).await.log_err();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// if let Some(mut entries) = fs::read_dir(&container_dir).await.log_err() {
|
||||
// while let Some(entry) = entries.next().await {
|
||||
// if let Some(entry) = entry.log_err() {
|
||||
// let entry_path = entry.path();
|
||||
// if entry_path.as_path() != version_dir {
|
||||
// fs::remove_dir_all(&entry_path).await.log_err();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
Ok(binary_path)
|
||||
}
|
||||
// Ok(binary_path)
|
||||
// }
|
||||
|
||||
#[bind]
|
||||
pub fn cached_server_binary(container_dir: PathBuf) -> Option<PathBuf> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue