MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / docstring_from_preceding_comments

Function docstring_from_preceding_comments

src/extraction/common.rs:77–104  ·  view source on GitHub ↗
(
    source: &[u8],
    node: TsNode<'_>,
    clean: fn(&str) -> String,
)

Source from the content-addressed store, hash-verified

75/// preceding `node`, cleaning each comment with `clean`.
76#[allow(dead_code)]
77pub(crate) fn docstring_from_preceding_comments(
78 source: &[u8],
79 node: TsNode<'_>,
80 clean: fn(&str) -> String,
81) -> Option<String> {
82 let mut comments = Vec::new();
83 let mut current = node.prev_named_sibling();
84 while let Some(sibling) = current {
85 if sibling.kind() == "comment" {
86 comments.push(node_text(source, sibling));
87 current = sibling.prev_named_sibling();
88 } else {
89 break;
90 }
91 }
92 if comments.is_empty() {
93 return None;
94 }
95 // Comments are collected in reverse order (closest first).
96 comments.reverse();
97 let cleaned: Vec<String> = comments.iter().map(|c| clean(c)).collect();
98 let result = cleaned.join("\n").trim().to_string();
99 if result.is_empty() {
100 None
101 } else {
102 Some(result)
103 }
104}
105
106/// Extract a docstring from the run of `#` comment siblings immediately
107/// preceding `node`.

Callers 7

extract_docstringMethod · 0.85
extract_docstringMethod · 0.85
extract_docstringMethod · 0.85
extract_docstringMethod · 0.85
extract_docstringMethod · 0.85
extract_docstringMethod · 0.85

Calls 5

node_textFunction · 0.85
kindMethod · 0.80
pushMethod · 0.80
collectMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected