Skip to content

Return the formatted file for file-output formatters - #765

Merged
mehmetozguldev merged 1 commit into
athasdev:mainfrom
IzonIcy:fix/file-based-formatter-output
Oct 4, 2026
Merged

mehmetozguldev merged 1 commit into
athasdev:mainfrom
IzonIcy:fix/file-based-formatter-output

Conversation

@IzonIcy

@IzonIcy IzonIcy commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Formatters configured with outputMethod: "file" rewrite the file in place, but format_with_generic never read it back. It returned the original content while reporting success: true, so the user silently kept unformatted text with no error surfaced. This predates the agent-chat redesign: the branch came from commit 1e321ac0 ("Unify editor command execution"), which left the TODO unimplemented.

  • Return the file's contents when outputMethod is not stdout
  • Return an error when no file_path was supplied
  • Fall back to the original content when the file cannot be read, rather than failing the request
  • Added two regression tests for the file-output path and the missing-path error

How to test:

  1. cargo test -p athas --bin athas -- commands::editor::format
  2. Confirm returns_file_contents_for_file_output_method fails if the else branch is reverted to content.to_string(), since rustfmt rewrites the temp file while the response keeps returning the unformatted input.

Screenshots:

Not applicable.

Validation

  • cargo check --workspace --all-targets — pass
  • cargo clippy --workspace --all-targets -- -D warnings — pass
  • cargo test --workspace --no-fail-fast — pass, 0 failures
  • cargo fmt --check — this file is clean. Note the repo pins nightly in rust-toolchain.toml and CI runs nightly for fmt; on a stable toolchain the check reports unrelated pre-existing diffs in crates/ai, crates/runtime, crates/terminal, crates/tooling and crates/wsl. None are from this change.

Gap: the tests shell out to rustfmt as the file formatter. That keeps the test honest end to end, but it does assume rustfmt is on PATH in CI, which the existing cargo fmt --check gate already guarantees.

format_with_generic returned the original content for any formatter whose
outputMethod is not "stdout". Extensions that reformat a file in place
therefore reported success while handing back unformatted text.

Read the file back instead, which is what the file output method actually
means. A missing file path now fails loudly, and a file that cannot be read
falls back to the original content rather than failing the whole request.

The TODO this replaces came from 1e321ac, which unified editor command
execution but left the file branch unimplemented.
Copilot AI balanced review requested due to automatic review settings October 1, 2026 22:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@mehmetozguldev
mehmetozguldev self-requested a review October 2, 2026 18:34
@mehmetozguldev
mehmetozguldev merged commit 003b057 into athasdev:main Oct 4, 2026
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants