@@ -80,8 +80,10 @@ type Input struct {
80
80
Encoding InputEncoding
81
81
}
82
82
83
- var ErrOperationLimit = errors .New ("operation limit was hit" )
84
- var ErrNoLanguage = errors .New ("cannot parse without language" )
83
+ var (
84
+ ErrOperationLimit = errors .New ("operation limit was hit" )
85
+ ErrNoLanguage = errors .New ("cannot parse without language" )
86
+ )
85
87
86
88
// Parse produces new Tree from content using old tree
87
89
//
@@ -217,6 +219,9 @@ func (p *Parser) Debug() {
217
219
}
218
220
219
221
// Close should be called to ensure that all the memory used by the parse is freed.
222
+ //
223
+ // As the constructor in go-tree-sitter would set this func call through runtime.SetFinalizer,
224
+ // parser.Close() will be called by Go's garbage collector and users would not have to call this manually.
220
225
func (p * Parser ) Close () {
221
226
if ! p .isClosed {
222
227
C .ts_parser_delete (p .c )
@@ -296,6 +301,9 @@ func (t *Tree) cachedNode(ptr C.TSNode) *Node {
296
301
}
297
302
298
303
// Close should be called to ensure that all the memory used by the tree is freed.
304
+ //
305
+ // As the constructor in go-tree-sitter would set this func call through runtime.SetFinalizer,
306
+ // parser.Close() will be called by Go's garbage collector and users would not have to call this manually.
299
307
func (t * BaseTree ) Close () {
300
308
if ! t .isClosed {
301
309
C .ts_tree_delete (t .c )
@@ -523,7 +531,7 @@ func (n Node) ChildByFieldName(name string) *Node {
523
531
524
532
// FieldNameForChild returns the field name of the child at the given index, or "" if not named.
525
533
func (n Node ) FieldNameForChild (idx int ) string {
526
- return C .GoString (C .ts_node_field_name_for_child (n .c , C .uint32_t (idx )))
534
+ return C .GoString (C .ts_node_field_name_for_child (n .c , C .uint32_t (idx )))
527
535
}
528
536
529
537
// NextSibling returns the node's next sibling.
@@ -597,6 +605,9 @@ func NewTreeCursor(n *Node) *TreeCursor {
597
605
598
606
// Close should be called to ensure that all the memory used by the tree cursor
599
607
// is freed.
608
+ //
609
+ // As the constructor in go-tree-sitter would set this func call through runtime.SetFinalizer,
610
+ // parser.Close() will be called by Go's garbage collector and users would not have to call this manually.
600
611
func (c * TreeCursor ) Close () {
601
612
if ! c .isClosed {
602
613
C .ts_tree_cursor_delete (c .c )
@@ -732,6 +743,9 @@ func NewQuery(pattern []byte, lang *Language) (*Query, error) {
732
743
}
733
744
734
745
// Close should be called to ensure that all the memory used by the query is freed.
746
+ //
747
+ // As the constructor in go-tree-sitter would set this func call through runtime.SetFinalizer,
748
+ // parser.Close() will be called by Go's garbage collector and users would not have to call this manually.
735
749
func (q * Query ) Close () {
736
750
if ! q .isClosed {
737
751
C .ts_query_delete (q .c )
@@ -834,8 +848,10 @@ func (qc *QueryCursor) SetPointRange(startPoint Point, endPoint Point) {
834
848
C .ts_query_cursor_set_point_range (qc .c , cStartPoint , cEndPoint )
835
849
}
836
850
837
- // Close should be called to ensure that all the memory used by the query
838
- // cursor is freed.
851
+ // Close should be called to ensure that all the memory used by the query cursor is freed.
852
+ //
853
+ // As the constructor in go-tree-sitter would set this func call through runtime.SetFinalizer,
854
+ // parser.Close() will be called by Go's garbage collector and users would not have to call this manually.
839
855
func (qc * QueryCursor ) Close () {
840
856
if ! qc .isClosed {
841
857
C .ts_query_cursor_delete (qc .c )
0 commit comments