1/// The implementation of this tool draws heavily from Zed's
2/// See
3use std::path::PathBuf;
4
5use async_lsp::LanguageServer;
6use async_lsp::lsp_types::{
7 DocumentDiagnosticParams, DocumentDiagnosticReportResult, PartialResultParams,
8 TextDocumentIdentifier, Url, WorkDoneProgressParams,
9};
10use rmcp::ErrorData as MCPError;
11use rmcp::{handler::server::wrapper::Parameters, model::CallToolResult, schemars, serde_json};
12
13use crate::mcp::*;
14
15#[derive(Debug, serde::Deserialize, schemars::JsonSchema)]
16pub struct ReadToolArgs {
17 pub path: PathBuf,
18 pub range_start: usize,
19 pub range_end: usize,
20}
21
22#[derive(Debug, serde::Serialize)]
23pub struct ReadToolOutput {
24 pub content: Option<String>,
25 pub diagnostics: DocumentDiagnosticReportResult,
26}
27
28pub async fn call(
29 server: &MCPServer,
30 Parameters(args): Parameters<ReadToolArgs>,
31) -> Result<CallToolResult, MCPError> {
32 let file_path = server
33 .config
34 .path_in_project(&args.path)
35 .await
36 .map_err(|err| MCPError::invalid_request(format!("{:?}", err), None))?
37 .ok_or_else(|| {
38 MCPError::invalid_params(format!("Path not in project: {:?}", &args.path), None)
39 })?;
40
41 Err(MCPError::internal_error("Not yet implemented", None))
42 // let content = tokio::fs::read_to_string(&file_path)
43 // .await
44 // .map_err(|e| MCPError::invalid_request(format!("Failed to read file: {e}"), None))?;
45
46 // let mut lsp_server = server.lsp_server.clone();
47
48 // let diagnostic_report = lsp_server
49 // .document_diagnostic(DocumentDiagnosticParams {
50 // text_document: TextDocumentIdentifier::new(Url::from_file_path(file_path).unwrap()),
51 // identifier: None,
52 // previous_result_id: None,
53 // work_done_progress_params: WorkDoneProgressParams {
54 // work_done_token: None,
55 // },
56 // partial_result_params: PartialResultParams {
57 // partial_result_token: None,
58 // },
59 // })
60 // .await
61 // .unwrap();
62
63 // Ok(CallToolResult {
64 // content: vec![],
65 // structured_content: Some(serde_json::json!(ReadToolOutput {
66 // content: Some(content),
67 // diagnostics: diagnostic_report
68 // })),
69 // is_error: None,
70 // meta: None,
71 // })
72}