Skip to main content

vs_plugin_api/
host.rs

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