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

Method extract_decorators_for

codegraph-kernel/src/tsjs/extractors.rs:2053–2077  ·  view source on GitHub ↗
(&mut self, decl: Node<'t>, decorated_row: u32)

Source from the content-addressed store, hash-verified

2051 // --- extractDecoratorsFor --------------------------------------------------------------
2052
2053 pub(super) fn extract_decorators_for(&mut self, decl: Node<'t>, decorated_row: u32) {
2054 // 1. Direct children (method/property style).
2055 for child in decl.named_children(&mut decl.walk()) {
2056 self.consider_decorator(child, decorated_row);
2057 if child.kind() == "modifiers" {
2058 for m in child.named_children(&mut child.walk()) {
2059 self.consider_decorator(m, decorated_row);
2060 }
2061 }
2062 }
2063 // 2. Preceding siblings (TypeScript class style), stopping at the
2064 // first non-decorator so an earlier declaration's decorators never
2065 // leak in. Matching by startIndex, not object identity.
2066 // Walked back from the declaration itself. Finding its place first, by counting the
2067 // parent's children from the start, cost each declaration as much as it has
2068 // siblings before it: a file of twenty thousand took minutes.
2069 let mut sibling = decl.prev_named_sibling();
2070 while let Some(sib) = sibling {
2071 if !matches!(sib.kind(), "decorator" | "annotation" | "marker_annotation") {
2072 break;
2073 }
2074 self.consider_decorator(sib, decorated_row);
2075 sibling = sib.prev_named_sibling();
2076 }
2077 }
2078
2079 fn consider_decorator(&mut self, n: Node<'t>, decorated_row: u32) {
2080 if !matches!(n.kind(), "decorator" | "annotation" | "marker_annotation" | "attribute") {

Callers 5

extract_functionMethod · 0.45
extract_classMethod · 0.45
extract_methodMethod · 0.45
extract_propertyMethod · 0.45

Calls 2

walkMethod · 0.45
consider_decoratorMethod · 0.45

Tested by

no test coverage detected