microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.4k stars 29.33k forks source link

[Bug]: Incorrect indentation when object nested inline on the same line as parent object #209521

Open aiday-mar opened 7 months ago

aiday-mar commented 7 months ago

Consider the following example:

const a = { b : {},

The current regex pattern for increase the indent does not match the line, so after pressing Enter at the end of the line, there is no indentation. This is a bug.

aiday-mar commented 7 months ago

Recursive regex seems to not be available yet for JavaScript in order to match full closing braces: https://stackoverflow.com/questions/4414339/recursive-matching-with-regular-expressions-in-javascript

It is possible to implement recursion to a certain depth for example here: https://blog.stevenlevithan.com/archives/regex-recursion. We could implement a recursive pattern here with depth 3, for example to match balancing brackets.