(
&self,
args: serde_json::Value,
ctx: ToolContext,
)
| 84 | } |
| 85 | |
| 86 | async fn execute( |
| 87 | &self, |
| 88 | args: serde_json::Value, |
| 89 | ctx: ToolContext, |
| 90 | ) -> Result<ToolResult, ToolError> { |
| 91 | let params: LspParams = serde_json::from_value(args) |
| 92 | .map_err(|e| ToolError::InvalidArguments(format!("Invalid parameters: {}", e)))?; |
| 93 | |
| 94 | let path = PathBuf::from(¶ms.file_path); |
| 95 | let path_str = path.to_string_lossy().to_string(); |
| 96 | |
| 97 | if !path.exists() { |
| 98 | return Err(ToolError::FileNotFound(format!( |
| 99 | "File not found: {}", |
| 100 | params.file_path |
| 101 | ))); |
| 102 | } |
| 103 | |
| 104 | if ctx.is_external_path(&path_str) { |
| 105 | ctx.ask_permission( |
| 106 | crate::PermissionRequest::new("external_directory") |
| 107 | .with_pattern(&path_str) |
| 108 | .with_metadata("filepath", serde_json::json!(&path_str)), |
| 109 | ) |
| 110 | .await?; |
| 111 | } |
| 112 | |
| 113 | ctx.ask_permission( |
| 114 | crate::PermissionRequest::new("lsp") |
| 115 | .with_patterns(vec!["*".to_string()]) |
| 116 | .always_allow(), |
| 117 | ) |
| 118 | .await?; |
| 119 | |
| 120 | let line = params.line.map(|l| l.saturating_sub(1)).unwrap_or(0); |
| 121 | let character = params.character.map(|c| c.saturating_sub(1)).unwrap_or(0); |
| 122 | |
| 123 | #[cfg(feature = "lsp")] |
| 124 | { |
| 125 | execute_with_lsp(¶ms, &path, line, character, &ctx).await |
| 126 | } |
| 127 | |
| 128 | #[cfg(not(feature = "lsp"))] |
| 129 | { |
| 130 | let output = |
| 131 | format_lsp_placeholder(¶ms.operation, ¶ms.file_path, line, character); |
| 132 | let mut metadata = Metadata::new(); |
| 133 | metadata.insert("operation".to_string(), serde_json::json!(params.operation)); |
| 134 | metadata.insert("file_path".to_string(), serde_json::json!(params.file_path)); |
| 135 | |
| 136 | Ok(ToolResult { |
| 137 | output, |
| 138 | title: format!("LSP: {:?} {}", params.operation, params.file_path), |
| 139 | metadata, |
| 140 | truncated: false, |
| 141 | }) |
| 142 | } |
| 143 | } |
nothing calls this directly
no test coverage detected