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

Method declaration_wrapper

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

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