Skip to main content

vs_plugin_api/
host.rs

1//! Host-facing traits implemented by plugin backends.
2
3use std::path::Path;
4
5use crate::error::PluginResult;
6use crate::model::{AvailableVersion, EnvKey, InstallPlan, InstalledRuntime, PluginManifest};
7
8/// Common runtime interface used by the application layer.
9pub trait Plugin {
10    /// Returns the immutable plugin manifest.
11    fn manifest(&self) -> &PluginManifest;
12
13    /// Lists versions that the plugin can install.
14    fn available_versions(&self, args: &[String]) -> PluginResult<Vec<AvailableVersion>>;
15
16    /// Builds an install plan for the requested version.
17    fn install_plan(&self, version: &str) -> PluginResult<InstallPlan>;
18
19    /// Runs optional post-install logic after artifacts are materialized.
20    fn post_install(&self, _runtime: &InstalledRuntime) -> PluginResult<()> {
21        Ok(())
22    }
23
24    /// Returns environment keys that should be exported for the installed version.
25    fn env_keys(&self, runtime: &InstalledRuntime) -> PluginResult<Vec<EnvKey>>;
26
27    /// Allows a plugin to map the requested version before activation.
28    fn pre_use(
29        &self,
30        _requested_version: &str,
31        _scope: &str,
32        _cwd: &Path,
33        _previous_version: Option<&str>,
34        _installed: &[InstalledRuntime],
35    ) -> PluginResult<Option<String>> {
36        Ok(None)
37    }
38
39    /// Attempts to map a legacy file content to a version.
40    fn parse_legacy_file(
41        &self,
42        file_name: &str,
43        file_path: &Path,
44        content: &str,
45        installed_versions: &[String],
46        strategy: &str,
47    ) -> PluginResult<Option<String>>;
48
49    /// Runs optional pre-uninstall logic before a version is removed.
50    fn pre_uninstall(&self, _runtime: &InstalledRuntime) -> PluginResult<()> {
51        Ok(())
52    }
53}