use crate::clangd::session::ClangdSessionTrait;
use crate::lsp::traits::LspClientTrait;
use crate::mcp_server::tools::analyze_symbols::AnalyzerError;
use crate::project::component_session::ComponentSession;
use crate::symbol::FileLocation;
pub async fn get_examples(
component_session: &ComponentSession,
symbol_location: &FileLocation,
max_examples: Option<u32>,
) -> Result<Vec<FileLocation>, AnalyzerError> {
let uri = symbol_location.get_uri();
let lsp_position: lsp_types::Position = symbol_location.range.start.into();
component_session
.ensure_file_ready(&symbol_location.file_path)
.await?;
let mut session = component_session.lsp_session().await;
let references = session
.client_mut()
.text_document_references(uri, lsp_position, false)
.await
.map_err(AnalyzerError::from)?;
let reference_locations: Vec<FileLocation> =
references.iter().map(FileLocation::from).collect();
let example_locations = match max_examples {
Some(max) => reference_locations.into_iter().take(max as usize).collect(),
None => reference_locations,
};
Ok(example_locations)
}