| 3919 | } |
| 3920 | |
| 3921 | static void process_class_for_fields(PHPLSPContext *ctx, CBMTypeRegistry *reg, TSNode class_node, |
| 3922 | php_class_field_table_t *tab) { |
| 3923 | const char *cqn = class_qn_for_node(ctx, class_node); |
| 3924 | if (!cqn) |
| 3925 | return; |
| 3926 | php_class_fields_t *f = fields_for(tab, cqn, ctx->arena); |
| 3927 | if (!f) |
| 3928 | return; |
| 3929 | |
| 3930 | /* PHPDoc on the class itself: @property + @method tags. */ |
| 3931 | char *class_doc = fetch_leading_phpdoc(ctx, class_node); |
| 3932 | if (class_doc) { |
| 3933 | apply_phpdoc_class_tags(ctx, reg, cqn, class_doc, f); |
| 3934 | } |
| 3935 | |
| 3936 | /* Belt-and-suspenders: walk the class declaration's `base_clause` and |
| 3937 | * `class_interface_clause` to gather extends/implements QNs and append |
| 3938 | * them to the registered type's embedded_types. The unified extractor |
| 3939 | * is supposed to populate base_classes for class_declaration but |
| 3940 | * may miss interface_declaration's `extends Base` chain or use a |
| 3941 | * raw form (with backslashes) that doesn't round-trip cleanly. |
| 3942 | * Doing this AST extraction here keeps the LSP self-sufficient. */ |
| 3943 | { |
| 3944 | const char *parent_qns[16]; |
| 3945 | int parent_count = 0; |
| 3946 | uint32_t cnc = ts_node_child_count(class_node); |
| 3947 | for (uint32_t i = 0; i < cnc && parent_count < 16; i++) { |
| 3948 | TSNode c = ts_node_child(class_node, i); |
| 3949 | if (ts_node_is_null(c) || !ts_node_is_named(c)) |
| 3950 | continue; |
| 3951 | const char *k = ts_node_type(c); |
| 3952 | if (strcmp(k, "base_clause") != 0 && strcmp(k, "class_interface_clause") != 0) { |
| 3953 | continue; |
| 3954 | } |
| 3955 | uint32_t bnc = ts_node_child_count(c); |
| 3956 | for (uint32_t j = 0; j < bnc && parent_count < 16; j++) { |
| 3957 | TSNode bc = ts_node_child(c, j); |
| 3958 | if (ts_node_is_null(bc) || !ts_node_is_named(bc)) |
| 3959 | continue; |
| 3960 | const char *bk = ts_node_type(bc); |
| 3961 | if (strcmp(bk, "name") != 0 && strcmp(bk, "qualified_name") != 0) |
| 3962 | continue; |
| 3963 | char *t = php_node_text(ctx, bc); |
| 3964 | if (!t) |
| 3965 | continue; |
| 3966 | const char *resolved = php_resolve_class_name(ctx, t); |
| 3967 | if (!resolved) |
| 3968 | continue; |
| 3969 | parent_qns[parent_count++] = resolved; |
| 3970 | } |
| 3971 | } |
| 3972 | if (parent_count > 0) { |
| 3973 | for (int t = 0; t < reg->type_count; t++) { |
| 3974 | if (strcmp(reg->types[t].qualified_name, cqn) != 0) |
| 3975 | continue; |
| 3976 | /* Merge with existing embedded_types — dedup. */ |
| 3977 | int existing = 0; |
| 3978 | if (reg->types[t].embedded_types) { |
no test coverage detected