Dart-Code / Dart-Code

Dart and Flutter support for VS Code
https://dartcode.org/
MIT License
1.47k stars 299 forks source link

Syntax Highlighting for `TODO:` and `ignore:` Comments #4963

Open Number-3434 opened 6 months ago

Number-3434 commented 6 months ago

Proposal

Please add syntax highlighting for TODO, FIXME, HACK, UNDONE, ignore:, and ignore_for_file: comments.

These could then be coloured, increasing clarity, as some users may be unaware that a particular comment actually has some sort of function to it.

[!NOTE] Ideally, both TextMate grammars and semantic highlighting should be used.


Comments

TODO Comments

For TODO comments, according to flutter_style_todos and the Flutter Style Guide:

The examples below demonstrate the different parts to highlight in a TODO comment:

// TODO: message // TODO([github]-username): message // TODO([github]-username): message, [github]-URL-to-issue

Other Comments

For other comments, there are only four parts:

// HACK: message // FIXME: message // UNDONE: message

ignore: and ignore_for_file:

The examples below demonstrate the different grammars in a ignore: or ignore_for_file: comment:

// [ignore]: [some_lint] // [ignore]: [some_lint], [REASON](https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#comment-all--ignores) // [ignore_for_file]: [some_lint] // [ignore_for_file]: [some_lint], [REASON](https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#comment-all--ignores) // [ignore]: [some_lint_1], [some_lint_2] // [ignore_for_file]: [some_lint_1], [some_lint_2]

Tasklist

DanTup commented 6 months ago

It's difficult to provide default colouring for custom things like this because we don't know what colours themes will use. It could be useful to add Semantic Token modifiers to those regions though (allowing them to be customised in VS Code settings). I don't know if the semantic tokens code currently has access to the TODO regions though (as they usually produce diagnostics and are not part of the AST).

Number-3434 commented 6 months ago

Okay, thanks! Sorry, I meant just to provide the textmate grammars, not necessarily colouring.

Number-3434 commented 6 months ago

Would it be necessary to use semantic highlighting?

Hopefully this could just use basic syntax highlighting?

DanTup commented 6 months ago

VS Code only supports using either the TextMate grammar or Semantic Tokens. Implementing this only in the TextMate grammar means any highlighting would appear when you open a file and then quickly disappear when replaced with semantic tokens colouring.

I don't know how many themes support Semantic Tokens, but the default VS Code ones I use do, so I suspect this would be the majority of users.

I'd like to try and have the two highlights converge over time, so I don't think we should add anything to the grammar before semantic tokens have the same support.

sprabhdeep commented 2 months ago

This implementation will be helpful.