Skip to content

The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.

1.9 KB
Raw Blame
//! `PluginEngine::check_component` (what installing and `openidea-plugin check`
//! run) refuses a component the IDE could not start: every import has to link
//! against the host, function by function, and the plugin world's exports have
//! to be there, not only the interface names and their API version.

use ide_plugin::PluginEngine;

fn check(wat: &str) -> Result<Option<semver::Version>, String> {
    let engine = PluginEngine::new().unwrap();
    let component = engine.compile_bytes(&wat::parse_str(wat).unwrap()).unwrap();
    engine.check_component(&component)
}

#[test]
fn components_the_host_cannot_link_are_refused() {
    let cases = [
        // As dengliu.gitlink 0.1.0 was: built from unreleased WIT that added functions under the same version.
        (
            "a function the host's interface lacks",
            r#"(component (import "openidea:plugin/[email protected]" (instance
                (export "not-a-host-function" (func (param "text" string))))))"#,
            "not-a-host-function",
        ),
        (
            "a function with another signature",
            r#"(component (import "openidea:plugin/[email protected]" (instance
                (export "show-notification" (func (param "title" string))))))"#,
            "show-notification",
        ),
        (
            "an interface the host lacks",
            r#"(component (import "openidea:plugin/[email protected]" (instance
                (export "copy" (func (param "text" string))))))"#,
            "openidea:plugin/[email protected]",
        ),
        ("no plugin exports", r#"(component (import "openidea:plugin/[email protected]" (instance)))"#, "lifecycle"),
    ];
    for (case, wat, names) in cases {
        let err = check(wat).expect_err(case);
        assert!(err.contains(names), "{case}: {err}");
        assert!(err.contains("update OpenIDEA") && err.contains("rebuild"), "{case}: {err}");
    }
}