use crate::clangd::session::ClangdSessionTrait;
use tracing::debug;
use crate::lsp::traits::LspClientTrait;
use crate::mcp_server::tools::analyze_symbols::AnalyzerError;
use crate::project::component_session::ComponentSession;
use crate::symbol::Symbol;
pub async fn get_matching_symbol(
symbol_query: &str,
component_session: &ComponentSession,
) -> Result<Symbol, AnalyzerError> {
let mut session = component_session.lsp_session().await;
let symbols = session
.client_mut()
.workspace_symbols(symbol_query.to_string())
.await
.map_err(AnalyzerError::from)?;
if symbols.is_empty() {
return Err(AnalyzerError::NoSymbols(symbol_query.to_string()));
}
debug!(
"Found {} symbols matching '{}'",
symbols.len(),
symbol_query
);
Ok(symbols[0].clone().into())
}