Skip to content

Provide offset/lengths for nodes #1287

Open

Description

@DanTup

There are some places in the analysis server that could benefit from parsing Markdown. For example Dart-Code/Dart-Code#3330 relates to code blocks no longer being highlighted in VS Code when Semantic Tokens are enabled (Semantic Tokens replace the old regex-based colouring, but the server doesn't produce highlights regions for the code blocks nested inside markdown).

Parsing the comments using this library produces code elements for the things I'd like to highlight, but it appears the offset/length are not provided on the nodes so it's not possible to produce a highlight region for that code.

If this seems like a reasonable extension, I'm happy to have a go at implementing it if someone is happy to provide pointers and/or reviews. Thanks!

Activity

  1. srawlins commented on May 17, 2021

    @srawlins
    Member

    This is in the works. I hope to land it this quarter (in the next 6 weeks). It involves a huge refactoring of how markdown is parsed; currently there is no Markdown source parse tree; only an output HTML AST.

  2. DanTup commented on May 17, 2021

    @DanTup
    ContributorAuthor

    Neat! I did wonder if the current AST might cause issues for non-HTML uses, so this sounds ideal. Thanks!

  3. frmatthew commented on Aug 13, 2021

    @frmatthew

    Any update on this issue? Thanks.

  4. srawlins commented on Aug 19, 2021

    @srawlins
    Member

    My teammate and I with whom I planned to work on this had a lot of non-overlapping vacation this summer, so I didn't get to land anything in June as I hoped. My new target is end of September. 🤞

  5. DanTup commented on Jan 18, 2022

    @DanTup
    ContributorAuthor

    @srawlins out of interest, is this still on your radar?

  6. srawlins commented on Jan 18, 2022

    @srawlins
    Member

    Oof, it is, but it keeps getting bumped by other slightly higher priority projects. :/ I should not announce a new target date.

  7. DanTup commented on Jan 18, 2022

    @DanTup
    ContributorAuthor

    lol, I know the feeling. It's not urgent to me, it's just useful to know if it may be on the way in the near-term or not :-) Thanks!

  8. crkit-chan commented on Jan 5, 2024

    @crkit-chan

    2024 - Any updates yet?

    Concerning Issue #3648 - Comment References

    I would really appreciate this, since this is the reason that documentation comment references cannot be parsed.

    Since this is a pretty big bug, I think this issue deserves more attention.

    For me, it is one of the only problems with the otherwise nearly-perfect Dart extension for VSCode.

    Note

    This works in JavaScript, maybe something could be copied over from that?

  9. srawlins commented on Jan 5, 2024

    @srawlins
    Member

    2024 - No updates.

    I would appreciate it as well. Sorry, it has not made it to the top of our priorities.

  10. FMorschel commented on Aug 17, 2026

    @FMorschel
    Contributor

    I opened #2530 that adds offset/length tracking to inline code spans (`code`), addressing this issue for that case. It's intentionally missing some cases and not a complete fix for every node/context, yet:

    Offsets are populated for code spans in top-level paragraphs and atx headers — the common cases for things like dartdoc comments.

    Offsets are still null for code spans nested inside constructs that rebuild Line content from a stripped source line — currently blockquotes, list items, footnote definitions, and GitHub alert blocks. For example:

    A blockquote code span.

    The span itself still renders correctly (blockquotes/lists fully support inline markdown); only the position metadata is missing there. This isn't a correctness bug — ContentOffsetMapper.map() deliberately returns null rather than a guessed/wrong offset whenever a contributing Line doesn't carry a known source offset.

    This is because block syntaxes like BlockquoteSyntax, *ListSyntax, FootnoteDefSyntax, and AlertBlockSyntax construct new Lines from a marker-stripped substring (e.g. Line(currentLine.content.substring(markerEnd))) without passing along the corresponding source offset. Each of these syntaxes already knows how many characters it stripped, so propagating offset: currentLine.offset == null ? null : currentLine.offset! + markerEnd (adjusted per syntax) would fix this.

    I've decided to land the paragraph/header case first and follow up with nested-block offset propagation separately, since it touches several block syntaxes and I think it might be easier to review these changes separately.

    Also, keep in mind that the block-level code is already handled (see dart-lang/sdk#63739 and related issues for more info).

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions