Skip to content
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

Bracket pair colorization in regexes #134560

Closed
thorn0 opened this issue Oct 7, 2021 · 7 comments
Closed

Bracket pair colorization in regexes #134560

thorn0 opened this issue Oct 7, 2021 · 7 comments
Assignees
Labels
*extension-candidate Issue identified as good extension implementation

Comments

@thorn0
Copy link

thorn0 commented Oct 7, 2021

From time to time I see bracket pairs in regexes get highlighted.

image

Probably, this is a manifestation of #132249, but it looks super useful as it improves the readability of long regexes a lot. Please consider turning this into a feature.

Version: 1.60.2 (user setup)
Commit: 7f6ab54
Date: 2021-09-22T12:00:31.514Z
Electron: 13.1.8
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Windows_NT x64 10.0.19043

@ghost
Copy link

ghost commented Oct 7, 2021

This would be very useful for long/complicated/nested regex's. I would assume it would ignore literal brackets like \(, \[, etc.

@gjsjohnmurray
Copy link
Contributor

/assign @hediet

@hediet
Copy link
Member

hediet commented Oct 11, 2021

I would assume it would ignore literal brackets like (, [, etc.

This makes it much more complex and unfeasable for the existing bracket pair detection infrastructure.

I think this feature is best implemented by an extension.

Regular expressions are usually very short.
A TypeScript (/JavaScript) language service plugin could use the AST to detect where regexps are.
A package such as https://www.npmjs.com/package/regexpp could be used to parse the regexp.
You can then use decorations to colorize the regular expression.

@hediet hediet added the *extension-candidate Issue identified as good extension implementation label Oct 11, 2021
@ghost
Copy link

ghost commented Oct 11, 2021

This makes it much more complex and unfeasable for the existing bracket pair detection infrastructure.

Huh I thought that would make it easer as you would have logical pairs that are guaranteed to have a closing bracket right?

@hediet
Copy link
Member

hediet commented Oct 12, 2021

Huh I thought that would make it easer

What about [)]? The regex is not tokenized itself (the regex is a single token), so the bracket matching infrastructure does not know which characters are brackets and which aren't.

@ghost
Copy link

ghost commented Oct 12, 2021

The regex is not tokenized itself (the regex is a single token)

That clears up the confusion

@github-actions github-actions bot locked and limited conversation to collaborators Nov 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*extension-candidate Issue identified as good extension implementation
Projects
None yet
Development

No branches or pull requests

4 participants
@thorn0 @hediet @gjsjohnmurray and others