Skip to content

Incorrect comment highlighting with recent update #1573

Closed

Description

@kankaristo

I use the following method to quickly and easily comment out code blocks:

/*/
code();
// */

Adding a single * on the first line uncomments the code block, so you can toggle the code block with a single character:

/**/
code();
// */

You can also toggle between 2 different code blocks with a single character, if you add * to the first line here:

/*/
code("A");
/*/
code("B");
// */

The same works in all languages that use /* */ for multiline comments (the C "family", JavaScript, JSON with comments, and a similar thing even works in Lua). Dart is a bit weird in that it requires the space in // */ or the code will fail to compile, but that's a "bug" in Dart, not in this package.


However, a recent change in this package (maybe related to #1498) breaks syntax highlighting.

The last line (// */) seems to be treated as a one line comment, and the end of the multiline comment is ignored, so the rest of the file is highlighted as a comment:
Screenshot from 2019-04-02 10-54-19

If there's a later */ (not part of another comment), the comment highlighting stops there, but it's (correctly) marked as a syntax error:
Screenshot from 2019-04-02 10-55-04

The same bug also occurs with a simple /* // */ (the rest of the file is highlighted as a comment):
Screenshot from 2019-04-02 11-00-19

This is a relatively recent change, I remember the highlighting working correctly about a week ago (but of course, that may depend on when I updated this package).

Activity

  1. kankaristo commented on Apr 2, 2019

    @kankaristo
    Author

    Temporary fix is to install this package, which provides Dart syntax highlighting only (works together with this package, but doesn't have the same bug):
    https://marketplace.visualstudio.com/items?itemName=oscarcs.dart-syntax-highlighting-only

  2. DanTup commented on Apr 2, 2019

    @DanTup
    Member

    Yikes! Thanks for the report. This is very likely related to the issue you linked or #1554 (which shipped on Friday). I'll do some digging.

    FWIW, VS Code has shortcuts for quickly commenting out blocks of code that might be easier than this (though it doesn't change that this needs fixing).

  3. added this to the v2.26.0 milestone on Apr 2, 2019
  4. kankaristo commented on Apr 2, 2019

    @kankaristo
    Author

    FWIW, VS Code has shortcuts for quickly commenting out blocks of code that might be easier than this (though it doesn't change that this needs fixing).

    I know, but this is "universal" (works in any editor, lots of different languages, etc.), and also nice because it allows you to "toggle" between 2 different code blocks. :)

    And I also consider this to be easier/faster, since it's just one character to comment/uncomment the block, instead of highlighting the code block and pressing a keyboard shortcut. At least it's easier once you have the "scaffolding comments" around the code block, before that, maybe not.

    But like you said, this should be fixed regardless, since even a simple /* // */ also breaks highlighting.

  5. added a commit that references this issue on Apr 2, 2019
    8190c76
  6. DanTup commented on Apr 2, 2019

    @DanTup
    Member

    Yeah, that makes sense if it's always the same block (though the selection can handle many).

    Here's the impact of the change I just made. I've saved this file in the repo now to make it easier to evaluate these in future (it's a bit of a game of whack-a-mole - I haven't found an official syntax for the language that is maintained with language changes).

    If there's anything other combinations of things you think worth adding, do let me know or (feel free to edit the file in a PR).

    comments

    @devoncarew FYI - one of my previous changes to support nested comments resulted in allowing line comments inside block comments, which resulted in the end-of-block-comment marker being ignored if it was on the same line.

  7. added a commit that references this issue on Apr 4, 2019
    13784a7
  8. devoncarew commented on Apr 4, 2019

    @devoncarew
    Contributor

    Thanks! I opened dart-atom/dart#1189.

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