-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plugins: Apply changes for shared types in host.
* Make the need adjustments after separating the plugins to different packages unifying the implementation for the shared types. * Generating the shared types doesn't generate not referenced types with `bindgen!()` macro. The current workaround is to generate the types from parser package inside the shared module.
- Loading branch information
1 parent
2eac9b0
commit d039c42
Showing
12 changed files
with
313 additions
and
317 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
use std::io; | ||
|
||
use crate::PluginGuestInitError; | ||
|
||
pub use self::chipmunk::plugin::{bytesource_types, shared_types}; | ||
use self::shared_types::{ConfigItem, ConfigSchemaItem, ConfigSchemaType, ConfigValue, Version}; | ||
pub use self::chipmunk::bytesource::bytesource_types; | ||
|
||
wasmtime::component::bindgen!({ | ||
path: "../plugins_api/wit/v_0.1.0/", | ||
world: "bytesource-plugin", | ||
path: "../plugins_api/wit/v0.1.0", | ||
world: "chipmunk:bytesource/bytesource", | ||
async: { | ||
only_imports: [], | ||
}, | ||
with: { | ||
"chipmunk:shared/[email protected]": crate::v0_1_0::shared::logging, | ||
"chipmunk:shared/[email protected]": crate::v0_1_0::shared::shared_types, | ||
} | ||
}); | ||
|
||
impl From<&stypes::PluginByteSourceGeneralSettings> for bytesource_types::SourceConfig { | ||
|
@@ -19,7 +20,7 @@ impl From<&stypes::PluginByteSourceGeneralSettings> for bytesource_types::Source | |
// functionality to log the message from the plugins. | ||
let current_log_level = log::max_level().to_level().unwrap_or(log::Level::Error); | ||
|
||
use chipmunk::plugin::logging::Level as PlugLevel; | ||
use crate::v0_1_0::shared::logging::Level as PlugLevel; | ||
let level = match current_log_level { | ||
log::Level::Error => PlugLevel::Error, | ||
log::Level::Warn => PlugLevel::Warn, | ||
|
@@ -32,93 +33,15 @@ impl From<&stypes::PluginByteSourceGeneralSettings> for bytesource_types::Source | |
} | ||
} | ||
|
||
impl From<shared_types::InitError> for PluginGuestInitError { | ||
fn from(value: shared_types::InitError) -> Self { | ||
use shared_types::InitError as E; | ||
use PluginGuestInitError as GuestE; | ||
match value { | ||
E::Config(msg) => GuestE::Config(msg), | ||
E::Io(msg) => GuestE::IO(msg), | ||
E::Unsupported(msg) => GuestE::Unsupported(msg), | ||
E::Other(msg) => GuestE::Other(msg), | ||
} | ||
} | ||
} | ||
|
||
impl From<bytesource_types::SourceError> for io::Error { | ||
fn from(value: bytesource_types::SourceError) -> Self { | ||
use bytesource_types::SourceError as E; | ||
let msg = match value { | ||
E::Io(msg) => format!("IO Error from bytesoruce plugin. Error: {msg}"), | ||
E::Unsupported => String::from("Unsupported Error from bytesource plugin"), | ||
E::Unsupported(msg) => format!("Unsupported Error from bytesource plugin: {msg}"), | ||
E::Other(msg) => format!("Unknown Error from bytesoruce plugin. Error: {msg}"), | ||
}; | ||
|
||
io::Error::new(io::ErrorKind::Other, msg) | ||
} | ||
} | ||
|
||
use stypes::PluginConfigValue as HostConfValue; | ||
impl From<HostConfValue> for ConfigValue { | ||
fn from(value: HostConfValue) -> Self { | ||
match value { | ||
HostConfValue::Boolean(val) => ConfigValue::Boolean(val), | ||
HostConfValue::Integer(val) => ConfigValue::Integer(val), | ||
HostConfValue::Float(val) => ConfigValue::Float(val), | ||
HostConfValue::Text(val) => ConfigValue::Text(val), | ||
HostConfValue::Files(val) => ConfigValue::Files( | ||
val.into_iter() | ||
.map(|p| p.to_string_lossy().to_string()) | ||
.collect(), | ||
), | ||
HostConfValue::Directories(val) => ConfigValue::Directories( | ||
val.into_iter() | ||
.map(|p| p.to_string_lossy().to_string()) | ||
.collect(), | ||
), | ||
HostConfValue::Dropdown(val) => ConfigValue::Dropdown(val), | ||
} | ||
} | ||
} | ||
|
||
impl From<stypes::PluginConfigItem> for ConfigItem { | ||
fn from(item: stypes::PluginConfigItem) -> Self { | ||
Self { | ||
id: item.id, | ||
value: item.value.into(), | ||
} | ||
} | ||
} | ||
|
||
use stypes::PluginConfigSchemaType as HostSchemaType; | ||
use stypes::SemanticVersion; | ||
impl From<ConfigSchemaType> for HostSchemaType { | ||
fn from(value: ConfigSchemaType) -> Self { | ||
match value { | ||
ConfigSchemaType::Boolean => HostSchemaType::Boolean, | ||
ConfigSchemaType::Integer => HostSchemaType::Integer, | ||
ConfigSchemaType::Float => HostSchemaType::Float, | ||
ConfigSchemaType::Text => HostSchemaType::Text, | ||
ConfigSchemaType::Directories => HostSchemaType::Directories, | ||
ConfigSchemaType::Files(exts) => HostSchemaType::Files(exts), | ||
ConfigSchemaType::Dropdown(items) => HostSchemaType::Dropdown(items), | ||
} | ||
} | ||
} | ||
|
||
impl From<ConfigSchemaItem> for stypes::PluginConfigSchemaItem { | ||
fn from(item: ConfigSchemaItem) -> Self { | ||
Self { | ||
id: item.id, | ||
title: item.title, | ||
description: item.description, | ||
input_type: item.input_type.into(), | ||
} | ||
} | ||
} | ||
|
||
impl From<Version> for SemanticVersion { | ||
fn from(value: Version) -> Self { | ||
Self::new(value.major, value.minor, value.patch) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod bytesource; | ||
pub mod parser; | ||
pub mod shared; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
use crate::{parser_shared::COLUMN_SEP, PluginGuestInitError, PluginParseMessage}; | ||
use crate::{parser_shared::COLUMN_SEP, PluginParseMessage}; | ||
|
||
pub use self::chipmunk::plugin::{parse_types::*, shared_types::*}; | ||
pub use self::chipmunk::parser::parse_types::*; | ||
|
||
use stypes::{ParserRenderOptions, PluginConfigValue as HostConfValue, SemanticVersion}; | ||
use stypes::ParserRenderOptions; | ||
|
||
wasmtime::component::bindgen!({ | ||
path: "../plugins_api/wit/v_0.1.0/", | ||
world: "parse-plugin", | ||
path: "../plugins_api/wit/v0.1.0", | ||
world: "chipmunk:parser/parse", | ||
async: { | ||
only_imports: [], | ||
}, | ||
with: { | ||
"chipmunk:shared/[email protected]": crate::v0_1_0::shared::logging, | ||
"chipmunk:shared/[email protected]": crate::v0_1_0::shared::shared_types, | ||
} | ||
}); | ||
|
||
impl From<&stypes::PluginParserGeneralSettings> for ParserConfig { | ||
|
@@ -18,7 +22,7 @@ impl From<&stypes::PluginParserGeneralSettings> for ParserConfig { | |
// functionality to log the message from the plugins. | ||
let current_log_level = log::max_level().to_level().unwrap_or(log::Level::Error); | ||
|
||
use chipmunk::plugin::logging::Level as PlugLevel; | ||
use crate::v0_1_0::shared::logging::Level as PlugLevel; | ||
let level = match current_log_level { | ||
log::Level::Error => PlugLevel::Error, | ||
log::Level::Warn => PlugLevel::Warn, | ||
|
@@ -31,18 +35,6 @@ impl From<&stypes::PluginParserGeneralSettings> for ParserConfig { | |
} | ||
} | ||
|
||
impl From<InitError> for PluginGuestInitError { | ||
fn from(value: InitError) -> Self { | ||
use PluginGuestInitError as GuestErr; | ||
match value { | ||
InitError::Config(msg) => GuestErr::Config(msg), | ||
InitError::Io(msg) => GuestErr::IO(msg), | ||
InitError::Unsupported(msg) => GuestErr::Unsupported(msg), | ||
InitError::Other(msg) => GuestErr::Other(msg), | ||
} | ||
} | ||
} | ||
|
||
use parsers as p; | ||
|
||
impl From<ParseYield> for p::ParseYield<PluginParseMessage> { | ||
|
@@ -92,69 +84,6 @@ impl From<ParsedMessage> for PluginParseMessage { | |
} | ||
} | ||
|
||
impl From<HostConfValue> for ConfigValue { | ||
fn from(value: HostConfValue) -> Self { | ||
match value { | ||
HostConfValue::Boolean(val) => ConfigValue::Boolean(val), | ||
HostConfValue::Integer(val) => ConfigValue::Integer(val), | ||
HostConfValue::Float(val) => ConfigValue::Float(val), | ||
HostConfValue::Text(val) => ConfigValue::Text(val), | ||
HostConfValue::Files(val) => ConfigValue::Files( | ||
val.into_iter() | ||
.map(|p| p.to_string_lossy().to_string()) | ||
.collect(), | ||
), | ||
HostConfValue::Directories(val) => ConfigValue::Directories( | ||
val.into_iter() | ||
.map(|p| p.to_string_lossy().to_string()) | ||
.collect(), | ||
), | ||
HostConfValue::Dropdown(val) => ConfigValue::Dropdown(val), | ||
} | ||
} | ||
} | ||
|
||
impl From<stypes::PluginConfigItem> for ConfigItem { | ||
fn from(item: stypes::PluginConfigItem) -> Self { | ||
Self { | ||
id: item.id, | ||
value: item.value.into(), | ||
} | ||
} | ||
} | ||
|
||
use stypes::PluginConfigSchemaType as HostSchemaType; | ||
impl From<ConfigSchemaType> for HostSchemaType { | ||
fn from(value: ConfigSchemaType) -> Self { | ||
match value { | ||
ConfigSchemaType::Boolean => HostSchemaType::Boolean, | ||
ConfigSchemaType::Integer => HostSchemaType::Integer, | ||
ConfigSchemaType::Float => HostSchemaType::Float, | ||
ConfigSchemaType::Text => HostSchemaType::Text, | ||
ConfigSchemaType::Directories => HostSchemaType::Directories, | ||
ConfigSchemaType::Files(exts) => HostSchemaType::Files(exts), | ||
ConfigSchemaType::Dropdown(items) => HostSchemaType::Dropdown(items), | ||
} | ||
} | ||
} | ||
|
||
impl From<ConfigSchemaItem> for stypes::PluginConfigSchemaItem { | ||
fn from(item: ConfigSchemaItem) -> Self { | ||
Self { | ||
id: item.id, | ||
title: item.title, | ||
description: item.description, | ||
input_type: item.input_type.into(), | ||
} | ||
} | ||
} | ||
|
||
impl From<Version> for SemanticVersion { | ||
fn from(value: Version) -> Self { | ||
Self::new(value.major, value.minor, value.patch) | ||
} | ||
} | ||
|
||
impl From<RenderOptions> for ParserRenderOptions { | ||
fn from(value: RenderOptions) -> Self { | ||
Self { | ||
|
Oops, something went wrong.