| 5042 | } JSDocParam; |
| 5043 | |
| 5044 | static void parse_jsdoc_block(TSLSPContext *ctx, const char *text, size_t len, |
| 5045 | JSDocParam *out_params, int *out_param_count, int max_params, |
| 5046 | const CBMType **out_return) { |
| 5047 | *out_return = NULL; |
| 5048 | *out_param_count = 0; |
| 5049 | if (!text || len == 0) |
| 5050 | return; |
| 5051 | |
| 5052 | const char *end = text + len; |
| 5053 | const char *p = text; |
| 5054 | while (p < end) { |
| 5055 | // Find next `@` that introduces a tag. |
| 5056 | while (p < end && *p != '@') |
| 5057 | p++; |
| 5058 | if (p >= end) |
| 5059 | return; |
| 5060 | p++; // skip @ |
| 5061 | |
| 5062 | // Match "param" or "returns"/"return". |
| 5063 | const char *tag_start = p; |
| 5064 | while (p < end && (*p >= 'a' && *p <= 'z')) |
| 5065 | p++; |
| 5066 | size_t tag_len = (size_t)(p - tag_start); |
| 5067 | bool is_param = (tag_len == 5 && memcmp(tag_start, "param", 5) == 0); |
| 5068 | bool is_return = ((tag_len == 7 && memcmp(tag_start, "returns", 7) == 0) || |
| 5069 | (tag_len == 6 && memcmp(tag_start, "return", 6) == 0)); |
| 5070 | if (!is_param && !is_return) |
| 5071 | continue; |
| 5072 | |
| 5073 | // Skip whitespace. |
| 5074 | while (p < end && (*p == ' ' || *p == '\t')) |
| 5075 | p++; |
| 5076 | if (p >= end || *p != '{') |
| 5077 | continue; |
| 5078 | p++; // skip { |
| 5079 | const char *type_start = p; |
| 5080 | int depth = 1; |
| 5081 | while (p < end && depth > 0) { |
| 5082 | if (*p == '{') |
| 5083 | depth++; |
| 5084 | else if (*p == '}') |
| 5085 | depth--; |
| 5086 | if (depth > 0) |
| 5087 | p++; |
| 5088 | } |
| 5089 | if (p >= end || *p != '}') |
| 5090 | continue; |
| 5091 | size_t type_len = (size_t)(p - type_start); |
| 5092 | char *type_text = cbm_arena_strndup(ctx->arena, type_start, type_len); |
| 5093 | const CBMType *parsed = parse_ts_type_text(ctx->arena, type_text, ctx->module_qn); |
| 5094 | p++; // skip } |
| 5095 | |
| 5096 | if (is_return) { |
| 5097 | *out_return = parsed; |
| 5098 | continue; |
| 5099 | } |
| 5100 | |
| 5101 | // Param: skip whitespace then read name. |
no test coverage detected