Skip to content

Add more specific scopes to bool, num, double, int, Object, String, dynamic in textmate grammar #4974

Open

Description

@crkit-chan

Treat bool, num, double, and int as keywords.

Note

It is not necessary to change the default colouring for these types.
These could be configured by the user, or by external theme packs.

Before:

Image of Syntax Highlighting Dark
Image of Syntax Highlighting Light

After:

Image of Syntax Highlighting Dark
Image of Syntax Highlighting Light

(Ignore the difference in bracket colours).

This could also apply to String, Map, List, Set, Object, and dynamic.

  • TextMate Grammars
  • Semantic Highlighting

Activity

  1. added
    is enhancement
    on Feb 3, 2024
  2. changed the title [-]Syntax Highlight bool, num, double, int as Keywords[/-] [+]Syntax Highlight `bool`, `num`, `double`, `int` as Keywords[/+] on Feb 3, 2024
  3. DanTup commented on Feb 5, 2024

    @DanTup
    Member

    Can you provide some motivation for this? Those things are types so it seems like they should be coloured as such.

    Unfortunately we can't change colours conditionally in a textmate grammar, so this isn't something we could control as an option there (we could perhaps have a Semantic Tokens modifier for built-in types like these that would allow you to customise them, but based on your other issues I think you're not using Semantic Tokens and that might not help you).

    To change the textmate grammar, I think it would need to be clear that the majority of users would prefer this change.

  4. added
    awaiting info
    on Feb 5, 2024
  5. crkit-chan commented on Feb 5, 2024

    @crkit-chan
    Author

    Can you provide some motivation for this? Those things are types so it seems like they should be coloured as such.

    Clarification

    I don't need there to be an option to toggle this, I can manually do it in the settings if TextMate grammars are provided.

    Motivation

    Dart is my second language after C#, and I got used to seeing keywords such as int, bool, etc. highlighted as keywords.

    (In fact, the images above are actually from Dart and C#).

    In my opinion, since int, bool, etc. in Dart are built-in types (i.e. shipped with the SDK and don't require an import statement), they could technically be interpreted as keywords.

    In C#, built-in keyworded types are given the scope keyword.type.<type>.cs (e.g. int would be given keyword.type.int.cs).

    Therefore, in Dart, these built-in types could be given scopes such as:

    • keyword.type.int.dart
    • keyword.type.double.dart
    • keyword.type.string.dart
    • keyword.type.num.dart
    • keyword.type.object.dart
    • keyword.type.dynamic.dart
    • keyword.type.set.dart
    • keyword.type.list.dart
    • keyword.type.map.dart
    • keyword.type.symbol.dart
    • keyword.type.bool.dart
  6. DanTup commented on Feb 5, 2024

    @DanTup
    Member

    One option is that we change support.class.dart to support.class.primitive.dart here (and add String to the list):

    {
    "match": "(?<!\\$)\\b(bool|num|int|double|dynamic)\\b(?!\\$)",
    "name": "support.class.dart"
    },

    This should keep the same colouring by default, but I think would allow you to customise the colours yourself in the VS Code settings.

    I think we should only do it for the items in that existing list though. Types like Set/List/Map/etc. are not really special - they are just classes that live inside the SDK (like hundreds of other classes). The textmate grammar cannot tell the difference between List from the SDK and class List {} that is user-defined.

  7. crkit-chan commented on Feb 5, 2024

    @crkit-chan
    Author

    One option is that we change support.class.dart to support.class.primitive.dart (and add String to the list)

    That sounds perfect!

    What about Object though? Would that also be included?

  8. DanTup commented on Feb 5, 2024

    @DanTup
    Member

    Yeah, I think it would be reasonable to include that too.

  9. added this to the v3.84.0 milestone on Feb 5, 2024
  10. added
    in editor
    and removed
    awaiting info
    on Feb 5, 2024
  11. changed the title [-]Syntax Highlight `bool`, `num`, `double`, `int` as Keywords[/-] [+]Add more specific scopes to `bool`, `num`, `double`, `int`, `Object`, `String`, `dynamic` in textmate grammar[/+] on Feb 5, 2024
  12. crkit-chan commented on Feb 5, 2024

    @crkit-chan
    Author

    Sorry, I didn't fully read your comment before.

    To clarify, I use semantic tokens.

    I like them as they provide much richer information, but it is sometimes annoying that they override textmate tokens.

    Sorry, I tried the fix and I actually do need semantic tokens for this, as they are overriding the TextMate tokens.


    With semantic highlighting:

    Screenshot 2024-02-05 at 16 24 43

    Without semantic highlighting:

    Screenshot 2024-02-05 at 16 22 39
  13. DanTup commented on Feb 5, 2024

    @DanTup
    Member

    I use semantic tokens.

    Ah sorry, I misunderstood from comments in #4963 and thought you had semantic tokens disabled.

    Semantic Tokens will completely replace the textmate grammar (this is VS Code behaviour), although the grammar will be used immediately when you open a file and then replaced when the tokens arrive.

    In that case, supporting this would require server changes to add additional modifiers to those types.

  14. modified the milestones: v3.84.0, On Deck on Feb 5, 2024
  15. added
    in lsp/analysis server
    on Feb 5, 2024
  16. crkit-chan commented on Feb 5, 2024

    @crkit-chan
    Author

    Ah sorry, I misunderstood from comments in #4963 and thought you had semantic tokens disabled.

    Sorry, in that issue I meant something like "this syntax highlighting does not need semantic tokens".

    Would it be wise to implement both? (I.e. in this v3.84.0, release TextMate grammars, and later release semantic highlighting)?

  17. DanTupBot commented on Nov 8, 2026

    @DanTupBot
    Collaborator

    Closely related issues requesting finer-grained Semantic Tokens / modifiers for theming:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in editorin lsp/analysis serveris enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions