since_v0_0_6.rs

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