use super::*;
pub(in crate::app) fn lldb_dap_rank(name: &str) -> Option<i64> {
if name == "lldb-dap" {
return Some(i64::MAX);
}
if name == "lldb-vscode" {
return Some(i64::MAX - 1);
}
let (version, family) = name
.strip_prefix("lldb-dap-")
.map(|v| (v, 1))
.or_else(|| name.strip_prefix("lldb-vscode-").map(|v| (v, 0)))?;
let version: i64 = version.parse().ok()?;
Some(version * 2 + family)
}
pub(in crate::app) fn lldb_dap_path() -> Option<String> {
let xcode = "/Library/Developer/CommandLineTools/usr/bin/lldb-dap";
if std::path::Path::new(xcode).is_file() {
return Some(xcode.to_string());
}
let path_var = std::env::var_os("PATH")?;
let mut best: Option<(i64, String)> = None;
for dir in std::env::split_paths(&path_var) {
let Ok(entries) = std::fs::read_dir(&dir) else {
continue;
};
for entry in entries.flatten() {
let Some(name) = entry.file_name().to_str().map(str::to_owned) else {
continue;
};
let Some(rank) = lldb_dap_rank(&name) else {
continue;
};
let full = entry.path();
if is_executable_file(&full) && best.as_ref().is_none_or(|(r, _)| rank > *r) {
best = Some((rank, full.to_string_lossy().into_owned()));
}
}
}
best.map(|(_, p)| p)
}
pub(in crate::app) fn lldb_dap_missing_message() -> String {
let hint = if cfg!(target_os = "macos") {
"install Xcode Command Line Tools"
} else {
"install LLVM, e.g. apt install lldb"
};
format!("lldb-dap not found ({hint})")
}
pub(in crate::app) fn is_executable_file(path: &Path) -> bool {
use std::os::unix::fs::PermissionsExt;
std::fs::metadata(path)
.map(|m| m.is_file() && m.permissions().mode() & 0o111 != 0)
.unwrap_or(false)
}
impl App {
pub(in crate::app) fn install_delve(&mut self) {
if !crate::dap::install::go_on_path() {
self.status = crate::dap::install::dlv_missing_message(false);
return;
}
match crate::widgets::terminal::PtyTerminal::new(self.roots.primary()) {
Ok(mut term) => {
term.set_manual_name(Some(String::from("delve install")));
term.write_input(format!("{}\r", crate::dap::install::DLV_INSTALL).as_bytes());
self.insert_terminal(term);
self.show_terminal = true;
self.focus_pane(Pane::Terminal);
self.status = String::from(
"Installing delve into ~/.croft/servers/go; start debugging again once it finishes",
);
}
Err(e) => self.status = format!("Could not open a terminal: {e}"),
}
}
}