Skip to content

Commit 2113a7b

Browse files
committed
vscode-dotty: Improve auto-indentation
- do not auto-indent after end marker (fixes #7274) - auto-indent after `if ...` as long as it doesn't match `if ... then ...` in anticipation of #7276 - use lazy matching (`.*?` instead of `.*`) when possible to avoid backtracking explosion.
1 parent 3901f2b commit 2113a7b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

vscode-dotty/src/extension.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ export function activate(context: ExtensionContext) {
5454
// package.json does not work)
5555
vscode.languages.setLanguageConfiguration("scala", {
5656
"indentationRules": {
57-
// Auto-indent when pressing enter on a line matching this regexp
58-
"increaseIndentPattern": /(((\b(then|else|do|catch|finally|yield|match|while|try|for|if|case)\b)|\bif\s*\(.*\)|=|=>|<-|=>>)\s*$)/,
57+
// Auto-indent when pressing enter on a line matching this regexp, in details:
58+
// 1. If they're not preceded by `end`, auto-indent after `while`, `for`, `match`, `try`, `if`
59+
// 2. Auto-indent after `if ...` as long as it doesn't match `if ... then ...`
60+
// 3. Auto-indent after `then`, `else`, `do`, `catch`, `finally`, `yield`, `case`, `=`, `=>`, `<-`, `=>>`x
61+
"increaseIndentPattern":
62+
/(((?<!\bend\b\s*?)\b(if|while|for|match|try))|(\bif\s+(?!.*?\bthen\b.*?$)[^\s]*?)|(\b(then|else|do|catch|finally|yield|case))|=|=>|<-|=>>)\s*?$/,
5963
// Auto-unindent disabled, because it doesn't work well with all
6064
// indentation styles
6165
"decreaseIndentPattern": /^.$/

0 commit comments

Comments
 (0)