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

Use textmate grammar token kind to exclude unbalanced brackets from being colorized #144736

Closed
hediet opened this issue Mar 9, 2022 · 3 comments · Fixed by #146962
Closed

Use textmate grammar token kind to exclude unbalanced brackets from being colorized #144736

hediet opened this issue Mar 9, 2022 · 3 comments · Fixed by #146962
Assignees
Labels
bracket-pair-colorization feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@hediet
Copy link
Member

hediet commented Mar 9, 2022

When a bracket is marked as comment, string or regexp token, it is not considered for bracket pair matching. It would be great to have a non-bracket token, so that we can use < ... > in languages such as TypeScript or rust, where it is both used as bracket and as comparison operator. The comparison operator should have token-kind non-bracket.

Would fix #144723, #138868, #142117, #145219 and others.

@alexdima FYI


We could some bits from the background color:

https://github.com/microsoft/vscode-textmate/blob/677f741f5b5ef69589e0e5d2a6e556f94514cbfd/src/main.ts#L217

@hediet hediet added feature-request Request for new features or functionality bracket-pair-colorization labels Mar 9, 2022
@hediet hediet added this to the Backlog milestone Mar 9, 2022
@hediet hediet self-assigned this Mar 9, 2022
@Lemmingh
Copy link
Contributor

I like the idea of taking advantage of parsing result.

However, I wonder if it's reliable to use TextMate-based tokenization. TextMate grammar has serious limitations, and cannot correctly express many languages, like C++, TypeScript, HTML, and Markdown. For example, we have to compile the whole project first to understand this C++ code:

a<b<c>> d;

Perhaps semantic tokens will be a good candidate to power this feature.

@hediet
Copy link
Member Author

hediet commented Apr 27, 2022

verification steps:

A grammar contribution can now define balancedBracketScopes (defaults to ['*']) and unbalancedBracketScopes (defaults to []).

The easiest way to try this is out is by changing an existing grammar contribution (package.json -> contributes/grammars, like here)

There you can list scopes to exclude or include scopes which contains balanced brackets.

"balancedBracketScopes": [
    "*"
],
"unbalancedBracketScopes": [
    "meta.scope.case-pattern.shell"
]

Verify that bracket pair colorization does not colorize scopes which contain unbalanced brackets or scopes that aren't included in balancedBracketScopes.

@hediet hediet removed the verification-steps-needed Steps to verify are needed for verification label Apr 27, 2022
@rchiodo
Copy link
Contributor

rchiodo commented Apr 27, 2022

/verified, I think?

I opened a 'sh' file with stable and insiders.

For the case-pattern, stable will show this:

image

Insiders shows this, where it looks to me like it's allowing the unbalanced bracket scope.

image

@rchiodo rchiodo added the verified Verification succeeded label Apr 27, 2022
@github-actions github-actions bot locked and limited conversation to collaborators May 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bracket-pair-colorization feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants
@jrieken @hediet @rchiodo @joyceerhl @Lemmingh and others