Skip to content

TextMate grammar doesn't handle unclosed triple-backtick code blocks in doc comments #6130

Closed

Description

@DanTup

Originally filed at dart-lang/sdk#63802, but it's from the textmate grammar not the semantic tokens:

/// Test
/// ```
/// this
/// 
void main() {}

Activity

  1. added this to the v3.140.0 milestone on Jul 27, 2026
  2. changed the title [-]Semantic tokens for code block doesn't stop at the end of comment[/-] [+]TextMate grammar doesn't handle unclosed triple-backtick code blocks in doc comments[/+] on Jul 27, 2026
  3. self-assigned this
    on Jul 27, 2026
  4. DanTup commented on Jul 27, 2026

    @DanTup
    MemberAuthor

    Oddly, this seems to only occur in some very specific cases.

    /// Text
    /// ```
    /// code
    ///
    int? x1;
    
    /// ```
    /// code
    ///
    int? x2;
    
    /// Text
    /// ```
    /// code
    int? x3;
    
    /// ```
    /// code
    int? x4;
    

    Here, only the first example seems to be left broken (it's the only one where the ? shows as blue because it's still in code mode):

    Image
    >/// Text
    #^^^ source.dart comment.block.documentation.dart
    #   ^^^^^^ source.dart comment.block.documentation.dart
    >/// ```
    #^^^^^^^ source.dart comment.block.documentation.dart
    >/// code
    #^^^^ source.dart comment.block.documentation.dart
    #    ^^^^ source.dart comment.block.documentation.dart variable.other.source.dart
    >///
    #^^^^ source.dart comment.block.documentation.dart
    >int? x1;
    #^^^^^^^^ source.dart comment.block.documentation.dart variable.other.source.dart
    >
    >/// ```
    #^^^ source.dart comment.block.documentation.dart
    #   ^^^^^ source.dart comment.block.documentation.dart
    >/// code
    #^^^^^^^^^ source.dart comment.block.documentation.dart
    >///
    #^^^^ source.dart comment.block.documentation.dart
    >int? x2;
    #^^^ source.dart support.class.dart
    #   ^ source.dart keyword.operator.ternary.dart
    #    ^^^ source.dart
    #       ^ source.dart punctuation.terminator.dart
    >
    >/// Text
    #^^^ source.dart comment.block.documentation.dart
    #   ^^^^^^ source.dart comment.block.documentation.dart
    >/// ```
    #^^^^^^^ source.dart comment.block.documentation.dart
    >/// code
    #^^^^ source.dart comment.block.documentation.dart
    #    ^^^^ source.dart comment.block.documentation.dart variable.other.source.dart
    >int? x3;
    #^^^ source.dart support.class.dart
    #   ^ source.dart keyword.operator.ternary.dart
    #    ^^^ source.dart
    #       ^ source.dart punctuation.terminator.dart
    >
    >/// ```
    #^^^ source.dart comment.block.documentation.dart
    #   ^^^^^ source.dart comment.block.documentation.dart
    >/// code
    #^^^^^^^^^ source.dart comment.block.documentation.dart
    >int? x4;
    #^^^ source.dart support.class.dart
    #   ^ source.dart keyword.operator.ternary.dart
    #    ^^^ source.dart
    #       ^ source.dart punctuation.terminator.dart
    >
    

    Fortunately TextMate grammars are easy to debug 😂

  5. DanTup commented on Jul 28, 2026

    @DanTup
    MemberAuthor

    I've a PR open that fixes this at #6132, however because the grammar is owned in another repo, and the parser used for the tests in that repo is owned in another repo, I'm going to wait to get all those PRs done before landing this one. Those PRs are linked in #6132

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

Metadata

Metadata

Assignees

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