Plugin json (#474)

* json encoder

* thread to pass messages

* description for example
This commit is contained in:
Fernando Herrera
2021-12-12 11:50:35 +00:00
committed by GitHub
parent f8e6620e48
commit 4d7dd23779
30 changed files with 1010 additions and 523 deletions

View File

@ -48,8 +48,8 @@ pub trait Command: Send + Sync + CommandClone {
self.name().contains(' ')
}
// Is a plugin command (returns plugin's name if yes)
fn is_plugin(&self) -> Option<&PathBuf> {
// Is a plugin command (returns plugin's path and encoding if yes)
fn is_plugin(&self) -> Option<(&PathBuf, &str)> {
None
}

View File

@ -230,11 +230,13 @@ impl EngineState {
self.plugin_decls().try_for_each(|decl| {
// A successful plugin registration already includes the plugin filename
// No need to check the None option
let path = decl.is_plugin().expect("plugin should have file name");
let (path, encoding) = decl.is_plugin().expect("plugin should have file name");
let file_name = path.to_str().expect("path should be a str");
serde_json::to_string_pretty(&decl.signature())
.map(|signature| format!("register {} {}\n\n", file_name, signature))
.map(|signature| {
format!("register {} -e {} {}\n\n", file_name, encoding, signature)
})
.map_err(|err| ShellError::PluginFailedToLoad(err.to_string()))
.and_then(|line| {
plugin_file

View File

@ -2,7 +2,7 @@ use miette::SourceSpan;
use serde::{Deserialize, Serialize};
/// A spanned area of interest, generic over what kind of thing is of interest
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Spanned<T>
where
T: Clone + std::fmt::Debug,