@var Type $name — bind a variable in current scope. * Generic types like `array ` may contain whitespace-free `<>` — we * tolerate those by including '<' and '>' in the type token. */
| 761 | * Generic types like `array<User>` may contain whitespace-free `<>` — we |
| 762 | * tolerate those by including '<' and '>' in the type token. */ |
| 763 | static void bind_phpdoc_var(PHPLSPContext *ctx, const char *docstring) { |
| 764 | if (!docstring || !ctx->current_scope) |
| 765 | return; |
| 766 | const char *p = docstring; |
| 767 | while ((p = strstr(p, "@var")) != NULL) { |
| 768 | p += 4; |
| 769 | while (*p == ' ' || *p == '\t') |
| 770 | p++; |
| 771 | const char *type_start = p; |
| 772 | /* Take a type token: stop at whitespace or '$' (start of var name). |
| 773 | * Allow '<', '>', ',', '|', '?' inside the type. */ |
| 774 | int depth = 0; |
| 775 | while (*p && *p != '\n') { |
| 776 | if (*p == '<') |
| 777 | depth++; |
| 778 | else if (*p == '>') |
| 779 | depth--; |
| 780 | else if (depth == 0 && (*p == ' ' || *p == '\t' || *p == '$')) |
| 781 | break; |
| 782 | p++; |
| 783 | } |
| 784 | if (p == type_start) |
| 785 | continue; |
| 786 | char *type_text = cbm_arena_strndup(ctx->arena, type_start, (size_t)(p - type_start)); |
| 787 | while (*p == ' ' || *p == '\t') |
| 788 | p++; |
| 789 | if (*p != '$') |
| 790 | continue; |
| 791 | p++; |
| 792 | const char *name_start = p; |
| 793 | while (*p && (isalnum((unsigned char)*p) || *p == '_')) |
| 794 | p++; |
| 795 | if (p == name_start) |
| 796 | continue; |
| 797 | char *vname = cbm_arena_strndup(ctx->arena, name_start, (size_t)(p - name_start)); |
| 798 | const CBMType *t = resolve_phpdoc_type(ctx, type_text); |
| 799 | if (vname && t && t->kind != CBM_TYPE_UNKNOWN) { |
| 800 | cbm_scope_bind(ctx->current_scope, vname, t); |
| 801 | } |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | /* Walk siblings backwards from `node` to find a leading PHPDoc comment |
| 806 | * ("/**...*/"). Returns cleaned doc text or NULL. */ |
no test coverage detected