LCOV - code coverage report
Current view: top level - ext - lsp_internal.h (source / functions) Coverage Total Hit
Test: Extension code coverage Lines: 90.0 % 211 190
Test Date: 2026-07-13 00:58:38 Functions: 100.0 % 31 31

            Line data    Source code
       1              : /*
       2              :   +----------------------------------------------------------------------+
       3              :   | LSParrot PHP LSP Extension                                           |
       4              :   +----------------------------------------------------------------------+
       5              :   | Copyright (c) LSParrot GitHub Organization                           |
       6              :   +----------------------------------------------------------------------+
       7              :   | This source file is subject to the 0BSD license that is              |
       8              :   | bundled with this package in the file LICENSE.                       |
       9              :   +----------------------------------------------------------------------+
      10              :   | Author: Go Kudo <zeriyoshi@gmail.com>                                |
      11              :   +----------------------------------------------------------------------+
      12              : */
      13              : 
      14              : #ifndef LSP_INTERNAL_H
      15              : # define LSP_INTERNAL_H
      16              : 
      17              : # include "lsp_portability.h"
      18              : 
      19              : # include <Zend/zend_compile.h>
      20              : # include <Zend/zend_exceptions.h>
      21              : # include <Zend/zend_smart_str.h>
      22              : # include <Zend/zend_stream.h>
      23              : # include <Zend/zend_virtual_cwd.h>
      24              : 
      25              : # include <ext/json/php_json.h>
      26              : 
      27              : # include "php_lsparrot.h"
      28              : 
      29              : # define LSP_SYMBOL_INDEX_MAGIC 0x5a534958u
      30              : # define LSP_SYMBOL_INDEX_PAYLOAD_VERSION 1u
      31              : # define LSP_SYMBOL_CLASS 'C'
      32              : # define LSP_SYMBOL_INTERFACE 'I'
      33              : # define LSP_SYMBOL_TRAIT 'T'
      34              : # define LSP_SYMBOL_ENUM 'E'
      35              : # define LSP_SYMBOL_FUNCTION 'F'
      36              : # define LSP_SYMBOL_CONSTANT 'N'
      37              : # define LSP_SYMBOL_TOMBSTONE '!'
      38              : # define LSP_ANALYZER_PROJECT_PENDING 1
      39              : # define LSP_ANALYZER_PROJECT_RUNNING 2
      40              : # define LSP_ANALYZER_PROJECT_READY 3
      41              : # define LSP_ANALYZER_PROJECT_ERROR 4
      42              : 
      43              : typedef struct _php_ver_abstract {
      44              :         const char *(*ast_kind_name)(zend_ast_kind kind);
      45              :         bool (*ast_is_decl)(zend_ast *ast);
      46              :         bool (*ast_is_opaque_node)(zend_ast_kind kind);
      47              :         bool (*string_equals_cstr)(zend_string *value, const char *literal, size_t length);
      48              : } php_ver_abstract_t;
      49              : 
      50              : extern php_ver_abstract_t php_ver_abstract;
      51              : 
      52              : /* Hot array/token accessors are header inlines so the strlen() over literal
      53              :  * keys constant-folds and no cross-object call is paid on the request paths. */
      54       643905 : static inline zval *lsp_array_find(zval *array, const char *key)
      55              : {
      56       643905 :         if (!array || Z_TYPE_P(array) != IS_ARRAY) {
      57            0 :                 return NULL;
      58              :         }
      59              : 
      60       643905 :         return zend_hash_str_find(Z_ARRVAL_P(array), key, strlen(key));
      61              : }
      62              : 
      63       538041 : static inline zend_string *lsp_array_string(zval *array, const char *key)
      64              : {
      65       538041 :         zval *value = lsp_array_find(array, key);
      66              : 
      67       538041 :         return value && Z_TYPE_P(value) == IS_STRING ? Z_STR_P(value) : NULL;
      68              : }
      69              : 
      70        90272 : static inline zend_long lsp_array_long(zval *array, const char *key, zend_long fallback)
      71              : {
      72        90272 :         zval *value = lsp_array_find(array, key);
      73              : 
      74        90272 :         return value && Z_TYPE_P(value) == IS_LONG ? Z_LVAL_P(value) : fallback;
      75              : }
      76              : 
      77       516128 : static inline zend_string *lsp_token_string(zval *token, const char *key)
      78              : {
      79       516128 :         return token && Z_TYPE_P(token) == IS_ARRAY ? lsp_array_string(token, key) : NULL;
      80              : }
      81              : 
      82        84956 : static inline zend_long lsp_token_long(zval *token, const char *key, zend_long fallback)
      83              : {
      84        84956 :         return token && Z_TYPE_P(token) == IS_ARRAY ? lsp_array_long(token, key, fallback) : fallback;
      85              : }
      86              : 
      87       446152 : static inline bool lsp_token_name_equals(zval *token, const char *name)
      88              : {
      89       446152 :         zend_string *token_name = lsp_token_string(token, "name");
      90              : 
      91       446152 :         return token_name && php_ver_abstract.string_equals_cstr(token_name, name, strlen(name));
      92              : }
      93              : 
      94            8 : static inline bool lsp_token_text_equals(zval *token, const char *text)
      95              : {
      96            8 :         zend_string *token_text = lsp_token_string(token, "text");
      97              : 
      98            8 :         return token_text && php_ver_abstract.string_equals_cstr(token_text, text, strlen(text));
      99              : }
     100              : 
     101              : typedef struct _lsp_document {
     102              :         zend_string *uri;
     103              :         zend_string *path;
     104              :         zend_string *text;
     105              :         zend_long version;
     106              :         zval lsparrot;
     107              :         /* Derived snapshot data computed lazily once per text revision so request
     108              :          * handlers never re-tokenize or re-compile the document per candidate. */
     109              :         zend_string *derived_namespace;
     110              :         HashTable *derived_imports;
     111              :         size_t derived_import_insert_offset;
     112              :         bool derived_import_after_use;
     113              :         bool derived_valid;
     114              :         /* documentSymbol outline memoized per text revision: editors poll the
     115              :          * outline continuously (breadcrumbs, sticky scroll), and the token walk
     116              :          * costs ~20ms on large files. */
     117              :         zval outline_cache;
     118              :         zend_string *outline_cache_text;
     119              : } lsp_document;
     120              : 
     121              : typedef struct _lsp_dir {
     122              :         php_stream *stream;
     123              :         php_stream_dirent entry;
     124              : } lsp_dir;
     125              : 
     126              : typedef enum _lsp_method_visibility {
     127              :         LSP_METHOD_VISIBILITY_PUBLIC = 0,
     128              :         LSP_METHOD_VISIBILITY_PROTECTED,
     129              :         LSP_METHOD_VISIBILITY_PRIVATE
     130              : } lsp_method_visibility;
     131              : 
     132              : typedef enum _lsp_psalm_transport {
     133              :         LSP_PSALM_TRANSPORT_AUTO = 0,
     134              :         LSP_PSALM_TRANSPORT_CLI,
     135              :         LSP_PSALM_TRANSPORT_LANGUAGE_SERVER
     136              : } lsp_psalm_transport;
     137              : 
     138              : typedef enum _lsp_indent_style {
     139              :         LSP_INDENT_STYLE_CLIENT = 0,
     140              :         LSP_INDENT_STYLE_SPACE = 1,
     141              :         LSP_INDENT_STYLE_TAB = 2,
     142              : } lsp_indent_style;
     143              : 
     144              : typedef struct _lsp_options {
     145              :         size_t symbol_index_size;
     146              :         zend_long worker_count;
     147              :         zend_long phpstan_level;
     148              :         zend_long psalm_level;
     149              :         bool formatting_enabled;
     150              :         bool formatting_reindent;
     151              :         bool formatting_trim_trailing_whitespace;
     152              :         bool formatting_insert_final_newline;
     153              :         lsp_indent_style formatting_indent_style;
     154              :         zend_long formatting_indent_size;
     155              :         double analyzer_diagnostics_timeout;
     156              :         double analyzer_type_query_timeout;
     157              :         bool analyzer_auto;
     158              :         bool analyzer_phpstan;
     159              :         bool analyzer_psalm;
     160              :         bool analyzer_psalm_ls;
     161              :         lsp_psalm_transport psalm_transport;
     162              :         bool psalm_on_change;
     163              :         bool psalm_enable_autocomplete;
     164              :         bool psalm_enable_diagnostics;
     165              :         bool psalm_enable_hover;
     166              :         bool psalm_enable_definition;
     167              :         bool psalm_enable_signature_help;
     168              :         bool psalm_show_info;
     169              :         bool psalm_live_dead_code_diagnostics;
     170              :         bool psalm_in_memory;
     171              :         zend_long psalm_on_change_debounce_ms;
     172              :         zend_long psalm_max_response_wait_ms;
     173              :         zend_string *memory_limit;
     174              :         zend_string **worker_php_args;
     175              :         uint32_t worker_php_arg_count;
     176              : } lsp_options;
     177              : 
     178              : typedef struct _lsp_symbol_index_header {
     179              :         uint32_t magic;
     180              :         uint32_t reserved;
     181              :         uint64_t generation;
     182              :         size_t capacity;
     183              :         size_t used;
     184              :         uint32_t symbol_count;
     185              :         uint32_t flags;
     186              : } lsp_symbol_index_header;
     187              : 
     188              : # define LSP_SYMBOL_ENTRY_VENDOR (1u << 0)
     189              : # define LSP_SYMBOL_ENTRY_DELETED (1u << 1)
     190              : 
     191              : typedef struct _lsp_symbol_entry {
     192              :         uint32_t record_offset;
     193              :         uint32_t fqcn_length;
     194              :         uint32_t path_length;
     195              :         uint8_t kind;
     196              :         uint8_t flags;
     197              : } lsp_symbol_entry;
     198              : 
     199              : typedef struct _lsp_symbol_segment {
     200              :         uint32_t entry_index;
     201              :         uint32_t segment_offset;
     202              : } lsp_symbol_segment;
     203              : 
     204              : typedef struct _lsp_symbol_index {
     205              :         size_t size;
     206              :         void *addr;
     207              :         bool available;
     208              :         bool keys_initialized;
     209              :         HashTable symbol_keys;
     210              :         /* Derived lookup tables rebuilt lazily after the arena changes: a packed
     211              :          * entry table (no strlen on the hot path) and a sorted FQCN-segment array
     212              :          * enabling binary-search prefix completion instead of linear scans. */
     213              :         lsp_symbol_entry *entries;
     214              :         lsp_symbol_segment *segments;
     215              :         uint32_t entry_count;
     216              :         uint32_t segment_count;
     217              :         bool table_valid;
     218              : } lsp_symbol_index;
     219              : 
     220              : typedef struct _lsp_analyzer_job {
     221              :         lsp_process_id pid;
     222              :         zend_string *uri;
     223              :         zend_string *cache_key;
     224              :         zend_string *cache_file;
     225              :         zend_string *project_root;
     226              :         zend_long version;
     227              :         bool running;
     228              : } lsp_analyzer_job;
     229              : 
     230              : typedef struct _lsp_perf_counter {
     231              :         uint64_t count;
     232              :         double total_seconds;
     233              :         double max_seconds;
     234              : } lsp_perf_counter;
     235              : 
     236              : typedef struct _lsp_server {
     237              :         HashTable documents;
     238              :         HashTable member_cache;
     239              :         HashTable completion_cache;
     240              :         HashTable type_cache;
     241              :         HashTable phpstan_projects;
     242              :         HashTable psalm_projects;
     243              :         HashTable psalm_ls_project_states;
     244              :         HashTable psalm_ls_projects;
     245              :         HashTable perf_stats;
     246              :         HashTable runner_sessions;
     247              :         HashTable workspace_roots;
     248              :         zend_string *root;
     249              :         lsp_options options;
     250              :         lsp_symbol_index symbol_index;
     251              :         /* Project-wide diagnostics jobs keyed by project root: independent
     252              :          * Composer projects in a workspace analyze concurrently, bounded by
     253              :          * lsp_analyzer_parallel_workers. */
     254              :         HashTable phpstan_jobs;
     255              :         HashTable psalm_jobs;
     256              :         lsp_analyzer_job phpstan_completion_job;
     257              :         lsp_analyzer_job psalm_completion_job;
     258              :         lsp_process_id index_worker_pid;
     259              :         bool index_worker_running;
     260              :         bool phpstan_enabled;
     261              :         bool psalm_enabled;
     262              :         bool psalm_ls_enabled;
     263              :         bool shutdown;
     264              :         bool saw_shutdown;
     265              :         bool symbol_index_dirty;
     266              : } lsp_server;
     267              : 
     268              : typedef struct _lsp_command {
     269              :         char **argv;
     270              :         uint32_t count;
     271              :         uint32_t capacity;
     272              : } lsp_command;
     273              : 
     274              : typedef struct _lsp_process_pipes {
     275              :         lsp_process_id process;
     276              :         lsp_pipe_handle input;
     277              :         lsp_pipe_handle output;
     278              :         lsp_pipe_handle error;
     279              : } lsp_process_pipes;
     280              : 
     281          216 : static inline void lsp_command_init(lsp_command *command)
     282              : {
     283          216 :         memset(command, 0, sizeof(*command));
     284          216 : }
     285              : 
     286          960 : static inline void lsp_command_add(lsp_command *command, const char *value)
     287              : {
     288          960 :         if (command->count + 1 >= command->capacity) {
     289          216 :                 command->capacity = command->capacity == 0 ? 8 : command->capacity * 2;
     290          216 :                 command->argv = erealloc(command->argv, sizeof(char *) * command->capacity);
     291              :         }
     292              : 
     293          960 :         command->argv[command->count++] = estrdup(value);
     294          960 :         command->argv[command->count] = NULL;
     295          960 : }
     296              : 
     297          876 : static inline void lsp_command_add_zstr(lsp_command *command, zend_string *value)
     298              : {
     299          876 :         if (command->count + 1 >= command->capacity) {
     300          124 :                 command->capacity = command->capacity == 0 ? 8 : command->capacity * 2;
     301          124 :                 command->argv = erealloc(command->argv, sizeof(char *) * command->capacity);
     302              :         }
     303              : 
     304          876 :         command->argv[command->count++] = estrndup(ZSTR_VAL(value), ZSTR_LEN(value));
     305          876 :         command->argv[command->count] = NULL;
     306          876 : }
     307              : 
     308          184 : static inline void lsp_command_destroy(lsp_command *command)
     309              : {
     310              :         uint32_t i;
     311              : 
     312         2020 :         for (i = 0; i < command->count; i++) {
     313         1836 :                 efree(command->argv[i]);
     314              :         }
     315              : 
     316          184 :         if (command->argv) {
     317          184 :                 efree(command->argv);
     318              :         }
     319              : 
     320          184 :         memset(command, 0, sizeof(*command));
     321          184 : }
     322              : 
     323          124 : static inline zend_string *lsp_type_cache_key(const char *analyzer, lsp_document *document, zend_string *expression, size_t offset)
     324              : {
     325              :         /* Deliberately no version/offset: an expression's analyzer type rarely
     326              :          * changes while typing on the same document, and version-scoped keys
     327              :          * meant a fresh analyzer run per keystroke. Entries are evicted on
     328              :          * didSave/didClose instead. */
     329              :         (void) offset;
     330              : 
     331          124 :         return strpprintf(0, "%s:type:%s:%s", analyzer, ZSTR_VAL(document->uri), ZSTR_VAL(expression));
     332              : }
     333              : 
     334          200 : static inline bool lsp_type_is_unhelpful(zend_string *type)
     335              : {
     336          200 :         if (!type || ZSTR_LEN(type) == 0) {
     337           44 :                 return true;
     338              :         }
     339              : 
     340          156 :         if (zend_string_equals_literal_ci(type, "mixed") || zend_string_equals_literal(type, "*ERROR*")) {
     341            0 :                 return true;
     342              :         }
     343              : 
     344          156 :         return false;
     345              : }
     346              : 
     347      1066412 : static inline const char *lsp_skip_global_namespace_prefix(const char *value, size_t *length)
     348              : {
     349      1066412 :         if (*length > 0 && value[0] == '\\') {
     350        40024 :                 (*length)--;
     351              : 
     352        40024 :                 return value + 1;
     353              :         }
     354              : 
     355      1026388 :         return value;
     356              : }
     357              : 
     358          492 : static inline size_t lsp_effective_name_prefix_length(zend_string *prefix)
     359              : {
     360              :         const char *value;
     361              :         size_t length;
     362              : 
     363          492 :         value = ZSTR_VAL(prefix);
     364          492 :         length = ZSTR_LEN(prefix);
     365              : 
     366          492 :         value = lsp_skip_global_namespace_prefix(value, &length);
     367          492 :         if (length > 0 && value[0] == '$') {
     368            0 :                 length--;
     369              :         }
     370              : 
     371          492 :         return length;
     372              : }
     373              : 
     374          700 : static inline bool lsp_completion_detail_has_empty_parameters(zend_string *detail)
     375              : {
     376              :         const char *value;
     377              :         size_t i, j;
     378              : 
     379          700 :         if (!detail) {
     380            0 :                 return false;
     381              :         }
     382              : 
     383          700 :         value = ZSTR_VAL(detail);
     384         9300 :         for (i = 0; i < ZSTR_LEN(detail); i++) {
     385         9300 :                 if (value[i] != '(') {
     386         8600 :                         continue;
     387              :                 }
     388              : 
     389          700 :                 for (j = i + 1; j < ZSTR_LEN(detail); j++) {
     390          700 :                         if (value[j] == ' ' || value[j] == '\t' || value[j] == '\r' || value[j] == '\n') {
     391            0 :                                 continue;
     392              :                         }
     393              : 
     394          700 :                         return value[j] == ')';
     395              :                 }
     396              : 
     397            0 :                 return false;
     398              :         }
     399              : 
     400            0 :         return false;
     401              : }
     402              : 
     403          704 : static inline zend_string *lsp_completion_call_snippet_ex(zend_string *insert_text, bool cursor_after_call)
     404              : {
     405          704 :         smart_str snippet = {0};
     406              :         size_t i;
     407              :         char c;
     408              : 
     409         7940 :         for (i = 0; i < ZSTR_LEN(insert_text); i++) {
     410         7236 :                 c = ZSTR_VAL(insert_text)[i];
     411         7236 :                 if (c == '\\' || c == '$' || c == '}') {
     412           24 :                         smart_str_appendc(&snippet, '\\');
     413              :                 }
     414         7236 :                 smart_str_appendc(&snippet, c);
     415              :         }
     416              : 
     417          704 :         if (cursor_after_call) {
     418          240 :                 smart_str_appendl(&snippet, "()$0", sizeof("()$0") - 1);
     419              :         } else {
     420          464 :                 smart_str_appendl(&snippet, "($0)", sizeof("($0)") - 1);
     421              :         }
     422          704 :         smart_str_0(&snippet);
     423              : 
     424          704 :         return snippet.s;
     425              : }
     426              : 
     427            4 : static inline zend_string *lsp_completion_call_snippet(zend_string *insert_text)
     428              : {
     429            4 :         return lsp_completion_call_snippet_ex(insert_text, false);
     430              : }
     431              : 
     432          700 : static inline zend_string *lsp_completion_call_snippet_for_detail(zend_string *insert_text, zend_string *detail)
     433              : {
     434          700 :         return lsp_completion_call_snippet_ex(insert_text, lsp_completion_detail_has_empty_parameters(detail));
     435              : }
     436              : 
     437        13128 : static inline lsp_dir *lsp_dir_open(zend_string *path)
     438              : {
     439              :         lsp_dir *dir;
     440              :         php_stream *stream;
     441              : 
     442        13128 :         stream = php_stream_opendir(ZSTR_VAL(path), 0, NULL);
     443        13128 :         if (!stream) {
     444          412 :                 return NULL;
     445              :         }
     446              : 
     447        12716 :         dir = emalloc(sizeof(*dir));
     448        12716 :         dir->stream = stream;
     449        12716 :         memset(&dir->entry, 0, sizeof(dir->entry));
     450              : 
     451        12716 :         return dir;
     452              : }
     453              : 
     454       176990 : static inline const char *lsp_dir_read(lsp_dir *dir)
     455              : {
     456              :         php_stream_dirent *entry;
     457              : 
     458       176990 :         entry = php_stream_readdir(dir->stream, &dir->entry);
     459       176990 :         if (!entry) {
     460        12708 :                 return NULL;
     461              :         }
     462              : 
     463       164282 :         return entry->d_name;
     464              : }
     465              : 
     466        12716 : static inline void lsp_dir_close(lsp_dir *dir)
     467              : {
     468        12716 :         if (!dir) {
     469            0 :                 return;
     470              :         }
     471              : 
     472        12716 :         php_stream_closedir(dir->stream);
     473        12716 :         efree(dir);
     474              : }
     475              : 
     476         1488 : static inline bool lsp_zval_string_equals_literal(zval *value, const char *literal)
     477              : {
     478         1488 :         return value &&
     479         2976 :                 Z_TYPE_P(value) == IS_STRING &&
     480         1388 :                 php_ver_abstract.string_equals_cstr(Z_STR_P(value), literal, strlen(literal))
     481              :         ;
     482              : }
     483              : 
     484         3152 : static inline zend_ast *lsp_compile_string_to_ast_silent(zend_string *code, zend_string *uri, zend_arena **ast_arena)
     485              : {
     486              :         zend_ast *ast;
     487              :         bool orig_record_errors;
     488              : 
     489         3152 :         *ast_arena = NULL;
     490         3152 :         orig_record_errors = EG(record_errors);
     491         3152 :         if (!orig_record_errors) {
     492         3152 :                 zend_begin_record_errors();
     493              :         }
     494              : 
     495         3152 :         ast = zend_compile_string_to_ast(code, ast_arena, uri ? uri : ZSTR_EMPTY_ALLOC());
     496         3152 :         if (EG(exception)) {
     497          244 :                 zend_clear_exception();
     498              :         }
     499              : 
     500         3152 :         if (!orig_record_errors) {
     501         3152 :                 EG(record_errors) = false;
     502         3152 :                 zend_free_recorded_errors();
     503              :         }
     504              : 
     505         3152 :         return ast;
     506              : }
     507              : 
     508         2920 : static inline void lsp_compiled_ast_destroy(zend_ast *ast, zend_arena *ast_arena)
     509              : {
     510         2920 :         if (ast) {
     511         2908 :                 zend_ast_destroy(ast);
     512         2908 :                 if (ast_arena) {
     513         2908 :                         zend_arena_destroy(ast_arena);
     514              :                 }
     515              :         }
     516         2920 : }
     517              : 
     518         2616 : static inline zend_string *lsp_ast_string_value(zend_ast *ast)
     519              : {
     520              :         zval *value;
     521              : 
     522         2616 :         if (!ast) {
     523          208 :                 return NULL;
     524              :         }
     525              : 
     526         2408 :         if (ast->kind == ZEND_AST_ZVAL) {
     527         2408 :                 value = zend_ast_get_zval(ast);
     528         2408 :                 if (Z_TYPE_P(value) == IS_STRING) {
     529         2408 :                         return Z_STR_P(value);
     530              :                 }
     531              : 
     532            0 :                 return NULL;
     533              :         }
     534              : 
     535            0 :         if (ast->kind == ZEND_AST_CONSTANT) {
     536            0 :                 return zend_ast_get_constant_name(ast);
     537              :         }
     538              : 
     539            0 :         return NULL;
     540              : }
     541              : 
     542              : void lsp_lsparrot_tokens_to_zval(zval *return_value, zend_string *source);
     543              : bool lsp_doc_is_identifier_char(char c);
     544              : zend_string *lsp_resolve_class_name(zend_string *text, zend_string *type);
     545              : zend_string *lsp_resolve_class_name_at(zend_string *text, zend_string *type, size_t offset);
     546              : zend_string *lsp_document_namespace_at(zend_string *text, size_t offset);
     547              : zend_string *lsp_document_namespace_at_ex(zend_string *text, size_t offset, bool *multiple);
     548              : bool lsp_token_in_bounds(zval *token, size_t start, size_t end);
     549              : bool lsp_token_at_depth(zend_string *text, zval *token, zend_long depth);
     550              : bool lsp_find_first_class_bounds(zend_string *text, size_t *body_start, size_t *body_end, zend_long *body_depth);
     551              : bool lsp_find_class_header_for_name(zend_string *text, zend_string *class_name, size_t *class_start, size_t *body_start, size_t *body_end, zend_long *body_depth);
     552              : 
     553        13216 : static inline bool lsp_keyword_at_slice(const char *value, size_t start, size_t end, const char *keyword, size_t *keyword_end)
     554              : {
     555              :         size_t length;
     556              : 
     557        13216 :         length = strlen(keyword);
     558        13216 :         if (start + length > end || strncasecmp(value + start, keyword, length) != 0) {
     559        12412 :                 return false;
     560              :         }
     561              : 
     562          804 :         if (start > 0 && lsp_doc_is_identifier_char(value[start - 1])) {
     563            0 :                 return false;
     564              :         }
     565              : 
     566          804 :         if (start + length < end && lsp_doc_is_identifier_char(value[start + length])) {
     567            0 :                 return false;
     568              :         }
     569              : 
     570          804 :         *keyword_end = start + length;
     571              : 
     572          804 :         return true;
     573              : }
     574              : 
     575           24 : static inline void lsp_add_resolved_trait_name(zval *traits, zend_string *text, const char *name_start, const char *name_end)
     576              : {
     577              :         zend_string *raw, *resolved;
     578              : 
     579           24 :         if (name_end <= name_start) {
     580            0 :                 return;
     581              :         }
     582              : 
     583           24 :         raw = zend_string_init(name_start, name_end - name_start, 0);
     584           24 :         resolved = lsp_resolve_class_name_at(text, raw, (size_t) (name_start - ZSTR_VAL(text)));
     585           24 :         zend_string_release(raw);
     586           24 :         if (resolved) {
     587           24 :                 add_next_index_str(traits, resolved);
     588              :         }
     589              : }
     590              : 
     591           24 : static inline void lsp_collect_trait_names_from_use_slice(zval *traits, zend_string *text, const char *slice_start, const char *slice_end)
     592              : {
     593              :         const char *p, *name_start, *name_end;
     594              : 
     595           24 :         p = slice_start;
     596           48 :         while (p < slice_end) {
     597           48 :                 while (p < slice_end && (isspace((unsigned char) *p) || *p == ',')) {
     598           24 :                         p++;
     599              :                 }
     600              : 
     601           24 :                 name_start = p;
     602          276 :                 while (p < slice_end && (lsp_doc_is_identifier_char(*p) || *p == '\\')) {
     603          252 :                         p++;
     604              :                 }
     605           24 :                 name_end = p;
     606              : 
     607           24 :                 lsp_add_resolved_trait_name(traits, text, name_start, name_end);
     608              : 
     609           24 :                 while (p < slice_end && *p != ',') {
     610            0 :                         p++;
     611              :                 }
     612              :         }
     613           24 : }
     614              : 
     615              : /* Collects trait names used inside one specific class body. traits must
     616              :  * already be initialized as an array; entries append to it. */
     617          336 : static inline void lsp_collect_class_trait_names_in_bounds(zend_string *text, size_t body_start, size_t body_end, zend_long body_depth, zval *traits)
     618              : {
     619              :         const char *value, *slice_start, *slice_end;
     620              :         zend_long offset;
     621              :         zval tokens_zv, *token;
     622              :         HashTable *tokens;
     623              :         uint32_t i, count;
     624              :         size_t text_length;
     625              : 
     626          336 :         value = ZSTR_VAL(text);
     627          336 :         text_length = ZSTR_LEN(text);
     628          336 :         ZVAL_UNDEF(&tokens_zv);
     629          336 :         lsp_lsparrot_tokens_to_zval(&tokens_zv, text);
     630          336 :         if (Z_TYPE(tokens_zv) != IS_ARRAY) {
     631            0 :                 if (!Z_ISUNDEF(tokens_zv)) {
     632            0 :                         zval_ptr_dtor(&tokens_zv);
     633              :                 }
     634              : 
     635            0 :                 return;
     636              :         }
     637              : 
     638          336 :         tokens = Z_ARRVAL(tokens_zv);
     639          336 :         count = zend_hash_num_elements(tokens);
     640        18756 :         for (i = 0; i < count; i++) {
     641        18420 :                 token = zend_hash_index_find(tokens, i);
     642        36840 :                 if (!token ||
     643        18420 :                         Z_TYPE_P(token) != IS_ARRAY ||
     644        18420 :                         !lsp_token_name_equals(token, "T_USE") ||
     645           96 :                         !lsp_token_in_bounds(token, body_start, body_end) ||
     646           24 :                         !lsp_token_at_depth(text, token, body_depth)
     647              :                 ) {
     648        18396 :                         continue;
     649              :                 }
     650              : 
     651           24 :                 offset = lsp_token_long(token, "offset", 0);
     652           24 :                 if (offset < 0 || (size_t) offset + sizeof("use") - 1 >= text_length) {
     653            0 :                         continue;
     654              :                 }
     655              : 
     656           24 :                 slice_start = value + (size_t) offset + sizeof("use") - 1;
     657           24 :                 slice_end = slice_start;
     658          300 :                 while (slice_end < value + text_length && *slice_end != ';' && *slice_end != '{') {
     659          276 :                         slice_end++;
     660              :                 }
     661           24 :                 lsp_collect_trait_names_from_use_slice(traits, text, slice_start, slice_end);
     662              :         }
     663              : 
     664          336 :         zval_ptr_dtor(&tokens_zv);
     665              : }
     666              : 
     667              : /* Legacy shape: traits of the FIRST class in the file. Prefer the _for /
     668              :  * _in_bounds variants — files can declare several classes. */
     669              : static inline void lsp_collect_class_trait_names(zend_string *text, zval *traits)
     670              : {
     671              :         zend_long body_depth = 0;
     672              :         size_t body_start = 0, body_end = 0;
     673              : 
     674              :         array_init(traits);
     675              :         if (lsp_find_first_class_bounds(text, &body_start, &body_end, &body_depth)) {
     676              :                 lsp_collect_class_trait_names_in_bounds(text, body_start, body_end, body_depth, traits);
     677              :         }
     678              : }
     679              : 
     680              : /* Traits of the class declaring the given (fully qualified) name; falls back
     681              :  * to the first class when the name cannot be matched. */
     682           36 : static inline void lsp_collect_class_trait_names_for(zend_string *text, zend_string *class_name, zval *traits)
     683              : {
     684           36 :         zend_long body_depth = 0;
     685           36 :         size_t class_start = 0, body_start = 0, body_end = 0;
     686              : 
     687           36 :         array_init(traits);
     688           36 :         if (lsp_find_class_header_for_name(text, class_name, &class_start, &body_start, &body_end, &body_depth) ||
     689            0 :                 lsp_find_first_class_bounds(text, &body_start, &body_end, &body_depth)
     690              :         ) {
     691           36 :                 lsp_collect_class_trait_names_in_bounds(text, body_start, body_end, body_depth, traits);
     692              :         }
     693           36 : }
     694              : 
     695              : void lsp_lsparrot_parse_to_zval(zval *return_value, zend_string *code, zend_string *uri);
     696              : void lsp_lsparrot_parse_to_zval_ex(zval *return_value, zend_string *code, zend_string *uri, bool include_tree);
     697              : void lsp_lsparrot_tokens_to_zval(zval *return_value, zend_string *source);
     698              : void lsp_tokens_cache_set_enabled(bool enabled);
     699              : void lsp_server_run(zval *options);
     700              : void lsp_member_cache_invalidate_path(lsp_server *server, zend_string *path);
     701              : 
     702              : void lsp_document_destroy(zval *value);
     703              : void lsp_analyzer_job_clear(lsp_analyzer_job *job);
     704              : void lsp_analyzer_job_destroy(lsp_analyzer_job *job);
     705              : bool lsp_analyzer_jobs_running_for_document(lsp_server *server, lsp_document *document);
     706              : void lsp_reap_analyzer_completion_jobs(void);
     707              : void lsp_psalm_ls_project_destroy(zval *value);
     708              : void lsp_psalm_ls_shutdown_all(lsp_server *server);
     709              : void lsp_psalm_ls_pump(lsp_server *server, double timeout);
     710              : bool lsp_psalm_ls_enabled(lsp_server *server);
     711              : bool lsp_psalm_ls_schedule_project(lsp_server *server, zend_string *project_root);
     712              : void lsp_psalm_ls_document_open(lsp_server *server, lsp_document *document);
     713              : void lsp_psalm_ls_document_change(lsp_server *server, lsp_document *document);
     714              : void lsp_psalm_ls_document_save(lsp_server *server, lsp_document *document);
     715              : void lsp_psalm_ls_document_close(lsp_server *server, zend_string *uri);
     716              : void lsp_psalm_ls_append_diagnostics(lsp_server *server, lsp_document *document, zval *diagnostics);
     717              : bool lsp_psalm_ls_completion_cache_or_schedule(lsp_server *server, zval *items, lsp_document *document, zval *position, size_t offset, zend_string *prefix);
     718              : zend_string *lsp_psalm_ls_type_for_position(lsp_server *server, lsp_document *document, zval *position, size_t offset, zend_string *word);
     719              : zend_string *lsp_psalm_ls_type_for_position_async(lsp_server *server, lsp_document *document, zval *position, size_t offset, zend_string *word);
     720              : uint32_t lsp_active_process_count(lsp_server *server);
     721              : zend_string *lsp_uri_to_path(zend_string *uri);
     722              : zend_string *lsp_uri_from_path(zend_string *path);
     723              : zend_string *lsp_read_file(zend_string *path);
     724              : void lsp_options_from_zval(lsp_options *options, zval *value);
     725              : void lsp_options_destroy(lsp_options *options);
     726              : void lsp_position_from_zval(zval *position, zend_long *line, zend_long *character);
     727              : size_t lsp_offset_at(zend_string *text, zend_long line, zend_long character);
     728              : size_t lsp_utf16_units_to_byte_offset(const char *value, size_t line_start, size_t length, zend_long character);
     729              : zend_long lsp_byte_offset_to_utf16_units(const char *value, size_t line_start, size_t end_offset);
     730              : zend_string *lsp_prefix_at(zend_string *text, size_t offset);
     731              : zend_string *lsp_word_at(zend_string *text, size_t offset);
     732              : bool lsp_matches_prefix_string(zend_string *label, zend_string *prefix);
     733              : bool lsp_matches_prefix_literal(const char *label, zend_string *prefix);
     734              : bool lsp_is_member_access_completion(zend_string *text, size_t offset, zend_string *prefix);
     735              : 
     736              : void lsp_symbol_index_init(lsp_symbol_index *region, lsp_options *options);
     737              : void lsp_symbol_index_destroy(lsp_symbol_index *region);
     738              : void lsp_symbol_index_reset(lsp_symbol_index *region);
     739              : bool lsp_symbol_index_add_symbol_kind(lsp_symbol_index *region, char kind, zend_string *fqcn, zend_string *path);
     740              : const char *lsp_basename_from_fqcn(const char *fqcn, size_t length, size_t *label_length);
     741              : bool lsp_token_is_class_like(zval *token);
     742              : zend_string *lsp_next_string_token(HashTable *tokens, uint32_t start);
     743              : zend_string *lsp_next_function_name_token(HashTable *tokens, uint32_t start);
     744              : zval *lsp_next_function_name_token_ex(HashTable *tokens, uint32_t start, uint32_t *index);
     745              : void lsp_add_completion_item_ex(zval *items, zend_string *label, zend_long kind, zend_string *detail, const char *source);
     746              : void lsp_add_variable_completion_item_ex(zval *items, zend_string *label, zend_string *detail, const char *source, zend_string *text, size_t start_offset, size_t end_offset);
     747              : void lsp_add_completion_item(zval *items, zend_string *label, zend_long kind, zend_string *detail);
     748              : void lsp_add_completion_item_qualified(zval *items, zend_string *label, zend_long kind, zend_string *detail, zend_string *namespace_name);
     749              : void lsp_add_keyword_completion(zval *items, const char *keyword, zend_string *prefix);
     750              : void lsp_deduplicate_completion_items(zval *items);
     751              : bool lsp_completion_attach_items(zval *return_value, zval *items);
     752              : zend_long lsp_symbol_workspace_kind(char kind);
     753              : void lsp_range_from_offsets(zend_string *text, size_t start_offset, size_t end_offset, zval *range);
     754              : bool lsp_path_value_contains_vendor(const char *path, size_t path_length);
     755              : zend_string *lsp_document_namespace(zend_string *text);
     756              : bool lsp_symbol_in_current_namespace(zend_string *current_namespace, char kind, const char *fqcn, size_t fqcn_length);
     757              : bool lsp_document_has_import(zend_string *text, char kind, const char *fqcn);
     758              : size_t lsp_import_insert_offset(zend_string *text, bool *after_existing_use);
     759              : zend_string *lsp_symbol_import_text(char kind, const char *fqcn, bool compact);
     760              : void lsp_add_class_like_symbol_completion_item(zval *items, lsp_document *document, size_t offset, zend_string *prefix, char kind, zend_string *fqcn);
     761              : void lsp_add_project_symbol_completions(lsp_server *server, zval *items, lsp_document *document, size_t offset, zend_string *prefix);
     762              : void lsp_add_project_class_like_completions(lsp_server *server, zval *items, lsp_document *document, size_t offset, zend_string *prefix);
     763              : void lsp_add_project_symbol_kind_completions(lsp_server *server, zval *items, lsp_document *document, size_t offset, zend_string *prefix, char filter_kind);
     764              : 
     765              : const char *lsp_primary_analyzer_source(lsp_server *server);
     766              : bool lsp_doc_is_identifier_start(char c);
     767              : bool lsp_doc_is_identifier_char(char c);
     768              : char lsp_type_constraint_completion_kind(zend_string *text, size_t offset, zend_string *prefix);
     769              : void lsp_phpdoc_add_variable_type_completions(lsp_server *server, zval *items, zend_string *text, zend_string *prefix);
     770              : void lsp_phpdoc_add_variable_type_completion_edits(lsp_server *server, zval *items, zend_string *text, zend_string *prefix, size_t prefix_start, size_t offset);
     771              : void lsp_phpdoc_add_annotation_completions(zval *items, zend_string *text, size_t offset);
     772              : zend_string *lsp_phpdoc_type_for_word(zend_string *text, zend_string *word);
     773              : zend_string *lsp_phpdoc_type_for_word_range(zend_string *text, size_t start_offset, size_t end_offset, zend_string *word);
     774              : zend_string *lsp_phpdoc_type_for_word_raw(zend_string *text, zend_string *word);
     775              : zend_string *lsp_phpdoc_property_type_for_word(zend_string *text, zend_string *word, size_t offset);
     776              : zend_string *lsp_phpdoc_property_type_for_word_raw(zend_string *text, zend_string *word, size_t offset);
     777              : void lsp_phpdoc_add_template_completions(lsp_server *server, zval *items, zend_string *text, zend_string *prefix);
     778              : zend_string *lsp_phpdoc_return_type_from_comment(zend_string *comment);
     779              : zend_string *lsp_phpdoc_return_type_from_comment_raw(zend_string *comment);
     780              : bool lsp_phpdoc_type_has_array_shape(zend_string *type);
     781              : zend_string *lsp_phpdoc_array_shape_key_type(zend_string *type, zend_string *key);
     782              : bool lsp_phpdoc_add_array_shape_completions(lsp_server *server, zval *items, lsp_document *document, size_t offset);
     783              : bool lsp_phpdoc_add_object_shape_member_completions(lsp_server *server, zval *items, lsp_document *document, size_t offset, zend_string *prefix);
     784              : zend_string *lsp_phpdoc_attribute_shape_type_before(zend_string *text, size_t offset, bool normalize);
     785              : void lsp_phpdoc_cache_class_methods(zval *methods, zend_string *contents, size_t class_start);
     786              : void lsp_phpdoc_cache_class_properties(zval *properties, zend_string *contents, size_t class_start);
     787              : zend_string *lsp_phpdoc_template_type_at(zend_string *text, uint32_t target_index);
     788              : zend_string *lsp_phpdoc_trait_use_generic_argument(zend_string *text, zend_string *trait_name, uint32_t target_index);
     789              : bool lsp_member_access_arrow(zend_string *text, size_t offset, zend_string *prefix, size_t *arrow_start, size_t *receiver_end);
     790              : bool lsp_member_access_context(zend_string *text, size_t offset, zend_string *prefix, zend_string **receiver, zend_string **member_prefix);
     791              : bool lsp_find_matching_open_paren(zend_string *text, size_t close_offset, size_t *open_offset);
     792              : bool lsp_find_matching_open_bracket(zend_string *text, size_t close_offset, size_t *open_offset);
     793              : bool lsp_parse_method_call_before_offset(zend_string *text, size_t offset, zend_string **method_name, size_t *receiver_end);
     794              : bool lsp_parse_this_method_call_ending_at(zend_string *text, size_t offset, zend_string **method_name);
     795              : bool lsp_this_method_call_member_access_context(zend_string *text, size_t offset, zend_string *prefix, zend_string **method_name, zend_string **member_prefix);
     796              : zend_string *lsp_infer_new_assignment_class(zend_string *text, zend_string *receiver, size_t offset);
     797              : size_t lsp_current_statement_scan_limit(zend_string *text, size_t offset);
     798              : zend_string *lsp_type_generic_argument(zend_string *type, uint32_t target_index);
     799              : bool lsp_type_equals(zend_string *left, zend_string *right);
     800              : zend_string *lsp_type_array_element_type(zend_string *type);
     801              : zend_string *lsp_resolve_class_name(zend_string *text, zend_string *type);
     802              : 
     803              : bool lsp_text_is_word_boundary(zend_string *text, size_t offset);
     804              : zend_long lsp_brace_depth_at(zend_string *text, size_t offset);
     805              : void lsp_brace_cache_clear(void);
     806              : void lsp_resolve_cache_clear(void);
     807              : bool lsp_find_matching_brace(zend_string *text, size_t open_offset, size_t *close_offset);
     808              : bool lsp_token_is_char(zval *token, char value);
     809              : bool lsp_token_in_bounds(zval *token, size_t start, size_t end);
     810              : bool lsp_token_at_depth(zend_string *text, zval *token, zend_long depth);
     811              : bool lsp_token_is_property_declaration(HashTable *tokens, uint32_t index, zend_string *text, zend_long body_depth);
     812              : zend_string *lsp_parameter_declared_type_for_variable(lsp_document *document, zend_string *variable, size_t offset);
     813              : zend_string *lsp_infer_variable_type(lsp_server *server, lsp_document *document, zend_string *variable, size_t offset);
     814              : zend_string *lsp_infer_variable_phpdoc_type(lsp_document *document, zend_string *variable, size_t offset);
     815              : zend_string *lsp_infer_variable_declared_type(lsp_server *server, lsp_document *document, zend_string *variable, size_t offset);
     816              : bool lsp_find_first_class_bounds(zend_string *text, size_t *body_start, size_t *body_end, zend_long *body_depth);
     817              : bool lsp_method_is_public(HashTable *tokens, uint32_t index, zend_string *text, zend_long body_depth);
     818              : bool lsp_path_value_contains_analysis_helper(const char *path, size_t path_length);
     819              : zend_string *lsp_find_project_symbol_path(lsp_server *server, char expected_kind, zend_string *fqcn);
     820              : bool lsp_member_access_class_context(lsp_server *server, lsp_document *document, size_t offset, zend_string *prefix, zend_string **class_name, zend_string **member_prefix);
     821              : zend_string *lsp_infer_receiver_class(lsp_server *server, lsp_document *document, zend_string *receiver, size_t offset);
     822              : 
     823              : size_t lsp_method_signature_end(HashTable *tokens, uint32_t name_index, zend_string *text, zend_long body_depth);
     824              : zend_string *lsp_function_signature_detail(zend_string *text, zval *name_token, HashTable *tokens, uint32_t name_index, zend_long body_depth, const char *prefix);
     825              : bool lsp_find_enclosing_class_header(zend_string *text, size_t offset, size_t *class_start, size_t *body_start, size_t *body_end, zend_long *body_depth);
     826              : bool lsp_find_class_header_from(zend_string *text, size_t search_start, size_t *class_start, size_t *body_start, size_t *body_end, zend_long *body_depth);
     827              : bool lsp_find_first_class_header(zend_string *text, size_t *class_start, size_t *body_start, size_t *body_end, zend_long *body_depth);
     828              : bool lsp_word_at_slice_equals(const char *start, const char *end, const char *word);
     829              : zend_string *lsp_class_extends_name(zend_string *text, size_t class_start, size_t body_start);
     830              : zend_string *lsp_class_declared_name(zend_string *text, size_t class_start, size_t body_start);
     831              : zend_string *lsp_property_completion_detail(zend_string *text, zval *variable_token, bool is_static);
     832              : zend_string *lsp_promoted_property_completion_detail(zend_string *text, zval *variable_token, size_t param_start);
     833              : void lsp_add_scope_variable_completions(lsp_server *server, zval *items, lsp_document *document, HashTable *tokens, size_t offset, zend_string *prefix, size_t prefix_start);
     834              : bool lsp_find_class_header_for_name(zend_string *text, zend_string *class_name, size_t *class_start, size_t *body_start, size_t *body_end, zend_long *body_depth);
     835              : lsp_document *lsp_document_for_path(lsp_server *server, zend_string *path);
     836              : zval *lsp_class_member_cache_entry(lsp_server *server, zend_string *class_name);
     837              : void lsp_add_inherited_project_class_member_completions(lsp_server *server, zval *items, zend_string *class_name, zend_string *member_prefix);
     838              : void lsp_add_inherited_public_project_class_member_completions(lsp_server *server, zval *items, zend_string *class_name, zend_string *member_prefix);
     839              : void lsp_add_static_project_class_member_completions(lsp_server *server, zval *items, zend_string *class_name, zend_string *member_prefix);
     840              : void lsp_add_inherited_static_project_class_member_completions(lsp_server *server, zval *items, zend_string *class_name, zend_string *member_prefix);
     841              : void lsp_add_parent_reflection_class_member_completions(lsp_server *server, zval *items, zend_string *class_name, zend_string *member_prefix);
     842              : void lsp_add_current_class_phpdoc_member_completions(lsp_server *server, zval *items, lsp_document *document, size_t class_start, zend_string *member_prefix, bool static_access);
     843              : void lsp_add_current_static_member_completions(zval *items, lsp_document *document, size_t body_start, size_t body_end, zend_long body_depth, zend_string *member_prefix);
     844              : void lsp_add_inferred_member_completions(lsp_server *server, zval *items, lsp_document *document, size_t offset, zend_string *prefix);
     845              : void lsp_add_this_member_completions(lsp_server *server, zval *items, lsp_document *document, size_t offset, zend_string *prefix);
     846              : bool lsp_add_override_method_completions(lsp_server *server, zval *items, lsp_document *document, HashTable *tokens, size_t offset, zend_string *prefix);
     847              : bool lsp_find_symbol(zval *lsparrot, zend_string *word, zval **matched_token, zend_string **matched_label, zend_string **matched_detail);
     848              : const char *lsp_builtin_class_detail_prefix(zend_class_entry *ce);
     849              : bool lsp_offset_is_inside_class_body(zend_string *text, size_t offset);
     850              : 
     851              : void lsp_lsparrot_completion(lsp_server *server, zval *return_value, lsp_document *document, zval *position);
     852              : void lsp_lsparrot_hover(lsp_server *server, zval *return_value, lsp_document *document, zval *position);
     853              : void lsp_lsparrot_definition(lsp_server *server, zval *return_value, lsp_document *document, zval *position);
     854              : void lsp_lsparrot_type_definition(lsp_server *server, zval *return_value, lsp_document *document, zval *position);
     855              : void lsp_lsparrot_folding_range(lsp_server *server, zval *return_value, lsp_document *document);
     856              : void lsp_options_apply_runtime(lsp_options *options, zval *params);
     857              : void lsp_lsparrot_prepare_call_hierarchy(lsp_server *server, zval *return_value, lsp_document *document, zval *position);
     858              : void lsp_lsparrot_call_hierarchy_incoming(lsp_server *server, zval *return_value, zval *params);
     859              : void lsp_lsparrot_call_hierarchy_outgoing(lsp_server *server, zval *return_value, zval *params);
     860              : void lsp_lsparrot_prepare_type_hierarchy(lsp_server *server, zval *return_value, lsp_document *document, zval *position);
     861              : void lsp_lsparrot_type_hierarchy_supertypes(lsp_server *server, zval *return_value, zval *params);
     862              : void lsp_lsparrot_type_hierarchy_subtypes(lsp_server *server, zval *return_value, zval *params);
     863              : void lsp_workspace_roots_add(lsp_server *server, zend_string *root);
     864              : void lsp_workspace_roots_remove(lsp_server *server, zend_string *root);
     865              : bool lsp_path_is_under_any_root(lsp_server *server, zend_string *path);
     866              : void lsp_workspace_roots_each(lsp_server *server, void (*callback)(lsp_server *server, zend_string *root, void *context), void *context);
     867              : void lsp_workspace_parse_folders(lsp_server *server, zval *params);
     868              : void lsp_workspace_did_change_folders(lsp_server *server, zval *params);
     869              : void lsp_lsparrot_will_rename_files(lsp_server *server, zval *return_value, zval *params);
     870              : HashTable *lsp_analyzer_job_table(lsp_server *server, const char *analyzer);
     871              : lsp_analyzer_job *lsp_analyzer_job_slot(lsp_server *server, const char *analyzer, zend_string *project_root);
     872              : uint32_t lsp_analyzer_running_project_jobs(lsp_server *server);
     873              : bool lsp_analyzer_job_table_running(HashTable *jobs);
     874              : void lsp_analyzer_job_entry_destroy(zval *value);
     875              : void lsp_reap_analyzer_job_table(lsp_server *server, HashTable *jobs, const char *analyzer);
     876              : void lsp_lsparrot_semantic_tokens_range(lsp_server *server, zval *return_value, lsp_document *document, zval *params);
     877              : void lsp_lsparrot_semantic_tokens_full_delta(lsp_server *server, zval *return_value, lsp_document *document, zval *params);
     878              : void lsp_semantic_tokens_cache_clear(void);
     879              : void lsp_semantic_tokens_cache_evict(zend_string *uri);
     880              : void lsp_runner_reap_idle_sessions(lsp_server *server);
     881              : void lsp_runner_close_pipes_in_child(lsp_server *server);
     882              : void lsp_psalm_ls_close_pipes_in_child(lsp_server *server);
     883              : void lsp_lsparrot_selection_range(lsp_server *server, zval *return_value, lsp_document *document, zval *params);
     884              : void lsp_lsparrot_document_link(lsp_server *server, zval *return_value, lsp_document *document);
     885              : void lsp_lsparrot_code_lens(lsp_server *server, zval *return_value, lsp_document *document);
     886              : void lsp_lsparrot_signature_help(lsp_server *server, zval *return_value, lsp_document *document, zval *position);
     887              : void lsp_lsparrot_references(lsp_server *server, zval *return_value, lsp_document *document, zval *params);
     888              : void lsp_lsparrot_document_highlight(lsp_server *server, zval *return_value, lsp_document *document, zval *position);
     889              : void lsp_lsparrot_implementation(lsp_server *server, zval *return_value, lsp_document *document, zval *position);
     890              : void lsp_lsparrot_code_action(lsp_server *server, zval *return_value, lsp_document *document, zval *params);
     891              : void lsp_add_analyzer_quick_fixes(zval *actions, lsp_document *document, zval *params);
     892              : void lsp_lsparrot_prepare_rename(lsp_server *server, zval *return_value, lsp_document *document, zval *position);
     893              : void lsp_lsparrot_rename(lsp_server *server, zval *return_value, lsp_document *document, zval *params);
     894              : void lsp_lsparrot_formatting(lsp_server *server, zval *return_value, lsp_document *document, zval *params);
     895              : void lsp_lsparrot_range_formatting(lsp_server *server, zval *return_value, lsp_document *document, zval *params);
     896              : void lsp_lsparrot_inlay_hint(lsp_server *server, zval *return_value, lsp_document *document, zval *params);
     897              : void lsp_lsparrot_semantic_tokens(lsp_server *server, zval *return_value, lsp_document *document);
     898              : void lsp_semantic_token_legend(zval *legend);
     899              : 
     900              : lsp_document *lsp_document_open_or_change(lsp_server *server, zend_string *uri, zend_long version, zend_string *text);
     901              : lsp_document *lsp_document_from_uri(lsp_server *server, zend_string *uri);
     902              : void lsp_document_analyze(lsp_document *document);
     903              : void lsp_document_derived_invalidate(lsp_document *document);
     904              : void lsp_document_derived_ensure(lsp_document *document);
     905              : void lsp_server_evict_document_caches(lsp_server *server, zend_string *uri, bool include_type_cache);
     906              : void lsp_analyzer_deferred_type_completed(lsp_server *server, zval *descriptor, zend_string *output);
     907              : zend_string *lsp_runner_run_capture_deferred(lsp_server *server, const char *analyzer, zend_string *project_root, lsp_command *command, zend_string *cwd, double wait_timeout, double job_timeout, zval *descriptor, bool *deferred);
     908              : void lsp_runner_pump_pending(lsp_server *server);
     909              : bool lsp_runner_has_pending_for_uri(lsp_server *server, zend_string *uri);
     910              : uint32_t lsp_runner_pending_count(lsp_server *server);
     911              : zend_string *lsp_phpstan_parse_type_output(zend_string *output, zend_string *analysis_file, zend_long dump_line);
     912              : zend_string *lsp_psalm_parse_type_output(zend_string *output, zend_string *expression, zend_long trace_line);
     913              : zend_string *lsp_document_namespace_cached(lsp_document *document);
     914              : bool lsp_document_has_import_cached(lsp_document *document, char kind, const char *fqcn, size_t fqcn_length);
     915              : bool lsp_document_import_binds_short_name(lsp_document *document, char kind, const char *fqcn, size_t fqcn_length);
     916              : void lsp_add_inherited_project_class_method_completions(lsp_server *server, zval *items, zend_string *class_name, zend_string *member_prefix);
     917              : zend_string *lsp_parameter_declared_type_before_variable(zend_string *text, size_t variable_offset, size_t param_start);
     918              : zend_string *lsp_inherited_member_detail(lsp_server *server, zend_string *class_name, zend_string *member);
     919              : bool lsp_static_member_receiver_class(lsp_document *document, size_t offset, zend_string *word, zend_string **class_name, bool *public_only);
     920              : bool lsp_project_method_definition_for_class(lsp_server *server, zend_string *class_name, zend_string *member_name, zval *return_value, uint32_t depth);
     921              : bool lsp_find_function_scope_at(HashTable *tokens, zend_string *text, size_t offset, size_t *param_start, size_t *param_end, size_t *body_start, size_t *body_end, zend_long *body_depth);
     922              : bool lsp_token_is_promoted_property(HashTable *tokens, uint32_t index, zend_string *text, zend_long body_depth, size_t *param_start);
     923              : zend_string *lsp_document_import_bound_name(lsp_document *document, char kind, const char *fqcn, size_t fqcn_length);
     924              : zend_string *lsp_document_import_fqcn_for_bound_name(lsp_document *document, char kind, zend_string *name);
     925              : zend_string *lsp_use_statement_class_name_at(zend_string *text, size_t offset);
     926              : size_t lsp_document_import_insert_offset_cached(lsp_document *document, bool *after_existing_use);
     927              : void lsp_document_collect_imports(zend_string *text, HashTable *imports);
     928              : void lsp_perf_stats_record(lsp_server *server, zend_string *method, double elapsed_seconds);
     929              : void lsp_symbol_index_table_ensure(lsp_symbol_index *region);
     930              : void lsp_symbol_index_table_invalidate(lsp_symbol_index *region);
     931              : const char *lsp_symbol_entry_fqcn(lsp_symbol_index *region, const lsp_symbol_entry *entry);
     932              : const char *lsp_symbol_entry_path(lsp_symbol_index *region, const lsp_symbol_entry *entry);
     933              : const char *lsp_symbol_index_lookup(lsp_symbol_index *region, char expected_kind, zend_string *fqcn, char *found_kind, const char **stored_fqcn, size_t *path_length);
     934              : uint32_t lsp_symbol_index_remove_path(lsp_symbol_index *region, zend_string *path);
     935              : void lsp_symbol_index_rebuild_keys(lsp_symbol_index *region);
     936              : void lsp_index_refresh_file(lsp_server *server, zend_string *path);
     937              : void lsp_project_index_persist(lsp_server *server);
     938              : void lsp_index_join_worker(lsp_server *server);
     939              : void lsp_index_poll_worker(lsp_server *server);
     940              : void lsp_index_stop_worker(lsp_server *server);
     941              : void lsp_protocol_respond(zval *id, zval *result);
     942              : void lsp_protocol_error(zval *id, int code, const char *message);
     943              : void lsp_protocol_notify(const char *method, zval *params);
     944              : void lsp_analyzer_status(const char *analyzer, const char *state, const char *message);
     945              : void lsp_analyzer_project_status(const char *analyzer, const char *state, const char *message, zend_string *project_root);
     946              : void lsp_analyzer_project_state(lsp_server *server, const char *analyzer, zend_string *project_root, zend_long state);
     947              : void lsp_reap_analyzer_jobs(lsp_server *server);
     948              : void lsp_analyzer_unavailable(const char *analyzer, const char *label);
     949              : void lsp_driver_status(lsp_server *server);
     950              : void lsp_server_status(lsp_server *server, zval *return_value);
     951              : bool lsp_protocol_next_message(lsp_server *server, zval *message);
     952              : bool lsp_protocol_request_is_cancelled(zval *id);
     953              : bool lsp_protocol_queue_supersedes_change(zend_string *uri);
     954              : void lsp_transport_shutdown(void);
     955              : 
     956              : double lsp_now_seconds(void);
     957              : zend_string *lsp_process_run_capture(lsp_command *command, zend_string *cwd, double timeout);
     958              : lsp_process_id lsp_process_spawn_to_file(lsp_command *command, zend_string *cwd, zend_string *output_file);
     959              : bool lsp_process_spawn_piped(lsp_command *command, zend_string *cwd, lsp_process_pipes *pipes);
     960              : bool lsp_process_wait_nonblocking(lsp_process_id process, int *status);
     961              : bool lsp_process_wait_timeout(lsp_process_id process, int *status, double timeout);
     962              : void lsp_process_wait(lsp_process_id process, int *status);
     963              : void lsp_process_terminate(lsp_process_id process);
     964              : void lsp_process_terminate_force(lsp_process_id process);
     965              : void lsp_process_close(lsp_process_id process);
     966              : void lsp_terminate_guard_install(void);
     967              : void lsp_terminate_guard_restore(void);
     968              : bool lsp_terminate_requested(void);
     969              : void lsp_pipe_close(lsp_pipe_handle *pipe);
     970              : bool lsp_pipe_write_all_timeout(lsp_pipe_handle pipe, const char *data, size_t length, double timeout);
     971              : bool lsp_pipe_read_available(lsp_pipe_handle pipe, smart_str *output, bool *closed);
     972              : 
     973              : zend_string *lsp_runner_run_capture(lsp_server *server, const char *analyzer, zend_string *project_root, lsp_command *command, zend_string *cwd, double timeout);
     974              : void lsp_runner_shutdown_all(lsp_server *server);
     975              : void lsp_runner_status(lsp_server *server, zval *target);
     976              : void lsp_runner_session_destroy(zval *value);
     977              : 
     978              : void lsp_publish_empty_diagnostics(zend_string *uri);
     979              : zend_string *lsp_join_path2(zend_string *base, const char *suffix);
     980              : zend_string *lsp_tool_project_candidate(zend_string *root, const char *name);
     981              : bool lsp_tool_available(const char *name, zend_string *root);
     982              : bool lsp_tool_command(lsp_server *server, zend_string *root, const char *name, lsp_command *command);
     983              : bool lsp_include_array_file(zend_string *path, zval *return_value);
     984              : zend_string *lsp_run_command_capture(lsp_command *command, zend_string *cwd, double timeout);
     985              : void lsp_add_analyzer_diagnostic(zval *diagnostics, const char *source, zend_string *message, zend_string *code, zval *range, zend_long severity);
     986              : zend_string *lsp_json_slice_from(zend_string *output, char open_char);
     987              : zend_string *lsp_analyzer_failure_message(const char *analyzer, zend_string *output);
     988              : zend_long lsp_analyzer_parallel_workers(lsp_server *server);
     989              : void lsp_analyzer_add_memory_limit(lsp_command *command, lsp_server *server);
     990              : zend_string *lsp_analyzer_project_output_file(zend_string *project_root, const char *analyzer);
     991              : zend_long lsp_analyzer_project_state_value(lsp_server *server, const char *analyzer, zend_string *project_root);
     992              : bool lsp_analyzer_project_has_state(lsp_server *server, const char *analyzer, zend_string *project_root);
     993              : bool lsp_analyzer_project_has_scope(zend_string *project_root);
     994              : bool lsp_document_is_in_analyzer_scope(lsp_document *document, zend_string *project_root);
     995              : void lsp_command_add_composer_analysis_paths(lsp_command *command, zend_string *project_root);
     996              : bool lsp_start_analyzer_project_job(lsp_server *server, const char *analyzer, zend_string *project_root, lsp_command *command, zend_string *output_file);
     997              : void lsp_analyzer_project_finished(lsp_server *server, const char *analyzer, zend_string *project_root, zend_string *output_file);
     998              : void lsp_schedule_workspace_analyzers(lsp_server *server);
     999              : void lsp_schedule_project_analyzers(lsp_server *server, lsp_document *document);
    1000              : void lsp_reschedule_project_analyzers(lsp_server *server, lsp_document *document);
    1001              : void lsp_start_pending_phpstan_project_analyzer(lsp_server *server);
    1002              : void lsp_schedule_phpstan_project_analyzer(lsp_server *server, zend_string *project_root);
    1003              : void lsp_append_phpstan_cached_diagnostics(lsp_server *server, lsp_document *document, zval *diagnostics);
    1004              : void lsp_reschedule_phpstan_project_analyzer(lsp_server *server, zend_string *project_root);
    1005              : void lsp_start_pending_psalm_project_analyzer(lsp_server *server);
    1006              : void lsp_schedule_psalm_project_analyzer(lsp_server *server, zend_string *project_root);
    1007              : void lsp_append_psalm_cached_diagnostics(lsp_server *server, lsp_document *document, zval *diagnostics);
    1008              : void lsp_reschedule_psalm_project_analyzer(lsp_server *server, zend_string *project_root);
    1009              : bool lsp_scan_should_skip_dir_name(const char *name);
    1010              : zend_string *lsp_composer_config_string(zend_string *root, const char *key);
    1011              : zend_string *lsp_composer_vendor_dir(zend_string *project_root);
    1012              : zval *lsp_composer_json_decoded(zend_string *project_root);
    1013              : void lsp_composer_cache_clear(void);
    1014              : bool lsp_path_is_under_composer_vendor_dir(zend_string *path, zend_string *project_root);
    1015              : bool lsp_path_is_in_workspace_composer_vendor(zend_string *workspace_root, zend_string *path);
    1016              : void lsp_line_range(zval *range, zend_string *text, zend_long one_based_line);
    1017              : void lsp_line_range_columns(zval *range, zend_string *text, zend_long one_based_line, zend_long column_from, zend_long column_to);
    1018              : void lsp_publish_document_diagnostics(lsp_server *server, lsp_document *document);
    1019              : zend_string *lsp_document_project_root(lsp_server *server, lsp_document *document);
    1020              : zend_string *lsp_phpstan_type_for_expression(lsp_server *server, lsp_document *document, zend_string *expression, size_t offset);
    1021              : zend_string *lsp_psalm_type_for_expression(lsp_server *server, lsp_document *document, zend_string *expression, size_t offset);
    1022              : zend_string *lsp_phpstan_config_file(zend_string *root);
    1023              : zend_string *lsp_phpstan_lsp_config_file(zend_string *project_root, zend_string *project_config, zend_long parallel_workers);
    1024              : zend_long lsp_project_phpstan_level(lsp_server *server, zend_string *project_root);
    1025              : zend_string *lsp_psalm_config_file(zend_string *root);
    1026              : zend_long lsp_project_psalm_level(lsp_server *server, zend_string *project_root);
    1027              : zend_string *lsp_psalm_ls_config_file(zend_string *project_root, zend_string *project_config, zend_long level, bool live_dead_code_diagnostics);
    1028              : zend_string *lsp_psalm_type_config_file(zend_string *project_root, zend_string *project_config, zend_long level, bool live_dead_code_diagnostics);
    1029              : void lsp_composer_analysis_paths(zend_string *project_root, zval *paths);
    1030              : bool lsp_composer_project_has_analysis_paths(zend_string *project_root);
    1031              : bool lsp_path_is_in_composer_analysis_paths(zend_string *path, zend_string *project_root);
    1032              : 
    1033              : void lsp_build_project_index(lsp_server *server);
    1034              : void lsp_resolve_analyzers(lsp_server *server);
    1035              : 
    1036              : void lsp_server_loop(lsp_server *server);
    1037              : 
    1038              : #endif /* LSP_INTERNAL_H */
        

Generated by: LCOV version 2.0-1