MCPcopy Create free account
hub / github.com/AI45Lab/Code / edit_file

Method edit_file

sdk/python/src/lib.rs:2094–2124  ·  view source on GitHub ↗
(
        &self,
        py: Python<'_>,
        path: String,
        old_string: String,
        new_string: String,
        replace_all: bool,
    )

Source from the content-addressed store, hash-verified

2092 /// Edit a file by replacing text in the workspace.
2093 #[pyo3(signature = (path, old_string, new_string, replace_all=false))]
2094 fn edit_file(
2095 &self,
2096 py: Python<'_>,
2097 path: String,
2098 old_string: String,
2099 new_string: String,
2100 replace_all: bool,
2101 ) -> PyResult<PyToolResult> {
2102 let session = self.inner.clone();
2103 let result = py
2104 .allow_threads(move || {
2105 get_runtime().block_on(session.edit_file(
2106 &path,
2107 &old_string,
2108 &new_string,
2109 replace_all,
2110 ))
2111 })
2112 .map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
2113
2114 Ok(PyToolResult {
2115 name: result.name,
2116 output: result.output,
2117 exit_code: result.exit_code,
2118 metadata_json: result.metadata.as_ref().map(serde_json::Value::to_string),
2119 error_kind_json: result
2120 .error_kind
2121 .as_ref()
2122 .and_then(|k| serde_json::to_string(k).ok()),
2123 })
2124 }
2125
2126 /// Apply a unified diff patch to a workspace file.
2127 fn patch_file(&self, py: Python<'_>, path: String, diff: String) -> PyResult<PyToolResult> {

Callers 1

Calls 3

block_onMethod · 0.80
get_runtimeFunction · 0.70
cloneMethod · 0.45

Tested by

no test coverage detected