IndentFix is a VS Code extension that fixes indentation errors via a right-click context menu. It implements a "formatter-first" strategy with a heuristic reindenter fallback, following the PRD requirements.
Features
✅ Context menu command: "IndentFix: Fix Indentation" appears in the editor right-click menu
✅ Formatter-first workflow: Attempts to use VS Code's formatDocument command first
✅ Heuristic reindenter fallback: Language-aware reindentation when formatters are unavailable
✅ Safe edit semantics: Single undo step for all changes
✅ Run-on-save: Optional automatic indentation fixing on save (opt-in)
✅ File size checks: Automatically skips files larger than 1MB
✅ Large change warnings: Prompts user for confirmation when >100 lines would change
✅ Backup option: Can create backup untitled file before applying large changes
✅ Configurable settings: Indent size, tabs vs spaces, language whitelist, formatter preferences
Supported Languages
Python
JavaScript/TypeScript (including JSX/TSX)
Java, C/C++, C#
JSON, HTML, CSS, XML
Quick Start
Install dependencies:
npm install
Build the extension:
npm run build
Run in Development:
Press F5 in VS Code to open a new Extension Development Host
Right-click in any editor and select "IndentFix: Fix Indentation"
Configuration
Open VS Code settings and search for "IndentFix" to configure:
indentfix.indentSize: Number of spaces per indent level (default: 4)
indentfix.useTabs: Use tabs instead of spaces (default: false)
indentfix.runOnSave: Automatically fix indentation on save (default: false)
indentfix.languagesWhitelist: List of language IDs for run-on-save (default: python, javascript, typescript, json, html, css)
indentfix.preferredFormatterPerLanguage: Map languageId to preferred formatter (optional)
Usage
Manual Fix: Right-click in the editor → "IndentFix: Fix Indentation"
Automatic Fix: Enable indentfix.runOnSave in settings for automatic fixing on save
How It Works
Formatter-first: Tries VS Code's editor.action.formatDocument command
Fallback: If formatter fails or doesn't change the file, uses language-aware heuristic reindenter
Safety: For large changes (>100 lines), prompts user with options:
Cancel
Backup + Apply (creates untitled backup file)
Apply
Implementation Details
Single undo step: All changes applied as one WorkspaceEdit
Language-aware: Different heuristics for brace languages (JS/TS/Java) vs Python-like languages
String/comment aware: Avoids modifying lines inside multi-line strings and comments