vscode-scala-syntax icon indicating copy to clipboard operation
vscode-scala-syntax copied to clipboard

Missing indentation rules

Open olafurpg opened this issue 6 years ago • 2 comments

Language extensions can provide rules for increasing/decreasing indentation when writing new lines and copy-pasting code. The VS Code documentation for this feature is here https://code.visualstudio.com/updates/v1_14#_auto-indent-on-type-move-lines-and-paste

Some scenarios where the current indentation behavior can be improved, the | marker is the position of the cursor

-- obtained
++ expected

  val x =
- |
+   |

  val x = (n: Int) =>
- |
+   |

  1 match {
    case 1 =>
-   |
+     |

To play around with this feature, the language-configuration.json file needs to be updated with regex rules like this:

{
  "indentationRules": {
    "increaseIndentPattern": "^\\s*((begin|class|def|else|elsif|ensure|for|if|module|rescue|unless|until|when|while)|(.*\\sdo\\b))\\b[^\\{;]*$",
    "decreaseIndentPattern": "^\\s*([}\\]]([,)]?\\s*(#_|$)|\\.[a-zA-Z_]\\w*\\b)|(end|rescue|ensure|else|elsif|when)\\b)"
  }
}

https://github.com/scala/vscode-scala-syntax/blob/5211d13c231498d0ca4480a81e1e9cfa4741875b/language-configuration.json

olafurpg avatar Jun 19 '19 16:06 olafurpg

A workaround to improve the current copy-paste behavior by a tiny bit is to disable the "auto indent" setting in VS Code

Screenshot 2019-06-19 at 18 07 49

olafurpg avatar Jun 19 '19 16:06 olafurpg

@odersky this feature might be interesting for the new syntax

nicolasstucki avatar Sep 17 '19 13:09 nicolasstucki