pub use bynk_ide::symbols::*;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use bynk_syntax::span::Span;
use tower_lsp::lsp_types::Url;
pub struct CrossFileSymbol {
pub uri: Url,
pub span: Span,
pub source: String,
}
pub fn find_declaration_cross_file(
files: &[PathBuf],
current_uri: &Url,
name: &str,
) -> Option<CrossFileSymbol> {
let current_path = current_uri.to_file_path().ok()?;
let found = bynk_ide::symbols::find_declaration_cross_file(files, ¤t_path, name)?;
Some(CrossFileSymbol {
uri: Url::from_file_path(&found.path).ok()?,
span: found.span,
source: found.source,
})
}
pub fn describe_symbol_cross_file(
files: &[PathBuf],
current_uri: &Url,
name: &str,
) -> Option<(Url, String)> {
let current_path = current_uri.to_file_path().ok()?;
let (path, desc) = bynk_ide::symbols::describe_symbol_cross_file(files, ¤t_path, name)?;
Some((Url::from_file_path(&path).ok()?, desc))
}
pub fn linkify_doc_links(
content: &str,
index: &bynk_check::index::ProjectIndex,
doc_scope: &HashMap<String, Vec<String>>,
project_root: &Path,
owner_unit: &str,
) -> String {
let candidates = bynk_ide::symbols::scan_doc_link_candidates(content);
if candidates.is_empty() {
return content.to_string();
}
let mut out = String::with_capacity(content.len());
let mut last = 0;
for cand in candidates {
let Some(def) =
crate::index_queries::resolve_doc_link(index, doc_scope, owner_unit, &cand.name)
else {
continue;
};
let Ok(url) = Url::from_file_path(project_root.join(&def.path)) else {
continue;
};
out.push_str(&content[last..cand.span.start]);
out.push_str(&format!("[{}]({url})", cand.display));
last = cand.span.end;
}
out.push_str(&content[last..]);
out
}