tsnode.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. ---@meta
  2. -- luacheck: no unused args
  3. error('Cannot require a meta file')
  4. --- @brief A "treesitter node" represents one specific element of the parsed contents of a buffer,
  5. --- which can be captured by a |Query| for, e.g., highlighting. It is a |userdata| reference to an
  6. --- object held by the treesitter library.
  7. ---
  8. --- An instance `TSNode` of a treesitter node supports the following methods.
  9. ---@nodoc
  10. ---@class TSNode: userdata
  11. ---@field named_children fun(self: TSNode): TSNode[]
  12. ---@field __has_ancestor fun(self: TSNode, node_types: string[]): boolean
  13. local TSNode = {} -- luacheck: no unused
  14. --- Get the node's immediate parent.
  15. --- Prefer |TSNode:child_with_descendant()|
  16. --- for iterating over the node's ancestors.
  17. --- @return TSNode?
  18. function TSNode:parent() end
  19. --- Get the node's next sibling.
  20. --- @return TSNode?
  21. function TSNode:next_sibling() end
  22. --- Get the node's previous sibling.
  23. --- @return TSNode?
  24. function TSNode:prev_sibling() end
  25. --- Get the node's next named sibling.
  26. --- @return TSNode?
  27. function TSNode:next_named_sibling() end
  28. --- Get the node's previous named sibling.
  29. --- @return TSNode?
  30. function TSNode:prev_named_sibling() end
  31. --- Iterates over all the direct children of {TSNode}, regardless of whether
  32. --- they are named or not.
  33. --- Returns the child node plus the eventual field name corresponding to this
  34. --- child node.
  35. --- @return fun(): TSNode, string
  36. function TSNode:iter_children() end
  37. --- Returns a table of the nodes corresponding to the {name} field.
  38. --- @param name string
  39. --- @return TSNode[]
  40. function TSNode:field(name) end
  41. --- Get the node's number of children.
  42. --- @return integer
  43. function TSNode:child_count() end
  44. --- Get the node's child at the given {index}, where zero represents the first
  45. --- child.
  46. --- @param index integer
  47. --- @return TSNode?
  48. function TSNode:child(index) end
  49. --- Get the node's number of named children.
  50. --- @return integer
  51. function TSNode:named_child_count() end
  52. --- Get the node's named child at the given {index}, where zero represents the
  53. --- first named child.
  54. --- @param index integer
  55. --- @return TSNode?
  56. function TSNode:named_child(index) end
  57. --- Get the node's child that contains {descendant}.
  58. --- @param descendant TSNode
  59. --- @return TSNode?
  60. --- @deprecated
  61. function TSNode:child_containing_descendant(descendant) end
  62. --- Get the node's child that contains {descendant} (includes {descendant}).
  63. ---
  64. --- For example, with the following node hierarchy:
  65. ---
  66. --- ```
  67. --- a -> b -> c
  68. ---
  69. --- a:child_with_descendant(c) == b
  70. --- a:child_with_descendant(b) == b
  71. --- a:child_with_descendant(a) == nil
  72. --- ```
  73. --- @param descendant TSNode
  74. --- @return TSNode?
  75. function TSNode:child_with_descendant(descendant) end
  76. --- Get the node's start position. Return three values: the row, column and
  77. --- total byte count (all zero-based).
  78. --- @return integer, integer, integer
  79. function TSNode:start() end
  80. --- Get the node's end position. Return three values: the row, column and
  81. --- total byte count (all zero-based).
  82. --- @return integer, integer, integer
  83. function TSNode:end_() end
  84. --- Get the range of the node.
  85. ---
  86. --- Return four or six values:
  87. ---
  88. --- - start row
  89. --- - start column
  90. --- - start byte (if {include_bytes} is `true`)
  91. --- - end row
  92. --- - end column
  93. --- - end byte (if {include_bytes} is `true`)
  94. --- @param include_bytes boolean?
  95. function TSNode:range(include_bytes) end
  96. --- @nodoc
  97. --- @param include_bytes false?
  98. --- @return integer, integer, integer, integer
  99. function TSNode:range(include_bytes) end
  100. --- @nodoc
  101. --- @param include_bytes true
  102. --- @return integer, integer, integer, integer, integer, integer
  103. function TSNode:range(include_bytes) end
  104. --- Get the node's type as a string.
  105. --- @return string
  106. function TSNode:type() end
  107. --- Get the node's type as a numerical id.
  108. --- @return integer
  109. function TSNode:symbol() end
  110. --- Check if the node is named. Named nodes correspond to named rules in the
  111. --- grammar, whereas anonymous nodes correspond to string literals in the
  112. --- grammar.
  113. --- @return boolean
  114. function TSNode:named() end
  115. --- Check if the node is missing. Missing nodes are inserted by the parser in
  116. --- order to recover from certain kinds of syntax errors.
  117. --- @return boolean
  118. function TSNode:missing() end
  119. --- Check if the node is extra. Extra nodes represent things like comments,
  120. --- which are not required by the grammar but can appear anywhere.
  121. --- @return boolean
  122. function TSNode:extra() end
  123. --- Check if a syntax node has been edited.
  124. --- @return boolean
  125. function TSNode:has_changes() end
  126. --- Check if the node is a syntax error or contains any syntax errors.
  127. --- @return boolean
  128. function TSNode:has_error() end
  129. --- Get an S-expression representing the node as a string.
  130. --- @return string
  131. function TSNode:sexpr() end
  132. --- Get a unique identifier for the node inside its own tree.
  133. ---
  134. --- No guarantees are made about this identifier's internal representation,
  135. --- except for being a primitive Lua type with value equality (so not a
  136. --- table). Presently it is a (non-printable) string.
  137. ---
  138. --- Note: The `id` is not guaranteed to be unique for nodes from different
  139. --- trees.
  140. --- @return string
  141. function TSNode:id() end
  142. --- Get the |TSTree| of the node.
  143. --- @return TSTree
  144. function TSNode:tree() end
  145. --- Get the smallest node within this node that spans the given range of (row,
  146. --- column) positions
  147. --- @param start_row integer
  148. --- @param start_col integer
  149. --- @param end_row integer
  150. --- @param end_col integer
  151. --- @return TSNode?
  152. function TSNode:descendant_for_range(start_row, start_col, end_row, end_col) end
  153. --- Get the smallest named node within this node that spans the given range of
  154. --- (row, column) positions
  155. --- @param start_row integer
  156. --- @param start_col integer
  157. --- @param end_row integer
  158. --- @param end_col integer
  159. --- @return TSNode?
  160. function TSNode:named_descendant_for_range(start_row, start_col, end_row, end_col) end
  161. --- Check if {node} refers to the same node within the same tree.
  162. --- @param node TSNode
  163. --- @return boolean
  164. function TSNode:equal(node) end
  165. --- Return the number of bytes spanned by this node.
  166. --- @return integer
  167. function TSNode:byte_length() end