Skip to content

Auto-unindent end #7282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ object Build {
lazy val `vscode-dotty` = project.in(file("vscode-dotty")).
settings(commonSettings).
settings(
version := "0.1.16-snapshot", // Keep in sync with package.json
version := "0.1.17-snapshot", // Keep in sync with package.json
autoScalaLibrary := false,
publishArtifact := false,
includeFilter in unmanagedSources := NothingFilter | "*.ts" | "**.json",
Expand Down
2 changes: 1 addition & 1 deletion vscode-dotty/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vscode-dotty/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "dotty",
"displayName": "Dotty Language Server",
"description": "IDE integration for Dotty, the experimental Scala compiler",
"version": "0.1.16-snapshot",
"version": "0.1.17-snapshot",
"license": "BSD-3-Clause",
"publisher": "lampepfl",
"repository": {
Expand Down
13 changes: 8 additions & 5 deletions vscode-dotty/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ export function activate(context: ExtensionContext) {
// package.json does not work)
vscode.languages.setLanguageConfiguration("scala", {
"indentationRules": {
// Auto-indent when pressing enter on a line matching this regexp
"increaseIndentPattern": /(((\b(then|else|do|catch|finally|yield|match|while|try|for|if|case)\b)|\bif\s*\(.*\)|=|=>|<-|=>>)\s*$)/,
// Auto-unindent disabled, because it doesn't work well with all
// indentation styles
"decreaseIndentPattern": /^.$/
// Auto-indent when pressing enter on a line matching this regexp, in details:
// 1. If they're not preceded by `end`, auto-indent after `while`, `for`, `match`, `try`, `if`
// 2. Auto-indent after `if ...` as long as it doesn't match `if ... then ...`
// 3. Auto-indent after `then`, `else`, `do`, `catch`, `finally`, `yield`, `case`, `=`, `=>`, `<-`, `=>>`x
"increaseIndentPattern":
/(((?<!\bend\b\s*?)\b(if|while|for|match|try))|(\bif\s+(?!.*?\bthen\b.*?$)[^\s]*?)|(\b(then|else|do|catch|finally|yield|case))|=|=>|<-|=>>)\s*?$/,
// Only auto-unindent completed `end` folowed by `while`, `for`, `match`, `try`, `if`
"decreaseIndentPattern": /(\bend\b\s*)\b(if|while|for|match|try)$/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing a check that there's only spaces on the line before end, use ^\s*end instead of \bend.
Also to get this into the next vscode-dotty release, I would have to rebase my branch to include this commit before the release commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should put this in the release.

How pressing is the release? I also found a couple of annoying integration with then+enter and auto-completion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not pressing

I also found a couple of annoying integration with then+enter and auto-completion.

I saw that too, but I think that can only be fixed on the language server side, not the vscode extension side

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could fix it by adding the keywords as template suggestions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though the language server could recommend more precise completion

}
})

Expand Down