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

Function preceding_docstring_with

codegraph-kernel/src/docstring.rs:173–252  ·  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

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