Skip to content

Commit 37c49f5

Browse files
committed
vscode-dotty: Auto-indentation support for brace-less syntax
By default, vscode knows how to auto-indent code with braces, e.g. given: if (foo) { pressing "Enter" will add one level of indentation. Similarly, entering a closing brace can unindent a line. Ideally, we'd like to do something similar with the brace-less syntax. This commit is a first attempt at doing so by using the built-in support in vscode for defining indentation patterns. Proper automatic unindentation seems much harder to achieve.
1 parent 1d5e95e commit 37c49f5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

vscode-dotty/src/extension.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ function isConfiguredProject() {
5050
}
5151

5252
export function activate(context: ExtensionContext) {
53+
// Override the language configuration from vscode-scala (doing this from
54+
// package.json does not work)
55+
vscode.languages.setLanguageConfiguration("scala", {
56+
"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*$)/,
59+
// Auto-unindent disabled, because it doesn't work well with all
60+
// indentation styles
61+
"decreaseIndentPattern": /^.$/
62+
}
63+
})
64+
5365
extensionContext = context
5466
outputChannel = vscode.window.createOutputChannel("Dotty")
5567
tracer = new Tracer({

0 commit comments

Comments
 (0)