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

semanticTokenScopes produces wrgon mappin #94367

Closed
matklad opened this issue Apr 3, 2020 · 4 comments
Closed

semanticTokenScopes produces wrgon mappin #94367

matklad opened this issue Apr 3, 2020 · 4 comments
Assignees

Comments

@matklad
Copy link

matklad commented Apr 3, 2020

Version: 1.44.0-insider
Commit: 20b88fa
Date: 2020-04-01T08:29:34.507Z
Electron: 7.1.11
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Linux x64 4.19.113

Problem: I am developing an extension which takes advantage of semantic highlighting, and looks like "semanticTokenScopes" selector matching is broken. Specifically, my pluging defines the mapping like this:

        "semanticTokenScopes": [
            {
                "language": "rust",
                "scopes": {
                    "attribute": [
                        "meta.attribute"
                    ],
                    "builtinType": [
                        "support.type.primitive"
                    ],
                    "lifetime": [
                        "entity.name.lifetime.rust"
                    ],
                    "typeAlias": [
                        "entity.name.typeAlias"
                    ],
                    "union": [
                        "entity.name.union"
                    ],
                    "keyword.unsafe": [
                        "keyword.other.unsafe"
                    ],
                    "keyword.control": [ // <- the interesting bit
                        "keyword.control"
                    ],
                    "variable.constant": [
                        "entity.name.constant"
                    ]
                }
            }
        ]

but somehow control styling is applied to all keywords, not only to control ones:

image

image

Note that I also use a "zero" textmate grammar for rust, to make sure that there's no interference wit tm, but the same bug is observable with default rust grammar as well.

Steps to Reproduce:

  1. Install rust-analyzer from source
  2. Enable semantic highlighitng with { "rust-analyzer.highlighting.semanticTokens": true, "editor.semanticHighlighting.enabled": true, }
  3. Observe all keywords colored as control keywords
@aeschli
Copy link
Contributor

aeschli commented Apr 3, 2020

We have a set of default rules configured, and keyword currently goes to TextMate scope keyword.control: see

registerTokenType('keyword', nls.localize('keyword', "Style for keywords."), [['keyword.control']]);

You can overwrite that for rust, if you prefer:

"semanticTokenScopes": [
            {
                "language": "rust",
                "scopes": {
                    "keyword": [
                        "keyword"
                    ]
            }
]

@matklad
Copy link
Author

matklad commented Apr 3, 2020

Ah... Yeah, that explains the observed behavior. I wonder though, why default maps to keyword.control and not just to keyword?

@aeschli
Copy link
Contributor

aeschli commented Apr 5, 2020

It comes from the built-in default themes where we differentiate between keywords ('if', 'function', ...) ('keyword.control') and operators ('and', 'not') ('keyword.operator'). So we basically interested in the color that a theme gives to the the first set.

@matklad
Copy link
Author

matklad commented Apr 5, 2020

Hm, right, that makes sense. Textmate scopes are confusing,I hope we’ll transition to more consistent semantic selectors eventually. Thanks for the explanation!

@matklad matklad closed this as completed Apr 5, 2020
matklad added a commit to matklad/rust-analyzer that referenced this issue Apr 6, 2020
In textmate, keyword.control is used for all kinds of things; in fact,
the default scope mapping for keyword is keyword.control!

So let's add a less ambiguous controlFlow modifier

See microsoft/vscode#94367
matklad added a commit to matklad/rust-analyzer that referenced this issue May 6, 2020
bors bot added a commit to rust-lang/rust-analyzer that referenced this issue May 6, 2020
4353: Better mapping to TextMate scopes for keywords r=matklad a=matklad

microsoft/vscode#94367 (comment)



bors r+
🤖

Co-authored-by: Aleksey Kladov <[email protected]>
@github-actions github-actions bot locked and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants