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

Function is_directive

codegraph-kernel/src/docstring.rs:251–262  ·  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

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`).
251fn 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.

Callers 1

preceding_docstring_withFunction · 0.85

Calls 1

getMethod · 0.65

Tested by

no test coverage detected