claytonrcarter/tree-sitter-phpdoc

Linebreaks in description not handled properly

Closed this issue · 2 comments

If a description for @param, @property or @return spans mutliple lines the * (and preceeding spaces) on the next line become part of the @description text:

ts_phpdoc_desc_linebreak

Well, the * is included in the description node, but it's correctly excluded from the enclosed text nodes. Here's the ts parse output for your example; note that each description spans 2 lines (ie 1-2, 3-4, 5-6) and includes 2 separate text nodes, the second of which starts after the * (ie at char posn 3). I'm inclined to call this behavior correct.

❯ cat foo.phpdoc
/**
 * @param int $x some value
 * continued on next line
 * @property int $x some value
 * continued on next line
 * @return int some value
 * continued on next line
 */

❯ ./node_modules/.bin/tree-sitter parse foo.phpdoc --scope comment.block.documentation.phpdoc.php
(document [0, 0] - [8, 0]
  (tag [1, 3] - [2, 25]
    (tag_name [1, 3] - [1, 9])
    (type_list [1, 10] - [1, 13]
      (primitive_type [1, 10] - [1, 13]))
    (variable_name [1, 14] - [1, 16]
      (name [1, 15] - [1, 16]))
    (description [1, 17] - [2, 25]
      (text [1, 17] - [1, 27])
      (text [2, 3] - [2, 25])))
  (tag [3, 3] - [4, 25]
    (tag_name [3, 3] - [3, 12])
    (type_list [3, 13] - [3, 16]
      (primitive_type [3, 13] - [3, 16]))
    (variable_name [3, 17] - [3, 19]
      (name [3, 18] - [3, 19]))
    (description [3, 20] - [4, 25]
      (text [3, 20] - [3, 30])
      (text [4, 3] - [4, 25])))
  (tag [5, 3] - [6, 25]
    (tag_name [5, 3] - [5, 10])
    (type_list [5, 11] - [5, 14]
      (primitive_type [5, 11] - [5, 14]))
    (description [5, 15] - [6, 25]
      (text [5, 15] - [5, 25])
      (text [6, 3] - [6, 25]))))

Ah, you're right. I've updated my query to use (tag (description (text) @text)) instead of (tag (description) @text). Now it works as expected.