isDirective (tree-sitter-helpers.ts) — a comment directive Go tools read, which go doc leaves out of a doc comment's text (go/ast's isDirective): a `//` comment with no space after the slashes that is `//line `, `//extern ` or `//export ` followed by text, or that opens with a lowercase word, a colon and a lowercase letter or digit (`//go:embed x`, `//nolint:errcheck`).
(comment: &str)
| 249 | /// or `//export ` followed by text, or that opens with a lowercase word, a |
| 250 | /// colon and a lowercase letter or digit (`//go:embed x`, `//nolint:errcheck`). |
| 251 | fn is_directive(comment: &str) -> bool { |
| 252 | let Some(text) = comment.strip_prefix("//") else { |
| 253 | return false; |
| 254 | }; |
| 255 | if text.starts_with("line ") || text.starts_with("extern ") || text.starts_with("export ") { |
| 256 | return true; |
| 257 | } |
| 258 | let word_char = |b: &u8| b.is_ascii_lowercase() || b.is_ascii_digit(); |
| 259 | let bytes = text.as_bytes(); |
| 260 | let word = bytes.iter().take_while(|b| word_char(b)).count(); |
| 261 | word > 0 && bytes.get(word) == Some(&b':') && bytes.get(word + 1).is_some_and(word_char) |
| 262 | } |
| 263 | |
| 264 | /// followsCodeOnItsLine (tree-sitter-helpers.ts) — whether code comes before |
| 265 | /// `node` on the line it starts on. |
no test coverage detected