Skip to content

Commit 43a4731

Browse files
committed
WIP
1 parent 67d8485 commit 43a4731

File tree

5 files changed

+68
-14
lines changed

5 files changed

+68
-14
lines changed

Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ path = "src/ruby.rs"
1010
crate-type = ["cdylib"]
1111

1212
[dependencies]
13-
zed_extension_api = { path = "../zed/crates/extension_api" }
13+
zed_extension_api = "0.3.0"

extension.toml

+10
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,13 @@ commit = "332262529bc51abf5746317b2255ccc2fff778f8"
2929
[grammars.rbs]
3030
repository = "https://github.com/joker1007/tree-sitter-rbs"
3131
commit = "de893b166476205b09e79cd3689f95831269579a"
32+
33+
[[capabilities]]
34+
kind = "process:exec"
35+
command = "gem"
36+
args = ["install", "--no-user-install", "--no-format-executable", "--no-document", "*"]
37+
38+
[[capabilities]]
39+
kind = "process:exec"
40+
command = "bundle"
41+
args = ["info", "*"]

src/language_servers/language_server.rs

+51-13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use zed_extension_api::{
66
pub struct LanguageServerBinary {
77
pub path: String,
88
pub args: Option<Vec<String>>,
9+
pub env: Option<Vec<(String, String)>>,
910
}
1011

1112
pub trait LanguageServer {
@@ -31,7 +32,7 @@ pub trait LanguageServer {
3132
Ok(zed::Command {
3233
command: binary.path,
3334
args: binary.args.unwrap_or(Self::get_executable_args()),
34-
env: Default::default(),
35+
env: binary.env.unwrap_or_default(),
3536
})
3637
}
3738

@@ -40,19 +41,14 @@ pub trait LanguageServer {
4041
language_server_id: &LanguageServerId,
4142
worktree: &zed::Worktree,
4243
) -> Result<LanguageServerBinary> {
43-
let output = Command::new("ls").output()?;
44-
45-
dbg!(&output.status);
46-
dbg!(String::from_utf8_lossy(&output.stdout).to_string());
47-
dbg!(String::from_utf8_lossy(&output.stderr).to_string());
48-
4944
let lsp_settings = LspSettings::for_worktree(language_server_id.as_ref(), worktree)?;
5045

5146
if let Some(binary_settings) = lsp_settings.binary {
5247
if let Some(path) = binary_settings.path {
5348
return Ok(LanguageServerBinary {
5449
path,
5550
args: binary_settings.arguments,
51+
env: Default::default(),
5652
});
5753
}
5854
}
@@ -75,16 +71,58 @@ pub trait LanguageServer {
7571
]
7672
.concat(),
7773
),
74+
env: Default::default(),
7875
})
7976
.ok_or_else(|| "Unable to find the 'bundle' command.".into())
8077
} else {
81-
worktree
82-
.which(Self::EXECUTABLE_NAME)
83-
.map(|path| LanguageServerBinary {
84-
path,
78+
let gem_home = std::env::current_dir()
79+
.map_err(|e| format!("Failed to get current directory: {}", e))?
80+
.to_string_lossy()
81+
.to_string();
82+
83+
// Check if the gem is already installed
84+
if let Some(existing_binary) = worktree.which(Self::EXECUTABLE_NAME) {
85+
return Ok(LanguageServerBinary {
86+
path: existing_binary,
8587
args: Some(Self::get_executable_args()),
86-
})
87-
.ok_or_else(|| format!("Unable to find the '{}' command.", Self::EXECUTABLE_NAME))
88+
env: Some(vec![(
89+
"GEM_PATH".to_string(),
90+
format!("{}:$GEM_PATH", gem_home),
91+
)]),
92+
});
93+
}
94+
95+
let output = Command::new("gem")
96+
.env("GEM_HOME", gem_home.clone())
97+
.arg("install")
98+
.arg("--no-user-install")
99+
.arg("--no-format-executable")
100+
.arg("--no-document")
101+
.arg(Self::GEM_NAME)
102+
.output()?;
103+
104+
let stderr_output = String::from_utf8_lossy(&output.stderr).to_string();
105+
106+
match output.status {
107+
Some(0) => Ok(LanguageServerBinary {
108+
path: format!("{}/bin/{}", gem_home, Self::EXECUTABLE_NAME),
109+
args: Some(Self::get_executable_args()),
110+
env: Some(vec![(
111+
"GEM_PATH".to_string(),
112+
format!("{}:$GEM_PATH", gem_home),
113+
)]),
114+
}),
115+
Some(status) => Err(format!(
116+
"Failed to install {} gem (status: {})\nError: {}",
117+
Self::GEM_NAME,
118+
status,
119+
stderr_output
120+
)),
121+
None => Err(format!(
122+
"Failed to start language server: {}",
123+
stderr_output
124+
)),
125+
}
88126
}
89127
}
90128
}

src/language_servers/solargraph.rs

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ impl LanguageServer for Solargraph {
1414
fn get_executable_args() -> Vec<String> {
1515
vec!["stdio".to_string()]
1616
}
17+
18+
fn default_use_bundler() -> bool {
19+
false
20+
}
1721
}
1822

1923
impl Solargraph {

0 commit comments

Comments
 (0)