MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / is_directive

Function is_directive

codegraph-kernel/src/docstring.rs:259–270  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

257/// or `//export ` followed by text, or that opens with a lowercase word, a
258/// colon and a lowercase letter or digit (`//go:embed x`, `//nolint:errcheck`).
259fn is_directive(comment: &str) -> bool {
260 let Some(text) = comment.strip_prefix("//") else {
261 return false;
262 };
263 if text.starts_with("line ") || text.starts_with("extern ") || text.starts_with("export ") {
264 return true;
265 }
266 let word_char = |b: &u8| b.is_ascii_lowercase() || b.is_ascii_digit();
267 let bytes = text.as_bytes();
268 let word = bytes.iter().take_while(|b| word_char(b)).count();
269 word > 0 && bytes.get(word) == Some(&b':') && bytes.get(word + 1).is_some_and(word_char)
270}
271
272/// followsCodeOnItsLine (tree-sitter-helpers.ts) — whether code comes before
273/// `node` on the line it starts on.

Callers 1

preceding_docstring_withFunction · 0.85

Calls 1

getMethod · 0.65

Tested by

no test coverage detected