(meta string, q *sitter.Query, source []byte)
| 27 | } |
| 28 | |
| 29 | func (qe *QueryEngine) run(meta string, q *sitter.Query, source []byte) []Comment { |
| 30 | var comments []Comment |
| 31 | |
| 32 | if meta != "" { |
| 33 | meta = "." + meta |
| 34 | } |
| 35 | |
| 36 | qc := sitter.NewQueryCursor() |
| 37 | qc.Exec(q, qe.tree.RootNode()) |
| 38 | |
| 39 | for { |
| 40 | m, ok := qc.NextMatch() |
| 41 | if !ok { |
| 42 | break |
| 43 | } |
| 44 | |
| 45 | m = qc.FilterPredicates(m, source) |
| 46 | for _, c := range m.Captures { |
| 47 | rText := c.Node.Content(source) |
| 48 | cText := qe.lang.Delims.ReplaceAllString(rText, "") |
| 49 | |
| 50 | scope := "text.comment" + meta + ".line" |
| 51 | if strings.Count(cText, "\n") > 1 { |
| 52 | scope = "text.comment" + meta + ".block" |
| 53 | |
| 54 | // Dedent like Python's inspect.cleandoc: the first line sits on |
| 55 | // (or just after) the opening delimiter, so its leading |
| 56 | // whitespace is incidental and is trimmed fully; the remaining |
| 57 | // lines are dedented only by the indentation common to them. |
| 58 | // This removes a comment's base indentation while preserving |
| 59 | // relative indentation, which is significant for markup such as |
| 60 | // RST literal blocks and Markdown indented code. See #1028. |
| 61 | lines := strings.Split(cText, "\n") |
| 62 | common := commonIndent(lines[1:], qe.cutset) |
| 63 | |
| 64 | buf := bytes.Buffer{} |
| 65 | for i, line := range lines { |
| 66 | if i == 0 { |
| 67 | buf.WriteString(strings.TrimLeft(line, qe.cutset)) |
| 68 | } else { |
| 69 | buf.WriteString(stripIndent(line, common, qe.cutset)) |
| 70 | } |
| 71 | buf.WriteString("\n") |
| 72 | } |
| 73 | |
| 74 | cText = buf.String() |
| 75 | } |
| 76 | |
| 77 | comments = append(comments, Comment{ |
| 78 | Line: int(c.Node.StartPoint().Row) + 1, |
| 79 | Offset: int(c.Node.StartPoint().Column), |
| 80 | Scope: scope, |
| 81 | Text: cText, |
| 82 | Source: rText, |
| 83 | }) |
| 84 | } |
| 85 | } |
| 86 |
no test coverage detected