forked from 1b-agent/opencadstudio-upstream
style: apply cargo fmt across workspace
This commit is contained in:
1 parent
85710e5454
commit
9cf9ff2c5c
531 files changed
+57740
-33906
No files matched your search
+30
-14
@@ -289,9 +289,7 @@ pub(crate) fn parse_plugin_toml(text: &str) -> Option<ExternalPlugin> {
|
||||
continue;
|
||||
}
|
||||
if let Some(header) = line.strip_prefix('[') {
|
||||
section = header
|
||||
.find(']')
|
||||
.map(|end| header[..end].trim());
|
||||
section = header.find(']').map(|end| header[..end].trim());
|
||||
continue;
|
||||
}
|
||||
let Some((key, value)) = line.split_once('=') else {
|
||||
@@ -562,7 +560,10 @@ xdata_apps = ["MYPLUGIN_RECORD"]
|
||||
assert_eq!(p.api_version, 3);
|
||||
assert_eq!(p.repository.as_deref(), Some("example/opencad-my-plugin"));
|
||||
assert!(p.command_prefixes.contains(&"MP_".to_string()));
|
||||
assert!(p.api_compatible(), "V3 plugins must be accepted by the current host");
|
||||
assert!(
|
||||
p.api_compatible(),
|
||||
"V3 plugins must be accepted by the current host"
|
||||
);
|
||||
let v2 = parse_plugin_toml("id=\"old\"\napi_version = 2").expect("parsed");
|
||||
assert!(!v2.api_compatible(), "V2 plugins are no longer loaded");
|
||||
}
|
||||
@@ -646,7 +647,10 @@ rustc_version = ""
|
||||
let p = parse_plugin_toml(toml).expect("parsed");
|
||||
assert!(p.rustc_declared);
|
||||
assert!(p.rustc_version.is_none());
|
||||
assert!(!p.rustc_compatible(), "declared but empty rustc is incompatible");
|
||||
assert!(
|
||||
!p.rustc_compatible(),
|
||||
"declared but empty rustc is incompatible"
|
||||
);
|
||||
assert!(!p.loadable());
|
||||
}
|
||||
|
||||
@@ -681,7 +685,10 @@ rustc_version = "{other}"
|
||||
);
|
||||
let p = parse_plugin_toml(&toml).expect("parsed");
|
||||
assert!(p.rustc_declared);
|
||||
assert!(!p.rustc_compatible(), "mismatched rustc should be incompatible");
|
||||
assert!(
|
||||
!p.rustc_compatible(),
|
||||
"mismatched rustc should be incompatible"
|
||||
);
|
||||
assert!(!p.loadable());
|
||||
}
|
||||
|
||||
@@ -758,7 +765,10 @@ acadrust_source = ""
|
||||
let p = parse_plugin_toml(toml).expect("parsed");
|
||||
assert!(p.acadrust_declared);
|
||||
assert!(p.acadrust_source.is_none());
|
||||
assert!(!p.acadrust_compatible(), "declared but empty source is incompatible");
|
||||
assert!(
|
||||
!p.acadrust_compatible(),
|
||||
"declared but empty source is incompatible"
|
||||
);
|
||||
assert!(!p.loadable());
|
||||
}
|
||||
|
||||
@@ -797,7 +807,10 @@ acadrust_source = "{other}"
|
||||
);
|
||||
let p = parse_plugin_toml(&toml).expect("parsed");
|
||||
assert!(p.acadrust_declared);
|
||||
assert!(!p.acadrust_compatible(), "mismatched opencadcodec fingerprint should be incompatible");
|
||||
assert!(
|
||||
!p.acadrust_compatible(),
|
||||
"mismatched opencadcodec fingerprint should be incompatible"
|
||||
);
|
||||
assert!(!p.loadable());
|
||||
}
|
||||
|
||||
@@ -818,7 +831,10 @@ acadrust_source = "{host}"
|
||||
);
|
||||
let p = parse_plugin_toml(&toml).expect("parsed");
|
||||
assert!(p.acadrust_declared);
|
||||
assert!(p.acadrust_compatible(), "matching opencadcodec fingerprint should be compatible");
|
||||
assert!(
|
||||
p.acadrust_compatible(),
|
||||
"matching opencadcodec fingerprint should be compatible"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -870,11 +886,11 @@ acadrust_source = "git+https://github.com/HakanSeven12/opencadcodec.git?rev=0908
|
||||
let mut app = crate::app::OpenCADStudio::new_for_test();
|
||||
let mut host = crate::app::plugin_host::HostSession::new(&mut app, 0);
|
||||
let process = ocs_plugin_api::process::PluginProcess::spawn(
|
||||
&path,
|
||||
&mut host,
|
||||
v4_support::notification_handler(),
|
||||
)
|
||||
.expect("spawn test plugin");
|
||||
&path,
|
||||
&mut host,
|
||||
v4_support::notification_handler(),
|
||||
)
|
||||
.expect("spawn test plugin");
|
||||
assert_eq!(process.id(), "opencad.my_plugin");
|
||||
let mut started = false;
|
||||
let handled = process
|
||||
|
||||
+1
-1
@@ -5,4 +5,4 @@
|
||||
// plugin-facing contract — `BuiltinPlugin` + `HostApi` — lives in
|
||||
// `ocs_plugin_api`; external cdylibs target it directly.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) use crate::app::plugin_host::HostSession;
|
||||
pub(crate) use crate::app::plugin_host::HostSession;
|
||||
+28
-21
@@ -228,19 +228,18 @@ pub fn fetch_release_info(repo: &str) -> Result<Vec<ReleaseInfo>, String> {
|
||||
);
|
||||
let rustc_version = manifest.rustc_version.clone();
|
||||
let rustc_declared = manifest.rustc_declared;
|
||||
let rustc_compatible = if !ocs_plugin_api::version_info::uses_acadrust_gate(
|
||||
manifest.api_version,
|
||||
) {
|
||||
true
|
||||
} else {
|
||||
match rustc_version.as_deref() {
|
||||
None | Some("") => false,
|
||||
Some(version) => ocs_plugin_api::version_info::rustc_versions_compatible(
|
||||
version,
|
||||
ocs_plugin_api::version_info::host_rustc_version(),
|
||||
),
|
||||
}
|
||||
};
|
||||
let rustc_compatible =
|
||||
if !ocs_plugin_api::version_info::uses_acadrust_gate(manifest.api_version) {
|
||||
true
|
||||
} else {
|
||||
match rustc_version.as_deref() {
|
||||
None | Some("") => false,
|
||||
Some(version) => ocs_plugin_api::version_info::rustc_versions_compatible(
|
||||
version,
|
||||
ocs_plugin_api::version_info::host_rustc_version(),
|
||||
),
|
||||
}
|
||||
};
|
||||
Ok::<_, String>(ReleaseInfo {
|
||||
tag: release.tag,
|
||||
api_version: manifest.api_version,
|
||||
@@ -331,20 +330,24 @@ pub fn install(release: &Release, repository: &str) -> Result<String, String> {
|
||||
|
||||
if ocs_plugin_api::version_info::uses_acadrust_gate(manifest.api_version) {
|
||||
let Some(source) = manifest.acadrust_source.as_deref() else {
|
||||
return Err("Release has no opencadcodec source; cannot verify ABI compatibility".to_string());
|
||||
return Err(
|
||||
"Release has no opencadcodec source; cannot verify ABI compatibility".to_string(),
|
||||
);
|
||||
};
|
||||
if source.is_empty() {
|
||||
return Err("Release has no opencadcodec source; cannot verify ABI compatibility".to_string());
|
||||
return Err(
|
||||
"Release has no opencadcodec source; cannot verify ABI compatibility".to_string(),
|
||||
);
|
||||
}
|
||||
if !ocs_plugin_api::version_info::acadrust_sources_compatible(
|
||||
source,
|
||||
ocs_plugin_api::version_info::host_acadrust_source(),
|
||||
) {
|
||||
let host_src = ocs_plugin_api::version_info::host_acadrust_source();
|
||||
let plugin_hash = ocs_plugin_api::version_info::acadrust_source_hash(source)
|
||||
.unwrap_or("unknown");
|
||||
let host_hash = ocs_plugin_api::version_info::acadrust_source_hash(host_src)
|
||||
.unwrap_or("unknown");
|
||||
let plugin_hash =
|
||||
ocs_plugin_api::version_info::acadrust_source_hash(source).unwrap_or("unknown");
|
||||
let host_hash =
|
||||
ocs_plugin_api::version_info::acadrust_source_hash(host_src).unwrap_or("unknown");
|
||||
return Err(format!(
|
||||
"Plugin built for opencadcodec @{plugin_hash}, but this host uses @{host_hash}"
|
||||
));
|
||||
@@ -353,10 +356,14 @@ pub fn install(release: &Release, repository: &str) -> Result<String, String> {
|
||||
|
||||
if ocs_plugin_api::version_info::uses_acadrust_gate(manifest.api_version) {
|
||||
let Some(version) = manifest.rustc_version.as_deref() else {
|
||||
return Err("Release has no rustc version; cannot verify ABI compatibility".to_string());
|
||||
return Err(
|
||||
"Release has no rustc version; cannot verify ABI compatibility".to_string(),
|
||||
);
|
||||
};
|
||||
if version.is_empty() {
|
||||
return Err("Release has no rustc version; cannot verify ABI compatibility".to_string());
|
||||
return Err(
|
||||
"Release has no rustc version; cannot verify ABI compatibility".to_string(),
|
||||
);
|
||||
}
|
||||
if !ocs_plugin_api::version_info::rustc_versions_compatible(
|
||||
version,
|
||||
|
||||
+6
-4
@@ -9,8 +9,8 @@ pub mod registry;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub mod v4_support;
|
||||
|
||||
pub use registry::{all_ribbon_modules, plugin_command_names, ribbon_modules_enabled};
|
||||
pub(crate) use registry::try_dispatch;
|
||||
pub use registry::{all_ribbon_modules, plugin_command_names, ribbon_modules_enabled};
|
||||
|
||||
/// Run a plugin entry point under a panic guard so a buggy external plugin
|
||||
/// can't take down the host. Returns `None` (after logging) when the plugin
|
||||
@@ -66,8 +66,8 @@ mod tests {
|
||||
#[test]
|
||||
fn swallows_panic_and_queues_error_message() {
|
||||
let _ = super::drain_errors(); // clear anything from earlier tests
|
||||
// Silence the default panic-hook stderr noise during the test (the
|
||||
// guard's own eprintln stays — that's the diagnostic we want).
|
||||
// Silence the default panic-hook stderr noise during the test (the
|
||||
// guard's own eprintln stays — that's the diagnostic we want).
|
||||
let prev = std::panic::take_hook();
|
||||
std::panic::set_hook(Box::new(|_| {}));
|
||||
let r: Option<i32> = guard("boom", || panic!("plugin went wrong"));
|
||||
@@ -77,7 +77,9 @@ mod tests {
|
||||
// loop drains it into the command line on the next tick).
|
||||
let queued = super::drain_errors();
|
||||
assert!(
|
||||
queued.iter().any(|m| m.contains("boom") && m.contains("plugin went wrong")),
|
||||
queued
|
||||
.iter()
|
||||
.any(|m| m.contains("boom") && m.contains("plugin went wrong")),
|
||||
"expected an error queued for the command line, got: {queued:?}"
|
||||
);
|
||||
}
|
||||
|
||||
+11
-10
@@ -12,9 +12,7 @@ pub fn all_ribbon_modules() -> Vec<Box<dyn CadModule>> {
|
||||
|
||||
/// Core ribbon tabs plus the tabs of loaded external plugins whose id is **not**
|
||||
/// in `disabled` (sorted by `manifest.ribbon_order`).
|
||||
pub fn ribbon_modules_enabled(
|
||||
disabled: &rustc_hash::FxHashSet<String>,
|
||||
) -> Vec<Box<dyn CadModule>> {
|
||||
pub fn ribbon_modules_enabled(disabled: &rustc_hash::FxHashSet<String>) -> Vec<Box<dyn CadModule>> {
|
||||
#[cfg_attr(target_arch = "wasm32", allow(unused_mut))]
|
||||
let mut core = core_registry::all_modules();
|
||||
// Dynamically-loaded external plugins contribute tabs via the crate manager.
|
||||
@@ -22,9 +20,11 @@ pub fn ribbon_modules_enabled(
|
||||
{
|
||||
crate::plugin::external::with_manager(|manager| {
|
||||
let addons = manager.ribbon_modules(|id| disabled.contains(id));
|
||||
core.extend(addons.into_iter().map(|(_, module)| {
|
||||
Box::new(module) as Box<dyn CadModule>
|
||||
}));
|
||||
core.extend(
|
||||
addons
|
||||
.into_iter()
|
||||
.map(|(_, module)| Box::new(module) as Box<dyn CadModule>),
|
||||
);
|
||||
});
|
||||
}
|
||||
let _ = disabled;
|
||||
@@ -71,10 +71,11 @@ pub(crate) fn try_dispatch(app: &mut OpenCADStudio, tab: usize, cmd: &str) -> bo
|
||||
if let Some((process, command_id)) = result.started {
|
||||
app.set_active_command(
|
||||
tab,
|
||||
Box::new(crate::app::plugin_host::PluginProcessInteractiveAdapter::new(
|
||||
process,
|
||||
command_id,
|
||||
)),
|
||||
Box::new(
|
||||
crate::app::plugin_host::PluginProcessInteractiveAdapter::new(
|
||||
process, command_id,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return result.handled;
|
||||
|
||||
@@ -12,10 +12,7 @@ fn mgr() -> std::sync::MutexGuard<'static, HostV4SnapshotManager> {
|
||||
}
|
||||
|
||||
/// Open (or refresh) the V4 shared document view for `tab_id`.
|
||||
pub fn open_document_view_v4(
|
||||
tab_id: u64,
|
||||
doc: &codec::CadDocument,
|
||||
) -> Option<DocumentViewInfo> {
|
||||
pub fn open_document_view_v4(tab_id: u64, doc: &codec::CadDocument) -> Option<DocumentViewInfo> {
|
||||
mgr().open(tab_id, doc)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user