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

Method extract_decorators_for

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

Source from the content-addressed store, hash-verified

1898 // --- extractDecoratorsFor --------------------------------------------------------------
1899
1900 pub(super) fn extract_decorators_for(&mut self, decl: Node<'t>, decorated_row: u32) {
1901 // 1. Direct children (method/property style).
1902 for i in 0..decl.named_child_count() {
1903 let Some(child) = decl.named_child(i) else { continue };
1904 self.consider_decorator(child, decorated_row);
1905 if child.kind() == "modifiers" {
1906 for j in 0..child.named_child_count() {
1907 if let Some(m) = child.named_child(j) {
1908 self.consider_decorator(m, decorated_row);
1909 }
1910 }
1911 }
1912 }
1913 // 2. Preceding siblings (TypeScript class style), stopping at the
1914 // first non-decorator so an earlier declaration's decorators never
1915 // leak in. Matching by startIndex, not object identity.
1916 let Some(parent) = decl.parent() else { return };
1917 let decl_start = decl.start_byte();
1918 let mut decl_idx: isize = -1;
1919 for i in 0..parent.named_child_count() {
1920 if let Some(sib) = parent.named_child(i) {
1921 if sib.start_byte() == decl_start {
1922 decl_idx = i as isize;
1923 break;
1924 }
1925 }
1926 }
1927 if decl_idx > 0 {
1928 let mut j = decl_idx - 1;
1929 while j >= 0 {
1930 let Some(sib) = parent.named_child(j as usize) else {
1931 j -= 1;
1932 continue;
1933 };
1934 if !matches!(sib.kind(), "decorator" | "annotation" | "marker_annotation") {
1935 break;
1936 }
1937 self.consider_decorator(sib, decorated_row);
1938 j -= 1;
1939 }
1940 }
1941 }
1942
1943 fn consider_decorator(&mut self, n: Node<'t>, decorated_row: u32) {
1944 if !matches!(n.kind(), "decorator" | "annotation" | "marker_annotation" | "attribute") {

Callers 4

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

Calls 1

consider_decoratorMethod · 0.45

Tested by

no test coverage detected