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

Function preceding_docstring_with

codegraph-kernel/src/docstring.rs:165–244  ·  view source on GitHub ↗
(
    node: Node,
    src: &str,
    step_over: &[&str],
    skip_trailing: bool,
    skip_detached: bool,
    skip_directives: bool,
)

Source from the content-addressed store, hash-verified

163}
164
165fn preceding_docstring_with(
166 node: Node,
167 src: &str,
168 step_over: &[&str],
169 skip_trailing: bool,
170 skip_detached: bool,
171 skip_directives: bool,
172) -> Option<String> {
173 let mut anchor = node;
174 while let Some(parent) = anchor.parent() {
175 if is_wrapper(parent.kind()) {
176 anchor = parent;
177 } else {
178 break;
179 }
180 }
181
182 let mut comments: Vec<Node> = Vec::new();
183 let mut sibling = anchor.prev_named_sibling();
184 while let Some(s) = sibling {
185 if is_comment(s.kind()) {
186 comments.push(s);
187 sibling = s.prev_named_sibling();
188 } else if step_over.contains(&s.kind()) {
189 sibling = s.prev_named_sibling();
190 } else {
191 break;
192 }
193 }
194 comments.reverse(); // collected nearest-first; TS unshifts to keep source order
195
196 let mut first = 0;
197 if skip_trailing {
198 let mut end_row = 0;
199 for c in &comments {
200 let trails = if first == 0 {
201 follows_code_on_its_line(*c, src)
202 } else {
203 c.start_position().row == end_row
204 };
205 if !trails {
206 break;
207 }
208 end_row = c.end_position().row;
209 first += 1;
210 }
211 }
212 if skip_detached {
213 // Walk back from the declaration: the last comment must end on the
214 // line above it, and each one before joins while it ends on the line
215 // the next one starts, or the line before that.
216 let mut start = comments.len();
217 if start > first && comments[start - 1].end_position().row + 1 == anchor.start_position().row {
218 start -= 1;
219 while start > first
220 && comments[start - 1].end_position().row + 1 >= comments[start].start_position().row
221 {
222 start -= 1;

Calls 10

is_wrapperFunction · 0.85
follows_code_on_its_lineFunction · 0.85
is_directiveFunction · 0.85
clean_comment_markersFunction · 0.85
pushMethod · 0.80
lenMethod · 0.80
mapMethod · 0.80
is_commentFunction · 0.70
collectMethod · 0.45
joinMethod · 0.45