LCOV - code coverage report
Current view: top level - ext - lsp_server.c (source / functions) Coverage Total Hit
Test: Extension code coverage Lines: 100.0 % 61 61
Test Date: 2026-07-13 00:58:38 Functions: 100.0 % 2 2

            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              : #include "lsp_internal.h"
      15              : 
      16         2444 : static inline void lsp_perf_counter_dtor(zval *value)
      17              : {
      18         2444 :         efree(Z_PTR_P(value));
      19         2444 : }
      20              : 
      21          548 : extern void lsp_server_run(zval *options)
      22              : {
      23              :         lsp_server server;
      24              : 
      25          548 :         memset(&server, 0, sizeof(server));
      26          548 :         lsp_terminate_guard_install();
      27          548 :         lsp_set_lsp_stdio_binary();
      28          548 :         lsp_options_from_zval(&server.options, options);
      29          548 :         lsp_symbol_index_init(&server.symbol_index, &server.options);
      30          548 :         zend_hash_init(&server.documents, 8, NULL, lsp_document_destroy, 0);
      31          548 :         zend_hash_init(&server.member_cache, 8, NULL, ZVAL_PTR_DTOR, 0);
      32          548 :         zend_hash_init(&server.completion_cache, 8, NULL, ZVAL_PTR_DTOR, 0);
      33          548 :         zend_hash_init(&server.type_cache, 64, NULL, ZVAL_PTR_DTOR, 0);
      34          548 :         zend_hash_init(&server.phpstan_projects, 8, NULL, ZVAL_PTR_DTOR, 0);
      35          548 :         zend_hash_init(&server.psalm_projects, 8, NULL, ZVAL_PTR_DTOR, 0);
      36          548 :         zend_hash_init(&server.psalm_ls_project_states, 8, NULL, ZVAL_PTR_DTOR, 0);
      37          548 :         zend_hash_init(&server.psalm_ls_projects, 8, NULL, lsp_psalm_ls_project_destroy, 0);
      38          548 :         zend_hash_init(&server.perf_stats, 8, NULL, lsp_perf_counter_dtor, 0);
      39          548 :         zend_hash_init(&server.runner_sessions, 8, NULL, lsp_runner_session_destroy, 0);
      40          548 :         zend_hash_init(&server.workspace_roots, 4, NULL, NULL, 0);
      41          548 :         zend_hash_init(&server.phpstan_jobs, 4, NULL, lsp_analyzer_job_entry_destroy, 0);
      42          548 :         zend_hash_init(&server.psalm_jobs, 4, NULL, lsp_analyzer_job_entry_destroy, 0);
      43          548 :         server.root = zend_string_init(".", sizeof(".") - 1, 0);
      44          548 :         server.phpstan_enabled = false;
      45          548 :         server.psalm_enabled = false;
      46          548 :         server.psalm_ls_enabled = false;
      47          548 :         server.shutdown = false;
      48          548 :         server.saw_shutdown = false;
      49              : 
      50          548 :         lsp_tokens_cache_set_enabled(true);
      51          548 :         lsp_server_loop(&server);
      52          548 :         lsp_tokens_cache_set_enabled(false);
      53          548 :         lsp_brace_cache_clear();
      54          548 :         lsp_resolve_cache_clear();
      55          548 :         lsp_composer_cache_clear();
      56          548 :         lsp_semantic_tokens_cache_clear();
      57          548 :         lsp_transport_shutdown();
      58          548 :         lsp_index_stop_worker(&server);
      59          548 :         lsp_project_index_persist(&server);
      60              : 
      61          548 :         lsp_runner_shutdown_all(&server);
      62          548 :         zend_hash_destroy(&server.runner_sessions);
      63          548 :         lsp_psalm_ls_shutdown_all(&server);
      64          548 :         zend_hash_destroy(&server.phpstan_jobs);
      65          548 :         zend_hash_destroy(&server.psalm_jobs);
      66          548 :         lsp_analyzer_job_destroy(&server.phpstan_completion_job);
      67          548 :         lsp_analyzer_job_destroy(&server.psalm_completion_job);
      68          548 :         zend_hash_destroy(&server.psalm_ls_projects);
      69          548 :         zend_hash_destroy(&server.psalm_ls_project_states);
      70          548 :         zend_hash_destroy(&server.psalm_projects);
      71          548 :         zend_hash_destroy(&server.phpstan_projects);
      72          548 :         zend_hash_destroy(&server.type_cache);
      73          548 :         zend_hash_destroy(&server.completion_cache);
      74          548 :         zend_hash_destroy(&server.member_cache);
      75          548 :         zend_hash_destroy(&server.documents);
      76          548 :         zend_hash_destroy(&server.perf_stats);
      77          548 :         zend_hash_destroy(&server.workspace_roots);
      78          548 :         zend_string_release(server.root);
      79          548 :         lsp_symbol_index_destroy(&server.symbol_index);
      80          548 :         lsp_options_destroy(&server.options);
      81              : 
      82          548 :         EG(exit_status) = server.saw_shutdown ? 0 : 1;
      83          548 :         lsp_terminate_guard_restore();
      84          548 : }
        

Generated by: LCOV version 2.0-1