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

Syntax highlighting of and/or/not/in in Starlark #396

Closed
nicolasstucki opened this issue May 17, 2024 · 8 comments · Fixed by #397
Closed

Syntax highlighting of and/or/not/in in Starlark #396

nicolasstucki opened this issue May 17, 2024 · 8 comments · Fixed by #397

Comments

@nicolasstucki
Copy link
Contributor

The following rule matches those keywords but do not result in any highlighting.

"match": "\\b(?<!\\.)(?:(and|or|not|in)(?# 1)|(for|if|else)(?# 2))(?!\\s*:)\\b|(\\*|\\+|-|%|//|/)(?# 3)|(!=|==|>=|<=|<|>)(?# 4)",

Screenshot 2024-05-17 at 11 36 48

These are currently tagged as

"name": "keyword.operator.logical.starlark"

@nicolasstucki
Copy link
Contributor Author

If we change the tag name to the following we get the same highlighting as in a Python file.

- "name": "keyword.operator.logical.starlark" 
+ "name": "keyword.language.logical.starlark"
Screenshot 2024-05-17 at 16 11 38

I am not sure if language is the same category used by the Python extension.

@vogelsgesang
Copy link
Collaborator

According to the documentation at https://macromates.com/manual/en/language_grammars (which is referenced by the VSCode docs), keyword.operator.* seems to be the right way to go. I wonder where the keyword.language.* is defined...

@vogelsgesang
Copy link
Collaborator

Also VSCode has a lot of mentions of keyword.operator.logical but not a single mention of keyword.language

@nicolasstucki
Copy link
Contributor Author

I see. My patch probably ended up falling back on keyword and therefore used the same highlighting as in keyword.operator.logical.python. The issue here seems to be that the highlighting of those operators as keywords is special-cased for Python with keyword.operator.logical.python and hence we do not get the same effect with keyword.operator.logical.starlark.

@vogelsgesang
Copy link
Collaborator

I wonder if we should use keyword.operator.logical.python.starlark. That way we would inherit the styles from Python by default, but theme authors would still have the option to provide Starlark specific styles, if they wish to do so

@nicolasstucki
Copy link
Contributor Author

keyword.operator.logical.python.starlark is an interesting approach. If we take this approach would we also change all others .starlark to .python.starlark to inherit all existing highlighings? This would imply changing around 100 names.

@vogelsgesang
Copy link
Collaborator

Personally, I would just rename all of them, for consistency. But others might have different opinions...
Could you create a PR? And then let's see if anybody dislikes the renaming during the review

@nicolasstucki
Copy link
Contributor Author

Yes @vogelsgesang, I can create a PR with this change.

nicolasstucki added a commit to nicolasstucki/vscode-bazel that referenced this issue May 19, 2024
This fixes bazelbuild#396. Changes the `.starlark` name suffix to `.python.starlark`.

By using both `python` and `starlark`, vscode is able to default to Python
highlighting if a color theme defines colors specifically for `python`.
For example, default color themes in vscode use
`keyword.operator.logical.python` to highlight `and`/`or`/`not`/`in`.
nicolasstucki added a commit to nicolasstucki/vscode-bazel that referenced this issue May 19, 2024
This fixes bazelbuild#396. Changes the `.starlark` name suffix to `.python.starlark`.

By using both `python` and `starlark`, vscode is able to default to Python
highlighting if a color theme defines colors specifically for `python`.
For example, default color themes in vscode use
`keyword.operator.logical.python` to highlight `and`/`or`/`not`/`in`.
vogelsgesang pushed a commit that referenced this issue May 27, 2024
This fixes #396. Changes the `.starlark` name suffix to `.python.starlark`.

By using both `python` and `starlark`, vscode is able to default to Python
highlighting if a color theme defines colors specifically for `python`.
For example, default color themes in vscode use
`keyword.operator.logical.python` to highlight `and`/`or`/`not`/`in`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants