zokugun / vscode-explicit-folding

Customize your Folding for Visual Studio Code
MIT License
95 stars 14 forks source link

Unable to match \n linefeed #63

Closed depascalis closed 2 years ago

depascalis commented 2 years ago

Describe the issue

Unable to match line feed with regex. Whenever \n is used the regex brakes.

Side issue

When \n is used without escaping it there is no error thrown. Example: "endRegex": "\n" Should be: "endRegex": "\\n"

To reproduce

Code Example

  // Comment about what comes next
  "fooBar": {
      "foo": true,
      "bar": false
  }

Settings

  "explicitFolding.rules": {
      "jsonc": {
          "beginRegex": "\\/\\/",
          "endRegex": "^\\n"
      }
  }

I'm not looking for an alternate solution, the code example above is just an example to simplify the issue.

Expected behavior

Posibillity to match linefeed \n The whole code example, from // to the next empty line, should be foldable.

Expected behavior of side issue

Throw error when not escaping \n

Additional context

Related issue https://github.com/zokugun/vscode-explicit-folding/issues/8

It is possible that this lies upstream. I could not find the cause when taking a quick look at the codebase.

daiyam commented 2 years ago

The extension is working line per line so the end of the line is the end of the expression i.e. $. By the way, endRegex is with small x.

"endRegex": "^$" wont work because of the double protection against regex that could match anything (to avoid infinite loop). I will fix that issue.

daiyam commented 2 years ago

I've updated the extension to v0.18.2 (should be available soon) and tested with the following setting:

"[jsonc]": {
    "explicitFolding.debug": true,
    "explicitFolding.rules": [
        {
            "beginRegex": "\\/\\/",
            "endRegex": "^\\s*$",
            "bypassProtection": true
        }
    ]
}
depascalis commented 2 years ago

Awesome work, thanks for the quick fix @daiyam 👏🏻

I actually tried that exact expression before "endRegex": "^\\s*$", it's working with bypassProtection now. endRegeX was just a typo, but thanks :)

So linefeed \n won't be implemented? I saw a error message that listed valid tokens, \n was included in that list.

daiyam commented 2 years ago

Yes, \n won't be implemented. The message must be from the parser used to detect capture groups and more.

depascalis commented 2 years ago

Ok thanks, maybe remove any references to \n to avoid confusion.