| 1 | program test_lsp_init |
| 2 | use lsp_server_manager_module |
| 3 | use iso_fortran_env, only: output_unit, error_unit |
| 4 | implicit none |
| 5 | |
| 6 | type(lsp_manager_t) :: manager |
| 7 | integer :: server_index |
| 8 | character(len=256) :: test_file |
| 9 | integer :: i |
| 10 | |
| 11 | print *, "Testing LSP initialization with fixed JSON parser..." |
| 12 | |
| 13 | ! Create test file |
| 14 | test_file = "/tmp/test.c" |
| 15 | open(10, file=test_file, status='replace') |
| 16 | write(10, '(a)') "#include <stdio.h>" |
| 17 | write(10, '(a)') "int main() { return 0; }" |
| 18 | close(10) |
| 19 | |
| 20 | ! Initialize manager |
| 21 | call init_lsp_manager(manager) |
| 22 | |
| 23 | ! Get or start server for C language |
| 24 | server_index = get_or_start_server(manager, "c", "/tmp") |
| 25 | if (server_index > 0) then |
| 26 | print *, "✓ Server started successfully" |
| 27 | print '(a,i0)', " Server index: ", server_index |
| 28 | else |
| 29 | print *, "✗ Failed to start server" |
| 30 | stop 1 |
| 31 | end if |
| 32 | |
| 33 | ! Wait a bit for initialization |
| 34 | print *, "Waiting for initialization..." |
| 35 | call sleep(2) |
| 36 | |
| 37 | ! Process any pending messages |
| 38 | call process_server_messages(manager) |
| 39 | |
| 40 | ! Check if server is initialized |
| 41 | do i = 1, manager%num_servers |
| 42 | if (manager%servers(i)%initialized) then |
| 43 | print *, "✓ Server initialized successfully!" |
| 44 | else |
| 45 | print *, "✗ Server not yet initialized" |
| 46 | end if |
| 47 | |
| 48 | ! Show server info |
| 49 | print '(a,a)', " Command: ", trim(manager%servers(i)%command) |
| 50 | print '(a,i0)', " Process ID: ", manager%servers(i)%process_id |
| 51 | print '(a,l1)', " Initialized: ", manager%servers(i)%initialized |
| 52 | print '(a,l1)', " Supports completion: ", manager%servers(i)%supports_completion |
| 53 | end do |
| 54 | |
| 55 | ! Cleanup |
| 56 | call cleanup_lsp_manager(manager) |
| 57 | print *, "Test complete." |
| 58 | |
| 59 | end program test_lsp_init |