Skip to content

Syntax highlighting for generic get methods inconsistent #4957

Closed

Description

@icnahom

Describe the bug
Highlighting error: Generic get function is treated as keyword when proving the generic type.

To Reproduce
Take this code snippet:

void main() {
  get();
  get<int>();
}

void get<T>() {}

Expected behavior
Having consistent highlighting that resembles a method instead of a keyword.

Screenshots
image

Please complete the following information:

You can run the Dart: Collect Diagnostic Information command from the VS Code command palette (F1) to easily capture this information or provide it manually.

  • Operating System and version: "Windows 10 Pro" 10.0 (Build 22635)
  • VS Code version: win 1.85.2
  • Dart extension version: 3.80.0
  • Dart/Flutter SDK version: 3.2.3/3.16.3
  • Target device (if the issue relates to Flutter debugging):

Activity

  1. DanTup commented on Jan 24, 2024

    @DanTup
    Member

    @icnahom could you confirm which theme you're using in VS Code, and what you have this setting set to?

    image

    The issue is likely in the textmate grammar, but if your theme supports it I would recommend using semantic tokens since the textmate grammar will never be as accurate or complete as semantic tokens.

  2. added
    awaiting infoRequires more information from the customer to progress
    on Jan 24, 2024
  3. icnahom commented on Jan 24, 2024

    @icnahom
    Author

    @DanTup The theme I'm using is "GitHub Dark Default" from the Extension GitHub.github-vscode-theme.

    When I enable semanticHighlighting "editor.semanticHighlighting.enabled": true, it works for the "get" issue I mentioned but messes up other codes' highlighting.

    image

    Broken highlighting, with "editor.semanticHighlighting.enabled": true.
    image

    Working highlighting, with "editor.semanticHighlighting.enabled": false.
    image

  4. DanTup commented on Jan 24, 2024

    @DanTup
    Member

    Thanks for the info.

    Semantic tokens is the preferred way and the only way to get completely reliable highlighting (because it uses the real Dart parser). If things in your theme look bad with semantic tokens, it might be worth filing issues to try and get the theme updated.

    The textmate grammar is much more basic and a best-effort. It uses regex and not a real Dart parser, so there will always be some things that aren't highlighted perfectly.

    This case looks fairly simple though, so I'll see if it can be improved. The handling of get is a bit special because it can be both a keyword and a method name (and without a real parser, it's hard to know which).

  5. added
    in editorRelates to code editing or language features
    and removed
    awaiting infoRequires more information from the customer to progress
    on Jan 24, 2024
  6. added this to the v3.82.0 milestone on Jan 24, 2024
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 editorRelates to code editing or language featuresis bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions