Skip to content

fix: preserve original indentation character in /improve suggestions#2429

Open
Oxygen56 wants to merge 1 commit into
The-PR-Agent:mainfrom
Oxygen56:fix/improve-tabs-indentation
Open

fix: preserve original indentation character in /improve suggestions#2429
Oxygen56 wants to merge 1 commit into
The-PR-Agent:mainfrom
Oxygen56:fix/improve-tabs-indentation

Conversation

@Oxygen56

@Oxygen56 Oxygen56 commented Jun 6, 2026

Copy link
Copy Markdown

What

Fixes #1858/improve replaces tabs with spaces in tab-indented codebases (Go, Makefile, etc.)

Root Cause

The dedent_code method in pr_code_suggestions.py only adjusted indentation when delta_spaces > 0 and never normalized the suggestion indentation character to match the original file.

Fix

  1. Handle delta_spaces < 0 (suggested code has more indent than original) with textwrap.dedent
  2. When the original file uses tabs, normalize all suggestion lines to use tabs (4 spaces → 1 tab)
  3. Auto-detection from original file content — no configuration needed

Before

func foo() {
    // suggested code uses spaces ← breaks Go formatting  
    return bar()
}

After

func foo() {
\t// suggested code uses tabs ← preserves original formatting
\treturn bar()
}

The dedent_code method only adjusted indentation when delta_spaces > 0
and never normalized the indentation character. This caused /improve to
replace tabs with spaces in Go, Makefile, and other tab-indented codebases.

Changes:
- Handle delta_spaces < 0 case with dedent (not just > 0)
- Normalize all suggestion lines to use the original file's indentation
  character (tab or space), auto-detected from the existing code

Fixes The-PR-Agent#1858

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions github-actions Bot added the bug label Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/improve uses spaces instead tabs in code suggestions

1 participant