MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / write_sibling_temp_file

Function write_sibling_temp_file

src/formatting.rs:482–500  ·  view source on GitHub ↗

Write content to a temporary file in the same directory as `original` so that tool config discovery (which walks up from the file) works. Returns a `NamedTempFile` whose destructor automatically removes the file on drop. The caller must keep it alive until after reading back the formatted content.

(original: &Path, content: &str)

Source from the content-addressed store, hash-verified

480/// file on drop. The caller must keep it alive until after reading back
481/// the formatted content.
482fn write_sibling_temp_file(original: &Path, content: &str) -> Result<NamedTempFile, String> {
483 let parent = original
484 .parent()
485 .ok_or_else(|| "Cannot determine parent directory of file".to_string())?;
486
487 let mut temp = tempfile::Builder::new()
488 .prefix(".phpantom-fmt-")
489 .suffix(".php")
490 .tempfile_in(parent)
491 .map_err(|e| format!("Failed to create temp file in {}: {}", parent.display(), e))?;
492
493 temp.write_all(content.as_bytes())
494 .map_err(|e| format!("Failed to write temp file: {}", e))?;
495
496 temp.flush()
497 .map_err(|e| format!("Failed to flush temp file: {}", e))?;
498
499 Ok(temp)
500}
501
502/// Result of running an external command.
503struct CommandResult {

Callers 3

run_php_cs_fixerFunction · 0.85
run_phpcbfFunction · 0.85

Calls 1

prefixMethod · 0.80

Tested by 1