MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / fetch_leading_phpdoc

Function fetch_leading_phpdoc

internal/cbm/lsp/php_lsp.c:807–841  ·  view source on GitHub ↗

Walk siblings backwards from `node` to find a leading PHPDoc comment * ("/**...*​/"). Returns cleaned doc text or NULL. */

Source from the content-addressed store, hash-verified

805/* Walk siblings backwards from `node` to find a leading PHPDoc comment
806 * ("/**...*​/"). Returns cleaned doc text or NULL. */
807static char *fetch_leading_phpdoc(PHPLSPContext *ctx, TSNode node) {
808 TSNode parent = ts_node_parent(node);
809 if (ts_node_is_null(parent))
810 return NULL;
811 uint32_t nc = ts_node_child_count(parent);
812 /* Find index of node within parent. */
813 int idx = -1;
814 for (uint32_t i = 0; i < nc; i++) {
815 TSNode c = ts_node_child(parent, i);
816 if (ts_node_eq(c, node)) {
817 idx = (int)i;
818 break;
819 }
820 }
821 if (idx <= 0)
822 return NULL;
823 for (int i = idx - 1; i >= 0; i--) {
824 TSNode c = ts_node_child(parent, (uint32_t)i);
825 if (ts_node_is_null(c))
826 continue;
827 const char *k = ts_node_type(c);
828 if (strcmp(k, "comment") == 0) {
829 char *raw = php_node_text(ctx, c);
830 if (raw && raw[0] == '/' && raw[1] == '*' && raw[2] == '*') {
831 return phpdoc_clean(ctx->arena, raw);
832 }
833 return NULL;
834 }
835 /* Skip whitespace-only or attributes; stop at any other node. */
836 if (strcmp(k, "attribute_list") == 0 || strcmp(k, "attribute_group") == 0)
837 continue;
838 return NULL;
839 }
840 return NULL;
841}
842
843/* PHP 8.1 first-class callable syntax reuses call-expression nodes but its
844 * argument list contains only a `variadic_placeholder`: `target(...)`,

Callers 2

process_function_likeFunction · 0.85
process_class_for_fieldsFunction · 0.85

Calls 2

php_node_textFunction · 0.85
phpdoc_cleanFunction · 0.85

Tested by

no test coverage detected