Checkpoint
This commit is contained in:
parent
92c4552146
commit
37e04320aa
5 changed files with 60 additions and 9 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
@ -1950,6 +1950,15 @@ version = "0.3.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
|
checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "future-wrap"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5bab12b2506593396c1339caf22beeb6f5cbe95dac5e376b71a3d17cbe2c4630"
|
||||||
|
dependencies = [
|
||||||
|
"pin-project",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures"
|
name = "futures"
|
||||||
version = "0.3.21"
|
version = "0.3.21"
|
||||||
|
@ -3720,6 +3729,7 @@ dependencies = [
|
||||||
"pollster",
|
"pollster",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"smol",
|
||||||
"wasi-common",
|
"wasi-common",
|
||||||
"wasmtime",
|
"wasmtime",
|
||||||
"wasmtime-wasi",
|
"wasmtime-wasi",
|
||||||
|
@ -7008,6 +7018,7 @@ dependencies = [
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"file_finder",
|
"file_finder",
|
||||||
"fsevent",
|
"fsevent",
|
||||||
|
"future-wrap",
|
||||||
"futures",
|
"futures",
|
||||||
"fuzzy",
|
"fuzzy",
|
||||||
"go_to_line",
|
"go_to_line",
|
||||||
|
|
|
@ -6,6 +6,15 @@ use syn::{
|
||||||
parse_macro_input, Block, FnArg, ForeignItemFn, Ident, ItemFn, Pat, PatIdent, Type, Visibility,
|
parse_macro_input, Block, FnArg, ForeignItemFn, Ident, ItemFn, Pat, PatIdent, Type, Visibility,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Attribute macro to be used guest-side within a plugin.
|
||||||
|
/// ```ignore
|
||||||
|
/// #[export]
|
||||||
|
/// pub fn say_hello() -> String {
|
||||||
|
/// "Hello from Wasm".into()
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
/// This macro makes a function defined guest-side avaliable host-side.
|
||||||
|
/// Note that all arguments and return types must be `serde`.
|
||||||
#[proc_macro_attribute]
|
#[proc_macro_attribute]
|
||||||
pub fn export(args: TokenStream, function: TokenStream) -> TokenStream {
|
pub fn export(args: TokenStream, function: TokenStream) -> TokenStream {
|
||||||
if !args.is_empty() {
|
if !args.is_empty() {
|
||||||
|
@ -81,6 +90,14 @@ pub fn export(args: TokenStream, function: TokenStream) -> TokenStream {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Attribute macro to be used guest-side within a plugin.
|
||||||
|
/// ```ignore
|
||||||
|
/// #[import]
|
||||||
|
/// pub fn operating_system_name() -> String;
|
||||||
|
/// ```
|
||||||
|
/// This macro makes a function defined host-side avaliable guest-side.
|
||||||
|
/// Note that all arguments and return types must be `serde`.
|
||||||
|
/// All that's provided is a signature, as the function is implemented host-side.
|
||||||
#[proc_macro_attribute]
|
#[proc_macro_attribute]
|
||||||
pub fn import(args: TokenStream, function: TokenStream) -> TokenStream {
|
pub fn import(args: TokenStream, function: TokenStream) -> TokenStream {
|
||||||
if !args.is_empty() {
|
if !args.is_empty() {
|
||||||
|
|
|
@ -102,6 +102,9 @@ tree-sitter-toml = { git = "https://github.com/tree-sitter/tree-sitter-toml", re
|
||||||
tree-sitter-typescript = "0.20.1"
|
tree-sitter-typescript = "0.20.1"
|
||||||
url = "2.2"
|
url = "2.2"
|
||||||
|
|
||||||
|
# TODO(isaac): remove this
|
||||||
|
future-wrap = "0.1.1"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
text = { path = "../text", features = ["test-support"] }
|
text = { path = "../text", features = ["test-support"] }
|
||||||
editor = { path = "../editor", features = ["test-support"] }
|
editor = { path = "../editor", features = ["test-support"] }
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use client::http::HttpClient;
|
use client::http::HttpClient;
|
||||||
use futures::lock::Mutex;
|
use futures::lock::Mutex;
|
||||||
|
use futures::Future;
|
||||||
use futures::{future::BoxFuture, FutureExt};
|
use futures::{future::BoxFuture, FutureExt};
|
||||||
use gpui::executor::Background;
|
use gpui::executor::Background;
|
||||||
use language::{LanguageServerName, LspAdapter};
|
use language::{LanguageServerName, LspAdapter};
|
||||||
|
@ -8,6 +9,8 @@ use plugin_runtime::{Plugin, PluginBuilder, WasiFn};
|
||||||
use std::{any::Any, path::PathBuf, sync::Arc};
|
use std::{any::Any, path::PathBuf, sync::Arc};
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
|
|
||||||
|
use future_wrap::*;
|
||||||
|
|
||||||
pub async fn new_json(executor: Arc<Background>) -> Result<PluginLspAdapter> {
|
pub async fn new_json(executor: Arc<Background>) -> Result<PluginLspAdapter> {
|
||||||
let plugin = PluginBuilder::new_with_default_ctx()?
|
let plugin = PluginBuilder::new_with_default_ctx()?
|
||||||
.host_function_async("command", |command: String| async move {
|
.host_function_async("command", |command: String| async move {
|
||||||
|
@ -15,15 +18,20 @@ pub async fn new_json(executor: Arc<Background>) -> Result<PluginLspAdapter> {
|
||||||
dbg!(&command);
|
dbg!(&command);
|
||||||
let mut args = command.split(' ');
|
let mut args = command.split(' ');
|
||||||
let command = args.next().unwrap();
|
let command = args.next().unwrap();
|
||||||
smol::process::Command::new(command)
|
dbg!("Running command");
|
||||||
.args(args)
|
let future = smol::process::Command::new(command).args(args).output();
|
||||||
.output()
|
let future = future.wrap(|fut, cx| {
|
||||||
.await
|
dbg!("Poll command start");
|
||||||
.log_err()
|
let res = fut.poll(cx);
|
||||||
.map(|output| {
|
dbg!("Poll command end");
|
||||||
dbg!("done running command");
|
res
|
||||||
output.stdout
|
});
|
||||||
})
|
dbg!("blocked on future");
|
||||||
|
let future = smol::block_on(future);
|
||||||
|
future.log_err().map(|output| {
|
||||||
|
dbg!("done running command");
|
||||||
|
output.stdout
|
||||||
|
})
|
||||||
})?
|
})?
|
||||||
.init(include_bytes!("../../../../plugins/bin/json_language.wasm"))
|
.init(include_bytes!("../../../../plugins/bin/json_language.wasm"))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
|
@ -69,3 +69,15 @@ fn import_half(a: u32) -> u32;
|
||||||
pub fn half_async(a: u32) -> u32 {
|
pub fn half_async(a: u32) -> u32 {
|
||||||
import_half(a)
|
import_half(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[import]
|
||||||
|
fn command_async(command: String) -> Option<Vec<u8>>;
|
||||||
|
|
||||||
|
#[export]
|
||||||
|
pub fn echo_async(message: String) -> String {
|
||||||
|
let command = dbg!(format!("echo {}", message));
|
||||||
|
let result = command_async(command);
|
||||||
|
dbg!(&result);
|
||||||
|
let result = result.expect("Could not run command");
|
||||||
|
String::from_utf8_lossy(&result).to_string()
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue