Precompile plugins depending on target triple

This commit is contained in:
Isaac Clayton 2022-07-14 13:23:04 +02:00
parent 4a5b8fd2e6
commit 80b45ef93b
6 changed files with 50 additions and 27 deletions

View file

@ -3,6 +3,7 @@ pub use language::*;
use lazy_static::lazy_static;
use rust_embed::RustEmbed;
use std::{borrow::Cow, str, sync::Arc};
// use util::ResultExt;
mod c;
mod go;
@ -54,6 +55,11 @@ pub async fn init(languages: Arc<LanguageRegistry>, _executor: Arc<Background>)
"json",
tree_sitter_json::language(),
Some(CachedLspAdapter::new(json::JsonLspAdapter).await),
// TODO: switch back to plugin
// match language_plugin::new_json(executor).await.log_err() {
// Some(lang) => Some(CachedLspAdapter::new(lang).await),
// None => None,
// },
),
(
"markdown",

View file

@ -5,30 +5,33 @@ use collections::HashMap;
use futures::lock::Mutex;
use gpui::executor::Background;
use language::{LanguageServerName, LspAdapter};
// use plugin_runtime::{Plugin, PluginBinary, PluginBuilder, WasiFn};
use plugin_runtime::{Plugin, WasiFn};
use plugin_runtime::{Plugin, PluginBinary, PluginBuilder, WasiFn};
use std::{any::Any, path::PathBuf, sync::Arc};
use util::ResultExt;
// pub async fn new_json(executor: Arc<Background>) -> Result<PluginLspAdapter> {
// let plugin = PluginBuilder::new_default()?
// .host_function_async("command", |command: String| async move {
// let mut args = command.split(' ');
// let command = args.next().unwrap();
// smol::process::Command::new(command)
// .args(args)
// .output()
// .await
// .log_err()
// .map(|output| output.stdout)
// })?
// .init(PluginBinary::Precompiled(include_bytes!(
// "../../../../plugins/bin/json_language.wasm.pre"
// )))
// .await?;
//
// PluginLspAdapter::new(plugin, executor).await
// }
#[allow(dead_code)]
pub async fn new_json(executor: Arc<Background>) -> Result<PluginLspAdapter> {
let bytes = include_bytes!(concat!(
"../../../../plugins/bin/json_language.wasm.",
env!("TARGET_TRIPLE"),
));
let plugin = PluginBuilder::new_default()?
.host_function_async("command", |command: String| async move {
let mut args = command.split(' ');
let command = args.next().unwrap();
smol::process::Command::new(command)
.args(args)
.output()
.await
.log_err()
.map(|output| output.stdout)
})?
.init(PluginBinary::Precompiled(bytes))
.await?;
PluginLspAdapter::new(plugin, executor).await
}
pub struct PluginLspAdapter {
name: WasiFn<(), String>,