MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / read_file

Function read_file

crates/opencode-server/src/routes.rs:2978–2992  ·  view source on GitHub ↗
(Query(query): Query<ListFilesQuery>)

Source from the content-addressed store, hash-verified

2976}
2977
2978async fn read_file(Query(query): Query<ListFilesQuery>) -> Result<Json<serde_json::Value>> {
2979 let root = project_root()?;
2980 let path = resolve_input_path(&query.path, &root)?;
2981
2982 if path.is_file() {
2983 match std::fs::read_to_string(&path) {
2984 Ok(content) => Ok(Json(
2985 serde_json::json!({ "content": content, "path": query.path }),
2986 )),
2987 Err(e) => Err(ApiError::BadRequest(format!("Failed to read file: {}", e))),
2988 }
2989 } else {
2990 Err(ApiError::BadRequest("Path is not a file".to_string()))
2991 }
2992}
2993
2994async fn get_file_status() -> Result<Json<Vec<FileStatusInfo>>> {
2995 let cwd = std::env::current_dir()

Callers

nothing calls this directly

Calls 3

project_rootFunction · 0.85
resolve_input_pathFunction · 0.85
is_fileMethod · 0.80

Tested by

no test coverage detected