use {
crate::{
connect::lsp::{
LspClient,
request::{
PrepareRenameRequest,
Rename as RenameRequest,
},
},
connect::mcp::{
schema,
tool::{
Tool,
ToolError,
ToolRegistry,
},
},
protocol::lsp::{
PrepareRenameResponse,
RenameParams,
TextDocumentPositionParams,
WorkspaceEdit,
},
},
serde_json::json,
};
pub fn register(registry: &mut ToolRegistry) {
registry.register::<PrepareRename>();
registry.register::<Rename>();
}
pub enum PrepareRename {}
impl Tool for PrepareRename {
type Input = TextDocumentPositionParams;
type Output = Option<PrepareRenameResponse>;
const NAME: &'static str = "prepare_rename";
const DESCRIPTION: &'static str =
"Validate that the symbol at the given position can be renamed, and \
return the range that would be replaced. Wraps LSP \
`textDocument/prepareRename`. Does not perform any rename.";
fn input_schema() -> serde_json::Value {
schema::text_document_position()
}
async fn call(
client: &LspClient,
input: Self::Input,
) -> Result<Self::Output, ToolError> {
Ok(client.send_request::<PrepareRenameRequest>(input).await?)
}
}
pub enum Rename {}
impl Tool for Rename {
type Input = RenameParams;
type Output = Option<WorkspaceEdit>;
const NAME: &'static str = "rename";
const DESCRIPTION: &'static str =
"Compute a workspace-wide rename of the symbol at the given position. \
Wraps LSP `textDocument/rename`. Returns the resulting `WorkspaceEdit` \
JSON; does NOT write to the filesystem. The agent is expected to apply \
the edits itself using its own Edit/Write tools.";
fn input_schema() -> serde_json::Value {
json!({
"type": "object",
"properties": {
"textDocument": schema::text_document_identifier(),
"position": schema::position(),
"newName": { "type": "string" }
},
"required": ["textDocument", "position", "newName"]
})
}
async fn call(
client: &LspClient,
input: Self::Input,
) -> Result<Self::Output, ToolError> {
Ok(client.send_request::<RenameRequest>(input).await?)
}
}