Skip to content

Commit

Permalink
ruby_runtime: draft
Browse files Browse the repository at this point in the history
  • Loading branch information
vitallium committed Feb 21, 2025
1 parent c18be3e commit 7a47372
Show file tree
Hide file tree
Showing 19 changed files with 460 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ members = [
"crates/rich_text",
"crates/rope",
"crates/rpc",
"crates/ruby_runtime",
"crates/schema_generator",
"crates/search",
"crates/semantic_index",
Expand Down Expand Up @@ -313,6 +314,7 @@ reqwest_client = { path = "crates/reqwest_client" }
rich_text = { path = "crates/rich_text" }
rope = { path = "crates/rope" }
rpc = { path = "crates/rpc" }
ruby_runtime = { path = "crates/ruby_runtime" }
search = { path = "crates/search" }
semantic_index = { path = "crates/semantic_index" }
semantic_version = { path = "crates/semantic_version" }
Expand Down
3 changes: 3 additions & 0 deletions crates/extension_api/src/extension_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ pub use wit::{
npm_package_latest_version,
},
zed::extension::platform::{current_platform, Architecture, Os},
zed::extension::ruby::{
gems_install_gem, gems_installed_version, gems_latest_version, ruby_binary_path,
},
zed::extension::slash_command::{
SlashCommand, SlashCommandArgumentCompletion, SlashCommandOutput, SlashCommandOutputSection,
},
Expand Down
1 change: 1 addition & 0 deletions crates/extension_api/wit/since_v0.2.0/extension.wit
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ world extension {
import http-client;
import platform;
import nodejs;
import ruby;

use common.{range};
use lsp.{completion, symbol};
Expand Down
13 changes: 13 additions & 0 deletions crates/extension_api/wit/since_v0.2.0/ruby.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
interface ruby {
/// Returns the path to the currently active Ruby binary.
ruby-binary-path: func() -> result<string, string>;

/// Returns the latest version of the given Ruby gem.
gems-latest-version: func(gem-name: string) -> result<string, string>;

/// Returns the installed version of the given Ruby gem, if it exists.
gems-installed-version: func(gem-name: string) -> result<option<string>, string>;

/// Installs the specified Ruby gem.
gems-install-gem: func(gem-name: string, version: string, binaries: list<string>) -> result<_, string>;
}
1 change: 1 addition & 0 deletions crates/extension_host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ paths.workspace = true
project.workspace = true
remote.workspace = true
release_channel.workspace = true
ruby_runtime.workspace = true
schemars.workspace = true
semantic_version.workspace = true
serde.workspace = true
Expand Down
5 changes: 5 additions & 0 deletions crates/extension_host/src/extension_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use node_runtime::NodeRuntime;
use project::ContextProviderWithTasks;
use release_channel::ReleaseChannel;
use remote::SshRemoteClient;
use ruby_runtime::RubyRuntime;
use semantic_version::SemanticVersion;
use serde::{Deserialize, Serialize};
use settings::Settings;
Expand Down Expand Up @@ -182,6 +183,7 @@ pub fn init(
fs: Arc<dyn Fs>,
client: Arc<Client>,
node_runtime: NodeRuntime,
ruby_runtime: RubyRuntime,
cx: &mut App,
) {
ExtensionSettings::register(cx);
Expand All @@ -196,6 +198,7 @@ pub fn init(
client.http_client().clone(),
Some(client.telemetry().clone()),
node_runtime,
ruby_runtime,
cx,
)
});
Expand Down Expand Up @@ -228,6 +231,7 @@ impl ExtensionStore {
builder_client: Arc<dyn HttpClient>,
telemetry: Option<Arc<Telemetry>>,
node_runtime: NodeRuntime,
ruby_runtime: RubyRuntime,
cx: &mut Context<Self>,
) -> Self {
let work_dir = extensions_dir.join("work");
Expand All @@ -250,6 +254,7 @@ impl ExtensionStore {
fs.clone(),
http_client.clone(),
node_runtime,
ruby_runtime,
extension_host_proxy,
work_dir,
cx,
Expand Down
6 changes: 6 additions & 0 deletions crates/extension_host/src/extension_store_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use parking_lot::Mutex;
use project::{Project, DEFAULT_COMPLETION_CONTEXT};
use release_channel::AppVersion;
use reqwest_client::ReqwestClient;
use ruby_runtime::RubyRuntime;
use serde_json::json;
use settings::{Settings as _, SettingsStore};
use std::{
Expand Down Expand Up @@ -269,6 +270,7 @@ async fn test_extension_store(cx: &mut TestAppContext) {
let language_registry = Arc::new(LanguageRegistry::test(cx.executor()));
language_extension::init(proxy.clone(), language_registry.clone());
let node_runtime = NodeRuntime::unavailable();
let ruby_runtime = RubyRuntime::unavailable();

let store = cx.new(|cx| {
ExtensionStore::new(
Expand All @@ -280,6 +282,7 @@ async fn test_extension_store(cx: &mut TestAppContext) {
http_client.clone(),
None,
node_runtime.clone(),
ruby_runtime.clone(),
cx,
)
});
Expand Down Expand Up @@ -406,6 +409,7 @@ async fn test_extension_store(cx: &mut TestAppContext) {
http_client.clone(),
None,
node_runtime.clone(),
ruby_runtime.clone(),
cx,
)
});
Expand Down Expand Up @@ -494,6 +498,7 @@ async fn test_extension_store_with_test_extension(cx: &mut TestAppContext) {
let language_registry = project.read_with(cx, |project, _cx| project.languages().clone());
language_extension::init(proxy.clone(), language_registry.clone());
let node_runtime = NodeRuntime::unavailable();
let ruby_runtime = RubyRuntime::unavailable();

let mut status_updates = language_registry.language_server_binary_statuses();

Expand Down Expand Up @@ -592,6 +597,7 @@ async fn test_extension_store_with_test_extension(cx: &mut TestAppContext) {
builder_client,
None,
node_runtime,
ruby_runtime,
cx,
)
});
Expand Down
3 changes: 3 additions & 0 deletions crates/extension_host/src/headless_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use http_client::HttpClient;
use language::{LanguageConfig, LanguageName, LanguageQueries, LoadedLanguage};
use lsp::LanguageServerName;
use node_runtime::NodeRuntime;
use ruby_runtime::RubyRuntime;

use crate::wasm_host::{WasmExtension, WasmHost};

Expand Down Expand Up @@ -40,6 +41,7 @@ impl HeadlessExtensionStore {
extension_dir: PathBuf,
extension_host_proxy: Arc<ExtensionHostProxy>,
node_runtime: NodeRuntime,
ruby_runtime: RubyRuntime,
cx: &mut App,
) -> Entity<Self> {
cx.new(|cx| Self {
Expand All @@ -48,6 +50,7 @@ impl HeadlessExtensionStore {
fs.clone(),
http_client.clone(),
node_runtime,
ruby_runtime,
extension_host_proxy.clone(),
extension_dir.join("work"),
cx,
Expand Down
4 changes: 4 additions & 0 deletions crates/extension_host/src/wasm_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use language::LanguageName;
use lsp::LanguageServerName;
use node_runtime::NodeRuntime;
use release_channel::ReleaseChannel;
use ruby_runtime::RubyRuntime;
use semantic_version::SemanticVersion;
use std::{
path::{Path, PathBuf},
Expand All @@ -40,6 +41,7 @@ pub struct WasmHost {
release_channel: ReleaseChannel,
http_client: Arc<dyn HttpClient>,
node_runtime: NodeRuntime,
ruby_runtime: RubyRuntime,
pub(crate) proxy: Arc<ExtensionHostProxy>,
fs: Arc<dyn Fs>,
pub work_dir: PathBuf,
Expand Down Expand Up @@ -329,6 +331,7 @@ impl WasmHost {
fs: Arc<dyn Fs>,
http_client: Arc<dyn HttpClient>,
node_runtime: NodeRuntime,
ruby_runtime: RubyRuntime,
proxy: Arc<ExtensionHostProxy>,
work_dir: PathBuf,
cx: &mut App,
Expand All @@ -345,6 +348,7 @@ impl WasmHost {
work_dir,
http_client,
node_runtime,
ruby_runtime,
proxy,
release_channel: ReleaseChannel::global(cx),
_main_thread_message_task: task,
Expand Down
46 changes: 46 additions & 0 deletions crates/extension_host/src/wasm_host/wit/since_v0_2_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,52 @@ impl nodejs::Host for WasmState {
}
}

impl ruby::Host for WasmState {
async fn ruby_binary_path(&mut self) -> wasmtime::Result<Result<String, String>> {
self.host
.ruby_runtime
.binary_path()
.await
.map(|path| path.to_string_lossy().to_string())
.to_wasmtime_result()
}

async fn gems_installed_version(
&mut self,
gem_name: String,
) -> wasmtime::Result<Result<Option<String>, String>> {
self.host
.ruby_runtime
.gem_installed_version(&self.work_dir(), &gem_name)
.await
.to_wasmtime_result()
}

async fn gems_latest_version(
&mut self,
gem_name: String,
) -> wasmtime::Result<Result<String, String>> {
self.host
.ruby_runtime
.gem_latest_version(&self.work_dir(), &gem_name)
.await
.to_wasmtime_result()
}

async fn gems_install_gem(
&mut self,
gem_name: String,
version: String,
binaries: Vec<String>,
) -> wasmtime::Result<Result<(), String>> {
self.host
.ruby_runtime
.gem_install_gem(&self.work_dir(), &gem_name, &version, binaries.clone())
.await
.to_wasmtime_result()
}
}

#[async_trait]
impl lsp::Host for WasmState {}

Expand Down
1 change: 1 addition & 0 deletions crates/project/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ rpc.workspace = true
schemars.workspace = true
task.workspace = true
tempfile.workspace = true
ruby_runtime.workspace = true
serde.workspace = true
serde_json.workspace = true
settings.workspace = true
Expand Down
1 change: 1 addition & 0 deletions crates/project/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,7 @@ impl Project {
Project::local(
client,
node_runtime::NodeRuntime::unavailable(),
ruby_runtime::RubyRuntime::unavailable(),
user_store,
Arc::new(languages),
fs,
Expand Down
42 changes: 42 additions & 0 deletions crates/ruby_runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[package]
name = "ruby_runtime"
version = "0.1.0"
publish.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later"

[lints]
workspace = true

[lib]
path = "src/ruby_runtime.rs"
doctest = false

[features]
test-support = ["tempfile"]

[dependencies]
anyhow.workspace = true
async-compression.workspace = true
async-watch.workspace = true
async-tar.workspace = true
async-trait.workspace = true
async_zip.workspace = true
futures.workspace = true
http_client.workspace = true
log.workspace = true
paths.workspace = true
semver.workspace = true
serde.workspace = true
serde_json.workspace = true
smol.workspace = true
tempfile = { workspace = true, optional = true }
util.workspace = true
walkdir = "2.5.0"
which.workspace = true

[target.'cfg(windows)'.dependencies]
async-std = { version = "1.12.0", features = ["unstable"] }

[dev-dependencies]
tempfile.workspace = true
Loading

0 comments on commit 7a47372

Please sign in to comment.