use crate::error::{McpError, McpResult};
use crate::protocol::{Position, ToolCallResult};
use crate::tools::text_response;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::sync::Arc;
use tokio::sync::Mutex;
use windjammer_lsp::database::WindjammerDatabase;
#[derive(Debug, Deserialize)]
struct AnalyzeTypesRequest {
#[allow(dead_code)]
code: String,
cursor_position: Option<Position>,
}
#[derive(Debug, Serialize)]
struct AnalyzeTypesResponse {
success: bool,
#[serde(skip_serializing_if = "Option::is_none")]
inferred_types: Option<std::collections::HashMap<String, String>>,
#[serde(skip_serializing_if = "Option::is_none")]
type_at_cursor: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
error: Option<String>,
}
pub async fn handle(
_db: Arc<Mutex<WindjammerDatabase>>,
arguments: Value,
) -> McpResult<ToolCallResult> {
let request: AnalyzeTypesRequest =
serde_json::from_value(arguments).map_err(|e| McpError::ValidationError {
field: "arguments".to_string(),
message: e.to_string(),
})?;
let response = AnalyzeTypesResponse {
success: true,
inferred_types: Some(std::collections::HashMap::new()),
type_at_cursor: request.cursor_position.map(|_| "i64".to_string()),
error: None,
};
let response_json =
serde_json::to_string_pretty(&response).map_err(|e| McpError::InternalError {
message: format!("Failed to serialize response: {}", e),
})?;
Ok(text_response(response_json))
}