Skip to content

Conversation

Patrick-Erichsen
Copy link
Collaborator

@Patrick-Erichsen Patrick-Erichsen commented Sep 9, 2025

Summary

  • Implement autoformatting detection for multiEdit and editFile tools in VSCode extension
  • Capture file content before/after save operations to detect editor autoformatting changes
  • Include autoformatting diff in tool responses with guidance for language model
  • Improve reliability of future edit operations by preventing content mismatch failures

Implementation Details

Key Components Added

  1. Diff Utility (diffUtils.ts)

    • createPrettyPatch function using Continue's existing myersDiff
    • Formats diffs in unified format for language model consumption
    • normalizeContent helper for content comparison
  2. Save Logic Enhancement (processDiff.ts)

    • Capture pre-save content before ide.saveFile() call
    • Capture post-save content after save operation
    • Compare normalized content to detect autoformatting
    • Generate diff if changes detected
  3. Protocol Updates

    • Add autoFormattingDiff?: string field to ApplyState interface
    • Updated in both core/config/types.ts and core/index.d.ts
  4. Tool Response Enhancement (handleApplyStateUpdate.ts)

    • Process autoformatting diff when tool is accepted
    • Add context item with formatted explanation for language model
    • Include guidance about quote changes, semicolons, indentation, etc.

Benefits

  • Improved Edit Reliability: Language model aware of autoformatting changes prevents future edit failures
  • Better Context: LM gets detailed info about quote style changes, semicolon additions/removals, line breaks, indentation
  • Leverages Existing Code: Uses Continue's existing myersDiff function for consistency

Test Plan

  • Test with files that trigger autoformatting (TypeScript, JavaScript with Prettier, etc.)
  • Verify autoformatting diffs are captured correctly in tool responses
  • Ensure no regression in existing edit tool functionality
  • Test that language model receives properly formatted autoformatting information
  • Verify edit operations work correctly after autoformatting detection

Summary by cubic

Detects editor auto-formatting on save for multiEdit/editFile and returns a diff with the tool output. This makes follow-up edits more reliable when Prettier or format-on-save changes the file.

  • New Features
    • Compare file content before and after save in processDiff; always save even without streamId.
    • Generate a pretty patch diff using myersDiff; normalize content before comparing.
    • Add autoFormattingDiff?: string to ApplyState (types.ts and index.d.ts).
    • Show an “Auto-formatting Applied” context item in tool output with guidance on quote, semicolon, and indentation changes.

Implement autoformatting detection similar to Cline's approach to improve reliability of edit operations. When edit tools (multiEdit/editFile) are executed, the system now captures file content before and after save operations to detect editor autoformatting changes.

Key changes:
- Add `createPrettyPatch` utility using existing `myersDiff` function
- Capture pre/post save content in `processDiff.ts`
- Add `autoFormattingDiff` field to `ApplyState` protocol
- Include autoformatting diff in tool responses with guidance for language model
- Help prevent future edit failures due to undetected formatting changes

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@Patrick-Erichsen Patrick-Erichsen requested a review from a team as a code owner September 9, 2025 18:19
@Patrick-Erichsen Patrick-Erichsen requested review from RomneyDa and removed request for a team September 9, 2025 18:19
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Sep 9, 2025
Copy link

github-actions bot commented Sep 9, 2025

⚠️ PR Title Format

Your PR title doesn't follow the conventional commit format, but this won't block your PR from being merged. We recommend using this format for better project organization.

Expected Format:

<type>[optional scope]: <description>

Examples:

  • feat: add changelog generation support
  • fix: resolve login redirect issue
  • docs: update README with new instructions
  • chore: update dependencies

Valid Types:

feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert

This helps with:

  • 📝 Automatic changelog generation
  • 🚀 Automated semantic versioning
  • 📊 Better project history tracking

This is a non-blocking warning - your PR can still be merged without fixing this.

@Patrick-Erichsen Patrick-Erichsen changed the title Add autoformatting detection for edit tools feat: add autoformatting detection for edit tools Sep 9, 2025
Copy link

github-actions bot commented Sep 9, 2025

⚠️ AI review completed but no review output was generated. Check the action logs for details.


💡 To request a new review, comment @continue-general-review

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 5 files

sestinj
sestinj previously approved these changes Sep 11, 2025
@github-project-automation github-project-automation bot moved this from Todo to In Progress in Issues and PRs Sep 11, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Sep 11, 2025
@sestinj sestinj merged commit bcc5600 into main Sep 11, 2025
54 of 56 checks passed
@sestinj sestinj deleted the pe/autoformat-results branch September 11, 2025 17:36
@github-project-automation github-project-automation bot moved this from In Progress to Done in Issues and PRs Sep 11, 2025
@github-actions github-actions bot added the tier 2 Important feature that adds new capabilities to the platform or improves critical user journeys label Sep 11, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Sep 11, 2025
@sestinj
Copy link
Contributor

sestinj commented Sep 11, 2025

🎉 This PR is included in version 1.13.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm This PR has been approved by a maintainer released size:M This PR changes 30-99 lines, ignoring generated files. tier 2 Important feature that adds new capabilities to the platform or improves critical user journeys
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants