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

Fix R grammar for highlighting #5017

Merged
merged 1 commit into from
Oct 16, 2024
Merged

Fix R grammar for highlighting #5017

merged 1 commit into from
Oct 16, 2024

Conversation

lionel-
Copy link
Contributor

@lionel- lionel- commented Oct 14, 2024

These changes fix a number of syntax higlighting issues caused by our TextMate grammar for R. Addresses #3688.

We are currently styling most of R variables as keywords or constants, which looks jarring with many themes. With the following changes we now style R variables with the conventional variable.parameter and variable.object scopes:

  • The scopes of identifiers are renamed from constant.other to variable.object and from entity.name.tag to variable.parameter.

  • To ensure these scopes are not overridden by a larger entity scope, we no longer use keyword.operator for bracket scopes, but meta.bracket. This is the appropriate scope prefix for large components in the code, see https://macromates.com/manual/en/language_grammars. This particular scope, meta.bracket, is not as popular as the ones discussed above but is used in the ObjC and Julia grammars.

    Similarly, we no longer scope function definitions as keyword but as meta.function.definition, the convention scope for these entities.

These changes allow colour themes to style R code much more consistently as they do other languages.

Before with Material:

Screenshot 2024-10-14 at 17 06 05

After with Material:

Screenshot 2024-10-14 at 17 06 31

Before with Monokai:

Screenshot 2024-10-14 at 16 26 16

After with Monokai:

Screenshot 2024-10-14 at 16 26 23

Note how these are less heavily styled.

We see kind of the opposite pattern with the default themes because they surprisingly seem to weigh more heavily regular text as opposed to keyword:

Before with Positron Light:

Screenshot 2024-10-14 at 17 11 14

After with Positron Light:

Screenshot 2024-10-14 at 17 10 58

Before with Positron Dark:

Screenshot 2024-10-14 at 16 26 46

After with Positron Dark:

Screenshot 2024-10-14 at 16 26 52

That said, this makes R styling consistent with how the theme works with other languages, here is how Positron Light and Dark style a C file for comparison:

Screenshot 2024-10-14 at 17 04 12 Screenshot 2024-10-14 at 16 28 22

@lionel-
Copy link
Contributor Author

lionel- commented Oct 16, 2024

We've decided to merge this PR to make the R grammar consistent with the other languages. This will cause heavier styling of R code with the default Positron themes, but this is consistent with how we style other languages.

Note that Python will still not be as heavily styled but that is because we are currently not decorating variables with the variable scope: #3731

@lionel- lionel- merged commit d56e898 into main Oct 16, 2024
3 checks passed
@lionel- lionel- deleted the bugfix/r-tm-grammar branch October 16, 2024 07:19
@github-actions github-actions bot locked and limited conversation to collaborators Oct 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants