A VS Code extension that replaces the built-in Java auto-indent with Eclipse JDT-style bracket-aware indentation.
VS Code's built-in editor.autoIndent for Java copies the previous line's indentation level regardless of bracket context. This causes incorrect indentation when pressing Enter after lines like:
public void doSomething(String param,
int value) { // ← cursor here, press Enter
// VS Code puts you at the `int` column; Eclipse/this extension puts you here (inside the block)Implements Eclipse JDT's JavaAutoIndentStrategy heuristics:
- Enter after
{→ indent one level deeper - Enter after
;→ stay at the same indent as the previous statement (sibling) }on empty line → re-aligns to match the opening{'s indent{|}expansion → when cursor is between{and}, Enter produces three lines with the caret in the middleelse/catch/finally→ aligns with matchingif/trycase/default→ aligns withswitch+ one level
- Install the extension (
.vsixfile viaExtensions: Install from VSIX…) - Add to your
settings.json:
"editor.autoIndent": "none",
"javaSmartIndent.enabled": trueSetting autoIndent to "none" prevents VS Code's built-in indentation from fighting with this extension.
| Setting | Default | Description |
|---|---|---|
javaSmartIndent.enabled |
true |
Enable/disable the extension |
javaSmartIndent.autoCloseBrace |
true |
Insert closing } when unclosed brace detected |
npm install
npm run bundle
npm run package # produces java-smart-indent-0.1.0.vsix