Menyeragamkan format kode sesuai rustfmt (126 file). Sebelumnya lefthook pre-commit 'cargo fmt --check' akan gagal pada commit apa pun.
55 lines
1.6 KiB
Rust
55 lines
1.6 KiB
Rust
//! Discovers installed language servers on the system PATH.
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use super::config::LspProvisionerConfig;
|
|
|
|
/// Known language server configurations keyed by language.
|
|
fn known_configs() -> HashMap<&'static str, (&'static str, Vec<&'static str>)> {
|
|
let mut m = HashMap::new();
|
|
m.insert("rust", ("rust-analyzer", vec![]));
|
|
m.insert("python", ("pyright-langserver", vec!["--stdio"]));
|
|
m.insert(
|
|
"typescript",
|
|
("typescript-language-server", vec!["--stdio"]),
|
|
);
|
|
m.insert(
|
|
"javascript",
|
|
("typescript-language-server", vec!["--stdio"]),
|
|
);
|
|
m.insert("go", ("gopls", vec![]));
|
|
m
|
|
}
|
|
|
|
/// Check if a command is available on PATH.
|
|
fn command_exists(cmd: &str) -> bool {
|
|
std::env::var_os("PATH")
|
|
.and_then(|path| {
|
|
std::env::split_paths(&path).find_map(|dir| {
|
|
let full_path = dir.join(cmd);
|
|
if full_path.is_file() {
|
|
Some(())
|
|
} else {
|
|
None
|
|
}
|
|
})
|
|
})
|
|
.is_some()
|
|
}
|
|
|
|
/// Discover which language servers are already on PATH.
|
|
pub fn discover_installed() -> Vec<LspProvisionerConfig> {
|
|
let mut configs = Vec::new();
|
|
for (lang, (cmd, args)) in known_configs() {
|
|
if command_exists(cmd) {
|
|
configs.push(LspProvisionerConfig {
|
|
language: lang.to_string(),
|
|
command: cmd.to_string(),
|
|
args: args.iter().map(|s| s.to_string()).collect(),
|
|
install_hint: None,
|
|
});
|
|
}
|
|
}
|
|
configs
|
|
}
|