use {
crate::{
connect::lsp::{
LspClient,
request::References,
},
connect::mcp::{
schema,
tool::{
Tool,
ToolError,
ToolRegistry,
},
},
protocol::lsp::{
Location,
ReferenceParams,
},
},
serde_json::json,
};
pub fn register(registry: &mut ToolRegistry) {
registry.register::<FindReferences>();
}
pub enum FindReferences {}
impl Tool for FindReferences {
type Input = ReferenceParams;
type Output = Option<Vec<Location>>;
const NAME: &'static str = "find_references";
const DESCRIPTION: &'static str =
"Find all references to the symbol at the given position across the \
workspace. Wraps LSP `textDocument/references`.";
fn input_schema() -> serde_json::Value {
json!({
"type": "object",
"properties": {
"textDocument": schema::text_document_identifier(),
"position": schema::position(),
"context": {
"type": "object",
"properties": {
"includeDeclaration": {
"type": "boolean",
"description": "If true, the declaration site is included in the result."
}
},
"required": ["includeDeclaration"]
}
},
"required": ["textDocument", "position", "context"]
})
}
async fn call(
client: &LspClient,
input: Self::Input,
) -> Result<Self::Output, ToolError> {
Ok(client.send_request::<References>(input).await?)
}
}