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

Method declaration_wrapper

codegraph-kernel/src/go.rs:393–403  ·  view source on GitHub ↗

goExtractor.getDeclarationWrapper: a type declared on its own, `type Foo struct{…}`, is a `type_declaration` holding one spec, and its doc comment comes before the declaration, outside the spec. A member of a `type ( … )` group has its comment beside it, and the comment above the group is the group's. A group of one is that type's declaration, as go doc reads it, unless its member has a comment of

(&self, node: Node<'t>)

Source from the content-addressed store, hash-verified

391 /// group is the group's. A group of one is that type's declaration, as go
392 /// doc reads it, unless its member has a comment of its own.
393 fn declaration_wrapper(&self, node: Node<'t>) -> Option<Node<'t>> {
394 let parent = node.parent()?;
395 if parent.kind() != "type_declaration" || parent.named_child(0)? != node {
396 return None;
397 }
398 let specs = (0..parent.named_child_count())
399 .filter_map(|i| parent.named_child(i))
400 .filter(|c| matches!(c.kind(), "type_spec" | "type_alias"))
401 .count();
402 (specs == 1).then_some(parent)
403 }
404
405 /// docstringFor (tree-sitter.ts) — the preceding comment run, looked up
406 /// from the declaration wrapper when there is one, without the comments

Callers 1

docstring_ofMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected