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