Factor out buffer code
This commit is contained in:
parent
fbaff615a3
commit
e9b87f3dc3
4 changed files with 109 additions and 118 deletions
|
@ -17,12 +17,15 @@ extern "C" {
|
|||
|
||||
// }
|
||||
|
||||
const BIN_PATH: &'static str =
|
||||
"node_modules/vscode-json-languageserver/bin/vscode-json-languageserver";
|
||||
|
||||
#[bind]
|
||||
pub fn name() -> &'static str {
|
||||
let number = unsafe { hello(27) };
|
||||
println!("got: {}", number);
|
||||
let number = unsafe { bye(28) };
|
||||
println!("got: {}", number);
|
||||
// let number = unsafe { hello(27) };
|
||||
// println!("got: {}", number);
|
||||
// let number = unsafe { bye(28) };
|
||||
// println!("got: {}", number);
|
||||
"vscode-json-languageserver"
|
||||
}
|
||||
|
||||
|
@ -33,79 +36,66 @@ pub fn server_args() -> Vec<String> {
|
|||
|
||||
#[bind]
|
||||
pub fn fetch_latest_server_version() -> Option<String> {
|
||||
// #[derive(Deserialize)]
|
||||
// struct NpmInfo {
|
||||
// versions: Vec<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()
|
||||
println!("fetching server version");
|
||||
Some("1.3.4".into())
|
||||
let mut info: NpmInfo = serde_json::from_slice(&output.stdout)?;
|
||||
info.versions.pop()
|
||||
}
|
||||
|
||||
#[bind]
|
||||
pub fn fetch_server_binary(container_dir: PathBuf, version: String) -> Option<PathBuf> {
|
||||
println!("Fetching server binary");
|
||||
return None;
|
||||
// let version_dir = container_dir.join(version.as_str());
|
||||
// fs::create_dir_all(&version_dir)
|
||||
// .await
|
||||
// .context("failed to create version directory")?;
|
||||
// let binary_path = version_dir.join(Self::BIN_PATH);
|
||||
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 = smol::process::Command::new("npm")
|
||||
// .current_dir(&version_dir)
|
||||
// .arg("install")
|
||||
// .arg(format!("vscode-json-languageserver@{}", version))
|
||||
// .output()
|
||||
// .await
|
||||
// .context("failed to run npm install")?;
|
||||
// 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)
|
||||
}
|
||||
|
||||
const BIN_PATH: &'static str =
|
||||
"node_modules/vscode-json-languageserver/bin/vscode-json-languageserver";
|
||||
|
||||
#[bind]
|
||||
pub fn cached_server_binary(container_dir: PathBuf) -> Option<PathBuf> {
|
||||
println!("Finding cached server binary...");
|
||||
let mut last_version_dir = None;
|
||||
println!("{}", container_dir.exists());
|
||||
let mut entries = fs::read_dir(&container_dir).ok()?;
|
||||
println!("Read Entries...");
|
||||
|
||||
while let Some(entry) = entries.next() {
|
||||
let entry = entry.ok()?;
|
||||
if entry.file_type().ok()?.is_dir() {
|
||||
last_version_dir = Some(entry.path());
|
||||
}
|
||||
}
|
||||
|
||||
let last_version_dir = last_version_dir?;
|
||||
let bin_path = last_version_dir.join(BIN_PATH);
|
||||
if bin_path.exists() {
|
||||
println!("this is the path: {}", bin_path.display());
|
||||
Some(bin_path)
|
||||
} else {
|
||||
None
|
||||
|
@ -113,10 +103,8 @@ pub fn cached_server_binary(container_dir: PathBuf) -> Option<PathBuf> {
|
|||
}
|
||||
|
||||
#[bind]
|
||||
pub fn initialization_options() -> Option<serde_json::Value> {
|
||||
Some(json!({
|
||||
"provideFormatter": true
|
||||
}))
|
||||
pub fn initialization_options() -> Option<String> {
|
||||
Some("{ \"provideFormatter\": true }".to_string())
|
||||
}
|
||||
|
||||
#[bind]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue