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

Method extract_docstring

src/extraction/php_extractor.rs:1050–1081  ·  view source on GitHub ↗

Extract PHP doc comments (`/** ... */`) preceding a node. Looks for a preceding sibling or leading `comment` node with `/**` prefix.

(state: &ExtractionState, node: TsNode<'_>)

Source from the content-addressed store, hash-verified

1048 ///
1049 /// Looks for a preceding sibling or leading `comment` node with `/**` prefix.
1050 fn extract_docstring(state: &ExtractionState, node: TsNode<'_>) -> Option<String> {
1051 // Walk previous named siblings to find a doc comment immediately before this node.
1052 let parent = node.parent()?;
1053 let mut cursor = parent.walk();
1054 let mut last_comment: Option<String> = None;
1055
1056 if cursor.goto_first_child() {
1057 loop {
1058 let child = cursor.node();
1059 if child.id() == node.id() {
1060 // Return the last comment seen immediately before this node.
1061 return last_comment;
1062 }
1063 if child.kind() == "comment" {
1064 let text = state.node_text(child);
1065 if text.trim_start().starts_with("/**") {
1066 last_comment = Some(Self::strip_doc_comment(&text));
1067 } else {
1068 // Non-doc comment resets the docstring candidate.
1069 last_comment = None;
1070 }
1071 } else if !child.is_extra() {
1072 // Any non-comment, non-whitespace node resets the candidate.
1073 last_comment = None;
1074 }
1075 if !cursor.goto_next_sibling() {
1076 break;
1077 }
1078 }
1079 }
1080 None
1081 }
1082
1083 /// Strip `/** ... */` markers from a PHP doc comment.
1084 fn strip_doc_comment(text: &str) -> String {

Callers

nothing calls this directly

Calls 3

kindMethod · 0.80
idMethod · 0.45
node_textMethod · 0.45

Tested by

no test coverage detected