tree-sitter / tree-sitter-rust

Rust grammar for tree-sitter
MIT License
350 stars 98 forks source link

bug: Doc-comments are not parsed correctly #236

Closed nfejzic closed 1 month ago

nfejzic commented 1 month ago

Did you check existing issues?

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

No response

Describe the bug

The latest release (0.23) broke the parsing of doc-comments. Here's an example of how it looks like right now:

image

It should look like the following (as in release 0.21.2):

image

I don't know the specific commit that broke this. However, the issue is present from commit 7de6a3bc1ba213424c137f134d2872975b3b7fbe forwards.

I'm using neovim (v0.10.0) with nvim-treesitter plugin.

Here's the tree of the wrongly parsed part:

(source_file ; [0, 0] - [7, 0]
  (line_comment ; [0, 0] - [1, 0]
    outer: (outer_doc_comment_marker) ; [0, 2] - [0, 3]
    doc: (doc_comment)) ; [0, 3] - [1, 0]
  (function_item ; [1, 0] - [3, 1]
    name: (identifier) ; [1, 3] - [1, 7]
    parameters: (parameters) ; [1, 7] - [1, 9]
    body: (block ; [1, 10] - [3, 1]
      (line_comment ; [2, 4] - [3, 0]
        inner: (inner_doc_comment_marker) ; [2, 6] - [2, 7]
        doc: (doc_comment))))) ; [2, 7] - [3, 0]

Steps To Reproduce/Bad Parse Tree

  1. Open a Rust file.
  2. Find (or create) a doc comment
  3. The /// and //! symbols of doc comments are parsed wrong, with third character parsed as operator (I think?)

Expected Behavior/Parse Tree

The /// symbol should be parsed as one symbol.

Repro

/// This is a doc comment
fn main() {
    //! this is inside function comment
}
mawkler commented 1 month ago

Came here since I'm having the same issue

amaanq commented 1 month ago

Highlights are implementation-dependent and are not controlled here. The parse tree is correct, this is the parser repo.

nfejzic commented 1 month ago

@amaanq Thank you for the info 🙏🏻