since_v0_0_6.rs

  1use super::{latest, since_v0_1_0};
  2use crate::wasm_host::WasmState;
  3use anyhow::Result;
  4use extension::WorktreeDelegate;
  5use semantic_version::SemanticVersion;
  6use std::sync::{Arc, OnceLock};
  7use wasmtime::component::{Linker, Resource};
  8
  9pub const MIN_VERSION: SemanticVersion = SemanticVersion::new(0, 0, 6);
 10
 11wasmtime::component::bindgen!({
 12    async: true,
 13    trappable_imports: true,
 14    path: "../extension_api/wit/since_v0.0.6",
 15    with: {
 16         "worktree": ExtensionWorktree,
 17         "zed:extension/github": latest::zed::extension::github,
 18         "zed:extension/lsp": since_v0_1_0::zed::extension::lsp,
 19         "zed:extension/nodejs": latest::zed::extension::nodejs,
 20         "zed:extension/platform": latest::zed::extension::platform,
 21    },
 22});
 23
 24mod settings {
 25    include!(concat!(env!("OUT_DIR"), "/since_v0.0.6/settings.rs"));
 26}
 27
 28pub type ExtensionWorktree = Arc<dyn WorktreeDelegate>;
 29
 30pub fn linker() -> &'static Linker<WasmState> {
 31    static LINKER: OnceLock<Linker<WasmState>> = OnceLock::new();
 32    LINKER.get_or_init(|| super::new_linker(Extension::add_to_linker))
 33}
 34
 35impl From<Command> for latest::Command {
 36    fn from(value: Command) -> Self {
 37        Self {
 38            command: value.command,
 39            args: value.args,
 40            env: value.env,
 41        }
 42    }
 43}
 44
 45impl From<SettingsLocation> for latest::SettingsLocation {
 46    fn from(value: SettingsLocation) -> Self {
 47        Self {
 48            worktree_id: value.worktree_id,
 49            path: value.path,
 50        }
 51    }
 52}
 53
 54impl From<LanguageServerInstallationStatus> for latest::LanguageServerInstallationStatus {
 55    fn from(value: LanguageServerInstallationStatus) -> Self {
 56        match value {
 57            LanguageServerInstallationStatus::None => Self::None,
 58            LanguageServerInstallationStatus::Downloading => Self::Downloading,
 59            LanguageServerInstallationStatus::CheckingForUpdate => Self::CheckingForUpdate,
 60            LanguageServerInstallationStatus::Failed(message) => Self::Failed(message),
 61        }
 62    }
 63}
 64
 65impl From<DownloadedFileType> for latest::DownloadedFileType {
 66    fn from(value: DownloadedFileType) -> Self {
 67        match value {
 68            DownloadedFileType::Gzip => Self::Gzip,
 69            DownloadedFileType::GzipTar => Self::GzipTar,
 70            DownloadedFileType::Zip => Self::Zip,
 71            DownloadedFileType::Uncompressed => Self::Uncompressed,
 72        }
 73    }
 74}
 75
 76impl From<Range> for latest::Range {
 77    fn from(value: Range) -> Self {
 78        Self {
 79            start: value.start,
 80            end: value.end,
 81        }
 82    }
 83}
 84
 85impl From<CodeLabelSpan> for latest::CodeLabelSpan {
 86    fn from(value: CodeLabelSpan) -> Self {
 87        match value {
 88            CodeLabelSpan::CodeRange(range) => Self::CodeRange(range.into()),
 89            CodeLabelSpan::Literal(literal) => Self::Literal(literal.into()),
 90        }
 91    }
 92}
 93
 94impl From<CodeLabelSpanLiteral> for latest::CodeLabelSpanLiteral {
 95    fn from(value: CodeLabelSpanLiteral) -> Self {
 96        Self {
 97            text: value.text,
 98            highlight_name: value.highlight_name,
 99        }
100    }
101}
102
103impl From<CodeLabel> for latest::CodeLabel {
104    fn from(value: CodeLabel) -> Self {
105        Self {
106            code: value.code,
107            spans: value.spans.into_iter().map(Into::into).collect(),
108            filter_range: value.filter_range.into(),
109        }
110    }
111}
112
113impl HostWorktree for WasmState {
114    async fn id(&mut self, delegate: Resource<Arc<dyn WorktreeDelegate>>) -> wasmtime::Result<u64> {
115        latest::HostWorktree::id(self, delegate).await
116    }
117
118    async fn root_path(
119        &mut self,
120        delegate: Resource<Arc<dyn WorktreeDelegate>>,
121    ) -> wasmtime::Result<String> {
122        latest::HostWorktree::root_path(self, delegate).await
123    }
124
125    async fn read_text_file(
126        &mut self,
127        delegate: Resource<Arc<dyn WorktreeDelegate>>,
128        path: String,
129    ) -> wasmtime::Result<Result<String, String>> {
130        latest::HostWorktree::read_text_file(self, delegate, path).await
131    }
132
133    async fn shell_env(
134        &mut self,
135        delegate: Resource<Arc<dyn WorktreeDelegate>>,
136    ) -> wasmtime::Result<EnvVars> {
137        latest::HostWorktree::shell_env(self, delegate).await
138    }
139
140    async fn which(
141        &mut self,
142        delegate: Resource<Arc<dyn WorktreeDelegate>>,
143        binary_name: String,
144    ) -> wasmtime::Result<Option<String>> {
145        latest::HostWorktree::which(self, delegate, binary_name).await
146    }
147
148    async fn drop(&mut self, _worktree: Resource<Worktree>) -> Result<()> {
149        // We only ever hand out borrows of worktrees.
150        Ok(())
151    }
152}
153
154impl ExtensionImports for WasmState {
155    async fn get_settings(
156        &mut self,
157        location: Option<self::SettingsLocation>,
158        category: String,
159        key: Option<String>,
160    ) -> wasmtime::Result<Result<String, String>> {
161        latest::ExtensionImports::get_settings(
162            self,
163            location.map(|location| location.into()),
164            category,
165            key,
166        )
167        .await
168    }
169
170    async fn set_language_server_installation_status(
171        &mut self,
172        server_name: String,
173        status: LanguageServerInstallationStatus,
174    ) -> wasmtime::Result<()> {
175        latest::ExtensionImports::set_language_server_installation_status(
176            self,
177            server_name,
178            status.into(),
179        )
180        .await
181    }
182
183    async fn download_file(
184        &mut self,
185        url: String,
186        path: String,
187        file_type: DownloadedFileType,
188    ) -> wasmtime::Result<Result<(), String>> {
189        latest::ExtensionImports::download_file(self, url, path, file_type.into()).await
190    }
191
192    async fn make_file_executable(&mut self, path: String) -> wasmtime::Result<Result<(), String>> {
193        latest::ExtensionImports::make_file_executable(self, path).await
194    }
195}