Skip to content

Syntax highlighting colours function names differently when starting with capital #311

Closed

Description

@DanTup

Not sure how easy this will be to fix, but TypeScript doesn't seem to have this problem. We should be able to identify functions from the parens?

Colours

Activity

  1. added
    is enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.
    good first issue :octocat:A relatively straight forward issue that could be done by a new contributor
    on May 25, 2017
  2. Skylled commented on May 25, 2017

    @Skylled
    Contributor

    Isn't this because capitalization implies a Class name instead of a function?

  3. DanTup commented on May 25, 2017

    @DanTup
    MemberAuthor

    That's the convention; but you don't have to follow it. If we were using the data from the analyzer, I'd expect they would be coloured correctly (based on actual AST, not guesses based on casing) so ideally we should be the same (whether it's reasonable or worthwhile, I don't know.. maybe we should just hope for microsoft/vscode#1967!)

  4. added
    in editorRelates to code editing or language features
    on Jun 24, 2017
  5. Skylled commented on Jul 23, 2017

    @Skylled
    Contributor

    Looking at this again on a whim, maybe we could assume that any ambiguous capitalized object that is followed by parens but not preceded by new or const is a function.

    class IsClass {}
    
    void NotClass(){}
    
    var x = new IsClass();
    var y = NotClass();
    

    But that still won't help when assigning a function to a variable.

    someObj.callback = NotClass // There's nothing here to detect from.
    

    Additionally, the inverse problem is also true, lowerCamelCase class names are not treated correctly.

    class alsoAClass {} // No colorizing
    var z = new alsoAClass(); // Colored as a function
    

    Seems like the best solution would be to get direct from the AST, as you said.

  6. DanTup commented on Jul 24, 2017

    @DanTup
    MemberAuthor

    I think using the parens is probably the best way; seems more reliable than guessing based on case. I don't think Code is going to support dynamic colouring anytime soon :(

    I'll see if I can change the regex at some point to handle this better.

  7. removed
    good first issue :octocat:A relatively straight forward issue that could be done by a new contributor
    on Feb 2, 2018
  8. added this to the Backlog milestone on Feb 21, 2018
  9. weenzeel commented on Jun 16, 2019

    @weenzeel

    Found another case where upper case is tripping up the syntax highlighting:

    class FileMode {
    /// The mode for opening a file only for reading.
    static const read = const FileMode._internal(0);
    @deprecated("Use read instead")
    static const READ = read;
    ...

    In this snippet lower case read is scoped as source.dart but upper case READ is scoped as support.class.

  10. DanTup commented on Jun 17, 2019

    @DanTup
    MemberAuthor

    @weenzeel thanks for the example. It's hard (for me) to fix some of these issues with the textmate grammar. I did hope to try and generate it from the language descriptions (in the hope it'd be accurate, including fixing the comment-highlighting bugs that keep coming up) - see dart-lang/sdk#19298, but so far I haven't found a good way.

  11. weenzeel commented on Jun 17, 2019

    @weenzeel

    @DanTup I opened a syntax issue with Jetbrains and Dart SDK earlier this year. Feedback from Jetbrains was that they depended on the Analysis Server for Dart syntax highlighting. Not sure how that works or viable for VSC as well?

    dart-lang/sdk#35679

  12. DanTup commented on Jun 17, 2019

    @DanTup
    MemberAuthor

    The Dart server provides this info, but VS Code doesn't allow extensions to perform colouring programtically:

    microsoft/vscode#585

    I have seen a workaround someone made that uses the VS Code decorations API to provide the colours - it's an interesting idea, but I haven't dug into how feasible (or reliably) it would be here.

  13. lukepighetti commented on Dec 11, 2019

    @lukepighetti

    tbh if you left it the way it is, i think it's fine. Typescript tooling is unopinionated, but Dart tooling is typically very opinionated. Just my opinion. 😄

  14. 2 remaining items

  15. modified the milestones: Backlog, On Deck on Oct 27, 2020
  16. DanTup commented on Oct 27, 2020

    @DanTup
    MemberAuthor

    This will be handled as part of #2202. It works using the semantic tokens and LSP, but the API hasn't been finalised in LSP so we can't finish/release it yet.

  17. modified the milestones: On Deck, v3.18.0 on Nov 25, 2020
  18. DanTup commented on Dec 15, 2020

    @DanTup
    MemberAuthor

    Fixed by dart-lang/sdk@cb2ede5.

    In order to get the fix you'll need Dart-Code v3.18.0 (a preview release should be available later today/tomorrow), be using LSP Preview, and have a Dart SDK from after yesterday (the most recent nightly works, and of course the next releases of Dart/Flutter SDKs will include this).

    semantic_tokens

  19. DanTup commented on Dec 22, 2020

    @DanTup
    MemberAuthor

    Due to some last minute issues, support for LSP 3.16 (which supports semantic tokens) won't be included in v3.18, but hopefully v3.19 next month instead.

  20. modified the milestones: v3.18.0, v3.19.0 on Dec 22, 2020
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 featuresin lsp/analysis serverSomething to be fixed in the Dart analysis serveris enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions