MCPcopy Create free account
hub / github.com/BishopFox/jsluice / QueryMulti

Method QueryMulti

tree.go:428–465  ·  view source on GitHub ↗

QueryMulti executes a tree-sitter query on a specific Node. Nodes captured by the query are grouped into a QueryResult and passed to the provided callback function. See https://tree-sitter.github.io/tree-sitter/using-parsers#pattern-matching-with-queries for query syntax documentation.

(query string, fn func(QueryResult))

Source from the content-addressed store, hash-verified

426// See https://tree-sitter.github.io/tree-sitter/using-parsers#pattern-matching-with-queries
427// for query syntax documentation.
428func (n *Node) QueryMulti(query string, fn func(QueryResult)) {
429 if !n.IsValid() {
430 return
431 }
432 q, err := sitter.NewQuery(
433 []byte(query),
434 javascript.GetLanguage(),
435 )
436 if err != nil {
437 return
438 }
439
440 qc := sitter.NewQueryCursor()
441 defer qc.Close()
442
443 qc.Exec(q, n.node)
444
445 for {
446 match, exists := qc.NextMatch()
447 if !exists || match == nil {
448 break
449 }
450
451 match = qc.FilterPredicates(match, n.source)
452
453 qr := NewQueryResult()
454
455 for _, capture := range match.Captures {
456 node := NewNode(capture.Node, n.source)
457 node.captureName = q.CaptureNameForId(capture.Index)
458 qr.Add(node)
459 }
460 if len(qr) == 0 {
461 continue
462 }
463 fn(qr)
464 }
465}
466
467// IsStringy returns true if a Node is a string
468// or is an expression starting with a string

Callers 1

QueryMethod · 0.95

Calls 4

IsValidMethod · 0.95
AddMethod · 0.95
NewQueryResultFunction · 0.85
NewNodeFunction · 0.85

Tested by

no test coverage detected