Skip to content

Debugger prototype for Ruby #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ crate-type = ["cdylib"]

[dependencies]
regex = "1.11.1"
zed_extension_api = "0.4.0"
zed_extension_api = { path = "../../zed/crates/extension_api" }
2 changes: 2 additions & 0 deletions extension.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ version = "0.7.3"
schema_version = 1
authors = ["Vitaly Slobodin <[email protected]>"]
repository = "https://github.com/zed-extensions/ruby"
debug_adapters = ["Ruby"]


[language_servers.solargraph]
name = "Solargraph"
Expand Down
83 changes: 82 additions & 1 deletion src/ruby.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
mod bundler;
mod gemset;
mod language_servers;

use std::net::{Ipv4Addr, SocketAddrV4, TcpListener};
use std::path::Path;

use language_servers::{LanguageServer, Rubocop, RubyLsp, Solargraph};

use zed::lsp::{Completion, Symbol};
use zed::settings::LspSettings;
use zed::{serde_json, CodeLabel, LanguageServerId};
use zed_extension_api::{self as zed, Result};
use zed::{DebugAdapterBinary, DebugRequest, DebugTaskDefinition};
use zed_extension_api::{
self as zed, resolve_tcp_template, Command, Result, StartDebuggingRequestArguments,
StartDebuggingRequestArgumentsRequest, TcpArgumentsTemplate, Worktree,
};

#[derive(Default)]
struct RubyExtension {
Expand Down Expand Up @@ -79,6 +87,79 @@ impl zed::Extension for RubyExtension {

Ok(Some(serde_json::json!(initialization_options)))
}
fn get_dap_binary(
&mut self,
adapter_name: String,
config: DebugTaskDefinition,
_: Option<String>,
worktree: &Worktree,
) -> Result<DebugAdapterBinary, String> {
let mut rdbg_path = Path::new(&adapter_name)
.join("rdbg")
.to_string_lossy()
.into_owned();

if worktree.which(&rdbg_path).is_none() {
match worktree.which("rdbg".as_ref()) {
Some(path) => rdbg_path = path.into(),
None => {
let output = Command::new("gem")
.arg("install")
.arg("--no-document")
.arg("--bindir")
.arg(&adapter_name)
.arg("debug")
.output()?;
if !output.status.is_none_or(|status| status != 0) {
return Err(format!(
"Failed to install rdbg:\n{}",
String::from_utf8_lossy(&output.stderr).to_string()
));
}
}
}
}

let tcp_connection =
config
.tcp_connection
.clone()
.unwrap_or_else(|| TcpArgumentsTemplate {
port: None,
host: None,
timeout: None,
});
let connection = resolve_tcp_template(tcp_connection)?;
let DebugRequest::Launch(launch) = config.request.clone() else {
return Err("rdbg does not yet support attaching".to_string());
};

let mut arguments = vec![
"--open".to_string(),
format!("--port={}", connection.port),
format!("--host={}", connection.host),
];
if worktree.which(launch.program.as_ref()).is_some() {
arguments.push("--command".to_string())
}
arguments.push(launch.program);
arguments.extend(launch.args);
let request = match config.request {
DebugRequest::Launch(_) => StartDebuggingRequestArgumentsRequest::Launch,
DebugRequest::Attach(_) => StartDebuggingRequestArgumentsRequest::Attach,
};
Ok(DebugAdapterBinary {
command: rdbg_path.to_string(),
arguments,
connection: Some(connection),
cwd: launch.cwd,
envs: launch.envs.into_iter().collect(),
request_args: StartDebuggingRequestArguments {
configuration: serde_json::Value::Object(Default::default()).to_string(),
request,
},
})
}
}

zed::register_extension!(RubyExtension);
Loading