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

Method declaration_wrapper

codegraph-kernel/src/go.rs:391–401  ·  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

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