use {
crate::{
connect::lsp::{
LspClient,
request::CodeActionRequest,
},
connect::mcp::{
schema,
tool::{
Tool,
ToolError,
ToolRegistry,
},
},
protocol::lsp::{
CodeActionParams,
CodeActionResponse,
},
},
serde_json::json,
};
pub fn register(registry: &mut ToolRegistry) {
registry.register::<CodeActions>();
}
pub enum CodeActions {}
impl Tool for CodeActions {
type Input = CodeActionParams;
type Output = Option<CodeActionResponse>;
const NAME: &'static str = "code_actions";
const DESCRIPTION: &'static str =
"List code actions (quick fixes, refactors, etc.) applicable to a range \
in a file. Wraps LSP `textDocument/codeAction`. Returns the action \
descriptors; does not apply them.";
fn input_schema() -> serde_json::Value {
json!({
"type": "object",
"properties": {
"textDocument": schema::text_document_identifier(),
"range": schema::range(),
"context": {
"type": "object",
"properties": {
"diagnostics": { "type": "array" },
"only": { "type": "array", "items": { "type": "string" } },
"triggerKind": { "type": "integer" }
},
"required": ["diagnostics"]
}
},
"required": ["textDocument", "range", "context"]
})
}
async fn call(
client: &LspClient,
input: Self::Input,
) -> Result<Self::Output, ToolError> {
Ok(client.send_request::<CodeActionRequest>(input).await?)
}
}