ci: add GitHub Actions workflows with semantic-release auto-versioning

chore: fix all 702 clippy warnings across codebase
- auto-fix 475 via cargo clippy --fix
- fix remaining 227 manually: uninlined_format_args, redundant_closure, match_same_arms,
  underscore_binding, format_push_string, items_after_statements, needless_pass_by_value,
  clone_on_copy, case_sensitive_extension, single_match/let-else, write_with_newline,
  and other clippy lints
This commit is contained in:
asepharyana
2026-07-13 08:12:12 +07:00
parent be921d6836
commit 29a9fae3f6
79 changed files with 826 additions and 904 deletions
+37 -39
View File
@@ -30,12 +30,12 @@ fn file_path_to_uri(path: &str) -> String {
if cfg!(windows) {
let path_str = path_str.replace('\\', "/");
if path_str.starts_with('/') {
format!("file://{}", path_str)
format!("file://{path_str}")
} else {
format!("file:///{}", path_str)
format!("file:///{path_str}")
}
} else {
format!("file://{}", path_str)
format!("file://{path_str}")
}
}
@@ -48,7 +48,7 @@ impl LspClient {
cmd.stderr(Stdio::piped());
let mut child = cmd.spawn()
.map_err(|e| anyhow::anyhow!("failed to spawn LSP server '{}': {}", command, e))?;
.map_err(|e| anyhow::anyhow!("failed to spawn LSP server '{command}': {e}"))?;
let stdin = child.stdin.take()
.ok_or_else(|| anyhow::anyhow!("failed to capture stdin for LSP server"))?;
@@ -106,10 +106,10 @@ impl LspClient {
}
});
let result = client.call_with_timeout("initialize", init_params, Duration::from_millis(LSP_INIT_TIMEOUT_MS))?;
let result = client.call_with_timeout("initialize", &init_params, Duration::from_millis(LSP_INIT_TIMEOUT_MS))?;
client.server_capabilities = result.get("capabilities").cloned().unwrap_or_default();
client.notify("initialized", json!({}))?;
client.notify("initialized", &json!({}))?;
Ok(client)
}
@@ -118,11 +118,11 @@ impl LspClient {
&self.server_capabilities
}
pub fn call(&mut self, method: &str, params: Value) -> anyhow::Result<Value> {
pub fn call(&mut self, method: &str, params: &Value) -> anyhow::Result<Value> {
self.call_with_timeout(method, params, Duration::from_millis(LSP_CALL_TIMEOUT_MS))
}
fn call_with_timeout(&mut self, method: &str, params: Value, timeout: Duration) -> anyhow::Result<Value> {
fn call_with_timeout(&mut self, method: &str, params: &Value, timeout: Duration) -> anyhow::Result<Value> {
self.next_id += 1;
let id = self.next_id;
let req = json!({
@@ -135,7 +135,7 @@ impl LspClient {
self.read_response(id, timeout)
}
pub fn notify(&mut self, method: &str, params: Value) -> anyhow::Result<()> {
pub fn notify(&mut self, method: &str, params: &Value) -> anyhow::Result<()> {
let req = json!({
"jsonrpc": "2.0",
"method": method,
@@ -146,14 +146,14 @@ impl LspClient {
fn send_frame(&mut self, msg: &Value) -> anyhow::Result<()> {
let body = serde_json::to_string(msg)
.map_err(|e| anyhow::anyhow!("failed to serialize LSP message: {}", e))?;
.map_err(|e| anyhow::anyhow!("failed to serialize LSP message: {e}"))?;
let header = format!("Content-Length: {}\r\n\r\n", body.len());
self.stdin.write_all(header.as_bytes())
.map_err(|e| anyhow::anyhow!("failed to write LSP frame header: {}", e))?;
.map_err(|e| anyhow::anyhow!("failed to write LSP frame header: {e}"))?;
self.stdin.write_all(body.as_bytes())
.map_err(|e| anyhow::anyhow!("failed to write LSP frame body: {}", e))?;
.map_err(|e| anyhow::anyhow!("failed to write LSP frame body: {e}"))?;
self.stdin.flush()
.map_err(|e| anyhow::anyhow!("failed to flush LSP stdin: {}", e))?;
.map_err(|e| anyhow::anyhow!("failed to flush LSP stdin: {e}"))?;
Ok(())
}
@@ -166,9 +166,9 @@ impl LspClient {
let frame = self.read_frame()?;
if frame.get("id") == Some(&json!(expected_id)) {
if let Some(err) = frame.get("error") {
let code = err.get("code").and_then(|c| c.as_i64()).unwrap_or(0);
let code = err.get("code").and_then(serde_json::Value::as_i64).unwrap_or(0);
let msg = err.get("message").and_then(|m| m.as_str()).unwrap_or("unknown error");
anyhow::bail!("LSP error {}: {}", code, msg);
anyhow::bail!("LSP error {code}: {msg}");
}
return Ok(frame.get("result").cloned().unwrap_or(Value::Null));
}
@@ -179,7 +179,7 @@ impl LspClient {
let deadline = Instant::now() + timeout;
loop {
if Instant::now() > deadline {
anyhow::bail!("timed out waiting for LSP notification '{}'", method);
anyhow::bail!("timed out waiting for LSP notification '{method}'");
}
let frame = self.read_frame()?;
if frame.get("method") == Some(&json!(method)) {
@@ -195,22 +195,21 @@ impl LspClient {
match self.stdout.read_line(&mut line) {
Ok(0) => anyhow::bail!("LSP server closed the connection"),
Ok(_) => {}
Err(e) => anyhow::bail!("LSP read error: {}", e),
Err(e) => anyhow::bail!("LSP read error: {e}"),
}
let trimmed = line.trim();
if trimmed.is_empty() {
break;
}
if let Some(len_str) = trimmed.strip_prefix("Content-Length: ") {
let length: usize = len_str.trim().parse::<usize>()
.map_err(|e| anyhow::anyhow!("invalid Content-Length '{}': {}", len_str.trim(), e))?;
// Cap Content-Length at 64 MiB to prevent OOM from a
// malicious or misconfigured LSP server (CWE-400).
const MAX_CONTENT_LENGTH: usize = 64 * 1024 * 1024;
let length: usize = len_str.trim().parse::<usize>()
.map_err(|e| anyhow::anyhow!("invalid Content-Length '{}': {}", len_str.trim(), e))?;
if length > MAX_CONTENT_LENGTH {
anyhow::bail!(
"Content-Length {} exceeds maximum allowed size of {} bytes",
length, MAX_CONTENT_LENGTH,
"Content-Length {length} exceeds maximum allowed size of {MAX_CONTENT_LENGTH} bytes",
);
}
content_length = Some(length);
@@ -222,17 +221,17 @@ impl LspClient {
let mut body = vec![0u8; length];
self.stdout.read_exact(&mut body)
.map_err(|e| anyhow::anyhow!("failed to read LSP body ({} bytes): {}", length, e))?;
.map_err(|e| anyhow::anyhow!("failed to read LSP body ({length} bytes): {e}"))?;
let json_str = String::from_utf8(body)
.map_err(|e| anyhow::anyhow!("invalid UTF-8 in LSP response: {}", e))?;
.map_err(|e| anyhow::anyhow!("invalid UTF-8 in LSP response: {e}"))?;
serde_json::from_str(&json_str)
.map_err(|e| anyhow::anyhow!("invalid JSON in LSP response: {}", e))
.map_err(|e| anyhow::anyhow!("invalid JSON in LSP response: {e}"))
}
pub fn did_open(&mut self, uri: &str, language_id: &str, version: i32, text: &str) -> anyhow::Result<()> {
self.notify("textDocument/didOpen", json!({
self.notify("textDocument/didOpen", &json!({
"textDocument": {
"uri": uri,
"languageId": language_id,
@@ -244,7 +243,7 @@ impl LspClient {
#[allow(dead_code)]
pub fn did_change(&mut self, uri: &str, version: i32, text: &str) -> anyhow::Result<()> {
self.notify("textDocument/didChange", json!({
self.notify("textDocument/didChange", &json!({
"textDocument": {
"uri": uri,
"version": version
@@ -256,7 +255,7 @@ impl LspClient {
}
pub fn did_close(&mut self, uri: &str) -> anyhow::Result<()> {
self.notify("textDocument/didClose", json!({
self.notify("textDocument/didClose", &json!({
"textDocument": {
"uri": uri
}
@@ -264,28 +263,28 @@ impl LspClient {
}
pub fn hover(&mut self, uri: &str, line: u32, character: u32) -> anyhow::Result<Value> {
self.call("textDocument/hover", json!({
self.call("textDocument/hover", &json!({
"textDocument": { "uri": uri },
"position": { "line": line, "character": character }
}))
}
pub fn completion(&mut self, uri: &str, line: u32, character: u32) -> anyhow::Result<Value> {
self.call("textDocument/completion", json!({
self.call("textDocument/completion", &json!({
"textDocument": { "uri": uri },
"position": { "line": line, "character": character }
}))
}
pub fn goto_definition(&mut self, uri: &str, line: u32, character: u32) -> anyhow::Result<Value> {
self.call("textDocument/definition", json!({
self.call("textDocument/definition", &json!({
"textDocument": { "uri": uri },
"position": { "line": line, "character": character }
}))
}
pub fn references(&mut self, uri: &str, line: u32, character: u32) -> anyhow::Result<Value> {
self.call("textDocument/references", json!({
self.call("textDocument/references", &json!({
"textDocument": { "uri": uri },
"position": { "line": line, "character": character },
"context": {
@@ -296,7 +295,7 @@ impl LspClient {
#[allow(dead_code)]
pub fn document_symbols(&mut self, uri: &str) -> anyhow::Result<Value> {
self.call("textDocument/documentSymbol", json!({
self.call("textDocument/documentSymbol", &json!({
"textDocument": { "uri": uri }
}))
}
@@ -327,7 +326,7 @@ impl LspClient {
/// still proves the process is up and the JSON-RPC channel is live.
/// Returns `false` on timeout, EOF, or any read/write error.
///
/// Flow: build request → send_frame → poll frames until id matches
/// Flow: build request → `send_frame` → poll frames until id matches
/// (alive) or deadline/read error fires (dead).
#[allow(dead_code)]
pub fn is_alive(&mut self) -> bool {
@@ -369,19 +368,18 @@ impl LspClient {
/// not block on any reply.
#[allow(dead_code)]
pub fn exit(&mut self) -> anyhow::Result<()> {
self.notify("exit", json!({}))
self.notify("exit", &json!({}))
}
pub fn shutdown(&mut self) -> anyhow::Result<()> {
let _ = self.call_with_timeout("shutdown", json!({}), Duration::from_secs(5));
let _ = self.notify("exit", json!({}));
Ok(())
pub fn shutdown(&mut self) {
let _ = self.call_with_timeout("shutdown", &json!({}), Duration::from_secs(5));
let _ = self.notify("exit", &json!({}));
}
}
impl Drop for LspClient {
fn drop(&mut self) {
let _ = self.notify("exit", json!({}));
let _ = self.notify("exit", &json!({}));
}
}
+18 -28
View File
@@ -70,7 +70,7 @@ impl LspManager {
language_id: &str,
) -> anyhow::Result<()> {
if self.servers.iter().any(|s| s.name == name) {
anyhow::bail!("LSP server '{}' is already connected", name);
anyhow::bail!("LSP server '{name}' is already connected");
}
let client = LspClient::spawn(command, args)?;
self.servers.push(LspServer {
@@ -101,7 +101,7 @@ impl LspManager {
pub fn disconnect(&mut self, name: &str) -> bool {
if let Some(server) = self.servers.iter().find(|s| s.name == name) {
if let Ok(mut client) = server.client.lock() {
let _ = client.shutdown();
client.shutdown();
}
}
let len = self.servers.len();
@@ -134,7 +134,7 @@ impl LspManager {
pub fn find_server_for_path(&self, path: &Path) -> Option<Arc<Mutex<LspClient>>> {
path.extension()
.and_then(|e| e.to_str())
.map(|s| format!(".{}", s))
.map(|s| format!(".{s}"))
.and_then(|ext| self.find_server_for_extension(&ext))
}
@@ -171,21 +171,15 @@ impl LspManager {
/// Non-critical failures (file missing, server unreachable, send
/// error) are logged with `tracing::warn!` rather than propagated,
/// so a stale notification cannot abort the calling flow.
pub fn did_change_file(&mut self, path: &Path) -> anyhow::Result<()> {
let ext = match path.extension().and_then(|e| e.to_str()).map(|s| format!(".{}", s)) {
Some(ext) => ext,
None => {
tracing::warn!("did_change_file: path has no extension: {:?}", path);
return Ok(());
}
pub fn did_change_file(&mut self, path: &Path) {
let Some(ext) = path.extension().and_then(|e| e.to_str()).map(|s| format!(".{s}")) else {
tracing::warn!("did_change_file: path has no extension: {:?}", path);
return;
};
let server_name = match self.extension_registry.get(&ext) {
Some(name) => name.clone(),
None => {
tracing::warn!("did_change_file: no LSP server registered for extension '{}'", ext);
return Ok(());
}
let server_name = if let Some(name) = self.extension_registry.get(&ext) { name.clone() } else {
tracing::warn!("did_change_file: no LSP server registered for extension '{}'", ext);
return;
};
let uri = path_to_lsp_uri(&path.to_string_lossy());
@@ -194,7 +188,7 @@ impl LspManager {
Ok(t) => t,
Err(e) => {
tracing::warn!("did_change_file: failed to read {:?}: {}", path, e);
return Ok(());
return;
}
};
@@ -202,12 +196,9 @@ impl LspManager {
.get_language_id(&server_name)
.unwrap_or_else(|| "plaintext".to_string());
let client = match self.get_client(&server_name) {
Some(c) => c,
None => {
tracing::warn!("did_change_file: server '{}' has no client", server_name);
return Ok(());
}
let Some(client) = self.get_client(&server_name) else {
tracing::warn!("did_change_file: server '{}' has no client", server_name);
return;
};
let next_version = match self.open_files.get(&uri) {
@@ -220,7 +211,7 @@ impl LspManager {
Ok(c) => c,
Err(e) => {
tracing::warn!("did_change_file: client mutex poisoned for '{}': {}", server_name, e);
return Ok(());
return;
}
};
if self.open_files.contains_key(&uri) {
@@ -237,7 +228,7 @@ impl LspManager {
uri,
e
);
return Ok(());
return;
}
self.open_files.insert(
@@ -248,7 +239,6 @@ impl LspManager {
},
);
Ok(())
}
/// Record that `server_name` has an open document at `uri`.
@@ -274,9 +264,9 @@ impl LspManager {
/// drop the vec. Failures from individual shutdowns are swallowed
/// because the goal is best-effort termination during teardown.
pub fn shutdown_all(&mut self) {
for server in self.servers.iter() {
for server in &self.servers {
if let Ok(mut client) = server.client.lock() {
let _ = client.shutdown();
client.shutdown();
}
}
self.servers.clear();
+46 -51
View File
@@ -1,10 +1,10 @@
//! Auto-provisioning engine for LSP language servers.
//!
//! Flow: detect_env() → for each supported server in supported_servers()
//! → provision_single() tries install tiers in order → returns
//! ProvisionResult (AlreadyAvailable / Installed / Failed).
//! Caller can then call auto_connect() to attach available servers
//! to an existing LspManager.
//! Flow: `detect_env()` → for each supported server in `supported_servers()`
//! → `provision_single()` tries install tiers in order → returns
//! `ProvisionResult` (`AlreadyAvailable` / Installed / Failed).
//! Caller can then call `auto_connect()` to attach available servers
//! to an existing `LspManager`.
//!
//! Why: opening a project on a fresh machine should not require the user
//! to manually hunt down and install 4 different language servers.
@@ -28,7 +28,7 @@ pub type ProgressFn<'a> = Option<&'a dyn Fn(&str)>;
/// Result of attempting to make a single language server available.
///
/// The caller should switch on this variant: AlreadyAvailable and
/// The caller should switch on this variant: `AlreadyAvailable` and
/// Installed both mean the binary can be launched; Failed means we
/// gave up and the user needs to install manually (see `manual_instructions`).
#[derive(Debug, Clone)]
@@ -99,12 +99,13 @@ pub struct InstallTier {
/// Snapshot of the host environment used to decide which install tiers are viable.
///
/// Populated by `detect_env()` once per provision_all() call so we
/// Populated by `detect_env()` once per `provision_all()` call so we
/// don't re-shell out for every server. `is_linux` / `is_macos` are
/// computed at startup (compile time would also work, but keeping the
/// shape uniform with the rest of the struct makes the call sites tidy).
#[derive(Debug, Clone)]
#[allow(dead_code)]
#[allow(clippy::struct_excessive_bools)]
pub struct EnvInfo {
pub has_rustup: bool,
pub has_npm: bool,
@@ -126,7 +127,7 @@ pub struct EnvInfo {
///
/// Flow: `Command::new("which").arg(binary).output()` → on Unix
/// `which` returns exit 0 + stdout path when found, non-zero
/// otherwise. We return the first stdout line as the PathBuf.
/// otherwise. We return the first stdout line as the `PathBuf`.
///
/// Returns None if `which` itself is missing, fails to spawn, or the
/// binary is not on PATH. We deliberately don't cache this — it's only
@@ -151,7 +152,7 @@ pub fn which(binary: &str) -> Option<PathBuf> {
///
/// Flow: shell out to `which` for each tool in parallel (sequentially,
/// actually — the calls are fast and the ordering doesn't matter)
/// → set EnvInfo flags. Linux/macOS are detected via cfg at
/// → set `EnvInfo` flags. Linux/macOS are detected via cfg at
/// compile time since `which` won't tell us.
///
/// Edge case: `which` may not exist on Windows; we guard with cfg so
@@ -185,6 +186,7 @@ pub fn detect_env() -> EnvInfo {
/// Why hard-coded rather than loaded from settings: the set is small,
/// changes rarely, and bundling it lets the provisioner run before any
/// user config has been read (e.g. on first launch).
#[allow(clippy::too_many_lines)]
pub fn supported_servers() -> Vec<LanguageServerDef> {
vec![
LanguageServerDef {
@@ -307,7 +309,7 @@ pub fn supported_servers() -> Vec<LanguageServerDef> {
/// commands tend to emit errors to stderr, and we want to surface
/// those.
///
/// Why a custom timeout: std::process::Command has no built-in timeout,
/// Why a custom timeout: `std::process::Command` has no built-in timeout,
/// and we'd rather kill a hung `apt` than block the TUI indefinitely.
pub fn run_command(cmd: &str, args: &[&str]) -> std::io::Result<(bool, String)> {
let mut command = Command::new(cmd);
@@ -334,23 +336,19 @@ pub fn run_command(cmd: &str, args: &[&str]) -> std::io::Result<(bool, String)>
})
});
let timeout = Duration::from_secs(180);
let timeout = Duration::from_mins(3);
let start = Instant::now();
let status = loop {
match child.try_wait()? {
Some(status) => break Ok(status),
None => {
if start.elapsed() > timeout {
let _ = child.kill();
let _ = child.wait();
break Err(std::io::Error::new(
std::io::ErrorKind::TimedOut,
format!("command '{}' timed out after {}s", cmd, timeout.as_secs()),
));
}
std::thread::sleep(Duration::from_millis(50));
}
if let Some(status) = child.try_wait()? { break Ok(status) }
if start.elapsed() > timeout {
let _ = child.kill();
let _ = child.wait();
break Err(std::io::Error::new(
std::io::ErrorKind::TimedOut,
format!("command '{}' timed out after {}s", cmd, timeout.as_secs()),
));
}
std::thread::sleep(Duration::from_millis(50));
};
let stdout = stdout_thread
@@ -362,7 +360,7 @@ pub fn run_command(cmd: &str, args: &[&str]) -> std::io::Result<(bool, String)>
match status {
Ok(s) if s.success() => Ok((true, stdout)),
Ok(_) => Ok((false, format!("{}{}", stdout, stderr))),
Ok(_) => Ok((false, format!("{stdout}{stderr}"))),
Err(e) => Err(e),
}
}
@@ -412,7 +410,7 @@ fn download_url(url: &str, dest: &Path, max_secs: u64) -> Result<(), String> {
"-o", &path_str,
url,
];
let (ok, out) = run_command("curl", &args).map_err(|e| format!("curl spawn: {}", e))?;
let (ok, out) = run_command("curl", &args).map_err(|e| format!("curl spawn: {e}"))?;
if !ok {
return Err(format!("download failed: {}", out.trim()));
}
@@ -423,7 +421,7 @@ fn download_url(url: &str, dest: &Path, max_secs: u64) -> Result<(), String> {
/// `~/.local/share/zesdex/lsp/rust-analyzer/bin/rust-analyzer`.
fn install_rust_analyzer_binary(env: &EnvInfo, progress: ProgressFn<'_>) -> Result<PathBuf, String> {
let base = lsp_install_dir("rust-analyzer")?;
std::fs::create_dir_all(&base).map_err(|e| format!("mkdir: {}", e))?;
std::fs::create_dir_all(&base).map_err(|e| format!("mkdir: {e}"))?;
let url = if env.is_linux {
"https://github.com/rust-lang/rust-analyzer/releases/latest/download/rust-analyzer-x86_64-unknown-linux-gnu.gz"
@@ -440,7 +438,7 @@ fn install_rust_analyzer_binary(env: &EnvInfo, progress: ProgressFn<'_>) -> Resu
download_url(url, &gz, 120)?;
if let Some(cb) = progress { cb("Rust: decompressing..."); }
let (ok, out) = run_command("gunzip", &["-f", &gz.to_string_lossy()])
.map_err(|e| format!("gunzip spawn: {}", e))?;
.map_err(|e| format!("gunzip spawn: {e}"))?;
if !ok {
return Err(format!("gunzip: {}", out.trim()));
}
@@ -452,7 +450,7 @@ fn install_rust_analyzer_binary(env: &EnvInfo, progress: ProgressFn<'_>) -> Resu
{
use std::os::unix::fs::PermissionsExt;
std::fs::set_permissions(&target, std::fs::Permissions::from_mode(0o755))
.map_err(|e| format!("chmod: {}", e))?;
.map_err(|e| format!("chmod: {e}"))?;
}
if let Some(cb) = progress { cb("Rust: installed ✓"); }
Ok(target)
@@ -462,7 +460,7 @@ fn install_rust_analyzer_binary(env: &EnvInfo, progress: ProgressFn<'_>) -> Resu
/// and create a launcher script at `bin/jdtls`.
fn install_jdtls_from_eclipse(progress: ProgressFn) -> Result<PathBuf, String> {
let base = lsp_install_dir("jdtls")?;
std::fs::create_dir_all(&base).map_err(|e| format!("mkdir: {}", e))?;
std::fs::create_dir_all(&base).map_err(|e| format!("mkdir: {e}"))?;
let url = "https://download.eclipse.org/jdtls/snapshots/jdt-language-server-latest.tar.gz";
let tarball = base.join("jdtls.tar.gz");
@@ -473,7 +471,7 @@ fn install_jdtls_from_eclipse(progress: ProgressFn) -> Result<PathBuf, String> {
let (ok, out) = run_command("tar", &[
"-xzf", tarball.to_str().unwrap_or(""),
"-C", base.to_str().unwrap_or("."),
]).map_err(|e| format!("tar spawn: {}", e))?;
]).map_err(|e| format!("tar spawn: {e}"))?;
if !ok {
return Err(format!("tar: {}", out.trim()));
}
@@ -484,7 +482,7 @@ fn install_jdtls_from_eclipse(progress: ProgressFn) -> Result<PathBuf, String> {
}
let bin_dir = base.join("bin");
std::fs::create_dir_all(&bin_dir).map_err(|e| format!("mkdir bin: {}", e))?;
std::fs::create_dir_all(&bin_dir).map_err(|e| format!("mkdir bin: {e}"))?;
let launcher = bin_dir.join("jdtls");
let script = r#"#!/usr/bin/env bash
@@ -505,12 +503,12 @@ exec java \
--add-opens java.base/java.lang=ALL-UNNAMED \
"$@"
"#;
std::fs::write(&launcher, script).map_err(|e| format!("write launcher: {}", e))?;
std::fs::write(&launcher, script).map_err(|e| format!("write launcher: {e}"))?;
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
std::fs::set_permissions(&launcher, std::fs::Permissions::from_mode(0o755))
.map_err(|e| format!("chmod launcher: {}", e))?;
.map_err(|e| format!("chmod launcher: {e}"))?;
}
if let Some(cb) = progress { cb("Java: JDT-LS installed ✓"); }
Ok(launcher)
@@ -521,7 +519,7 @@ fn run_download_tier(name: &str, env: &EnvInfo, progress: ProgressFn<'_>) -> Res
match name {
DOWNLOAD_RUST_BIN => install_rust_analyzer_binary(env, progress),
DOWNLOAD_JDTLS => install_jdtls_from_eclipse(progress),
other => Err(format!("unknown download tier '{}'", other)),
other => Err(format!("unknown download tier '{other}'")),
}
}
@@ -556,7 +554,7 @@ fn manual_instructions(def: &LanguageServerDef) -> String {
/// Try to provision a single language server.
///
/// Flow: check whether any `binary_names` candidate is already on PATH
/// → if yes, return AlreadyAvailable → otherwise walk
/// → if yes, return `AlreadyAvailable` → otherwise walk
/// `install_tiers` in order, skipping tiers whose `requires`
/// binaries are missing → for each viable tier, run the install
/// command (120s timeout) → if it succeeds AND the binary now
@@ -641,7 +639,7 @@ fn provision_single_with_progress(def: &LanguageServerDef, env: &EnvInfo, progre
}
// Normal shell-out tier.
let arg_refs: Vec<&str> = tier.args.iter().map(|s| s.as_str()).collect();
let arg_refs: Vec<&str> = tier.args.iter().map(std::string::String::as_str).collect();
match run_command(&tier.command, &arg_refs) {
Ok((true, _)) => {
let located = def
@@ -683,9 +681,9 @@ fn provision_single_with_progress(def: &LanguageServerDef, env: &EnvInfo, progre
/// Provision every supported server in order, returning one
/// `ProvisionResult` per server.
///
/// Flow: detect_env() once → for each server in supported_servers()
/// call provision_single() → collect results. Order matches
/// supported_servers() (rust, typescript, go, java).
/// Flow: `detect_env()` once → for each server in `supported_servers()`
/// call `provision_single()` → collect results. Order matches
/// `supported_servers()` (rust, typescript, go, java).
#[allow(dead_code)]
pub fn provision_all() -> Vec<ProvisionResult> {
let env = detect_env();
@@ -725,7 +723,7 @@ pub fn provision_all_with_progress(progress: ProgressFn) -> Vec<ProvisionResult>
let avail: String = flags.iter()
.filter(|(_, v)| *v).map(|(k, _)| *k)
.collect::<Vec<_>>().join(", ");
cb(&format!("LSP: environment ready — {}", avail));
cb(&format!("LSP: environment ready — {avail}"));
}
supported_servers()
.iter()
@@ -736,8 +734,8 @@ pub fn provision_all_with_progress(progress: ProgressFn) -> Vec<ProvisionResult>
/// For every successful provision result, attach the corresponding
/// server to the given `LspManager`.
///
/// Flow: for each result, if it's AlreadyAvailable or Installed, look
/// up the LanguageServerDef, then call manager.connect() with
/// Flow: for each result, if it's `AlreadyAvailable` or Installed, look
/// up the `LanguageServerDef`, then call `manager.connect()` with
/// the binary path and empty args. On connect success, log and
/// record the name; on failure, log a warning and skip.
/// Returns the names that successfully connected.
@@ -745,7 +743,7 @@ pub fn provision_all_with_progress(progress: ProgressFn) -> Vec<ProvisionResult>
/// Why empty args: most LSP servers don't need CLI flags to start;
/// the spec for each server lives in the protocol handshake, not the
/// argv. If we ever need flags (e.g. --stdio), they'll be a per-server
/// constant in supported_servers().
/// constant in `supported_servers()`.
pub fn auto_connect(manager: &Arc<Mutex<LspManager>>, results: &[ProvisionResult]) -> Vec<String> {
let defs = supported_servers();
let mut connected: Vec<String> = Vec::new();
@@ -767,12 +765,9 @@ pub fn auto_connect(manager: &Arc<Mutex<LspManager>>, results: &[ProvisionResult
// Sanity: only connect to servers we know about. Protects against
// future ProvisionResult variants sneaking in unknown names.
let def = match defs.iter().find(|d| d.name == name) {
Some(d) => d,
None => {
warn!(name = %name, "skipping connect: unknown server");
continue;
}
let Some(def) = defs.iter().find(|d| d.name == name) else {
warn!(name = %name, "skipping connect: unknown server");
continue;
};
let mut guard = match manager.lock() {
@@ -784,7 +779,7 @@ pub fn auto_connect(manager: &Arc<Mutex<LspManager>>, results: &[ProvisionResult
};
// Build extension slice for connect_with_extensions.
let ext_refs: Vec<&str> = def.extensions.iter().map(|s| s.as_str()).collect();
let ext_refs: Vec<&str> = def.extensions.iter().map(std::string::String::as_str).collect();
match guard.connect_with_extensions(&name, &binary, &[], &language, &ext_refs) {
Ok(()) => {