MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / execute

Method execute

crates/opencode-tool/src/lsp_tool.rs:86–143  ·  view source on GitHub ↗
(
        &self,
        args: serde_json::Value,
        ctx: ToolContext,
    )

Source from the content-addressed store, hash-verified

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(&params.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(&params, &path, line, character, &ctx).await
126 }
127
128 #[cfg(not(feature = "lsp"))]
129 {
130 let output =
131 format_lsp_placeholder(&params.operation, &params.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 }

Callers

nothing calls this directly

Calls 10

newFunction · 0.85
execute_with_lspFunction · 0.85
format_lsp_placeholderFunction · 0.85
existsMethod · 0.80
is_external_pathMethod · 0.80
ask_permissionMethod · 0.80
with_metadataMethod · 0.80
with_patternMethod · 0.80
always_allowMethod · 0.80
with_patternsMethod · 0.80

Tested by

no test coverage detected