@@ -25,9 +25,31 @@ module lsp_client_module |
| 25 | 25 | character(len=:), allocatable :: file_path |
| 26 | 26 | character(len=:), allocatable :: language_id |
| 27 | 27 | integer :: version = 0 |
| 28 | | - type(lsp_server_t), pointer :: server => null() |
| 28 | + integer :: server_index = 0 ! 0 means no server assigned |
| 29 | 29 | end type document_info_t |
| 30 | 30 | |
| 31 | + ! Type stubs for return types |
| 32 | + type :: lsp_completion_t |
| 33 | + character(len=:), allocatable :: label |
| 34 | + character(len=:), allocatable :: detail |
| 35 | + end type lsp_completion_t |
| 36 | + |
| 37 | + type :: lsp_location_t |
| 38 | + character(len=:), allocatable :: uri |
| 39 | + integer :: line |
| 40 | + integer :: column |
| 41 | + end type lsp_location_t |
| 42 | + |
| 43 | + type :: lsp_document_symbol_t |
| 44 | + character(len=:), allocatable :: name |
| 45 | + integer :: kind |
| 46 | + end type lsp_document_symbol_t |
| 47 | + |
| 48 | + type :: lsp_code_action_t |
| 49 | + character(len=:), allocatable :: title |
| 50 | + character(len=:), allocatable :: command |
| 51 | + end type lsp_code_action_t |
| 52 | + |
| 31 | 53 | ! Main LSP client |
| 32 | 54 | type :: lsp_client_t |
| 33 | 55 | type(lsp_manager_t) :: manager |
@@ -77,7 +99,7 @@ contains |
| 77 | 99 | type(lsp_server_t), pointer :: server |
| 78 | 100 | type(lsp_message_t) :: msg |
| 79 | 101 | character(len=:), allocatable :: lang_id, uri |
| 80 | | - integer :: i |
| 102 | + integer :: i, server_index |
| 81 | 103 | |
| 82 | 104 | ! Check if already open |
| 83 | 105 | do i = 1, client%num_documents |
@@ -96,8 +118,8 @@ contains |
| 96 | 118 | end if |
| 97 | 119 | |
| 98 | 120 | ! Get or start server for this language |
| 99 | | - server => get_or_start_server(client%manager, lang_id, client%workspace_root) |
| 100 | | - if (.not. associated(server)) return |
| 121 | + server_index = get_or_start_server(client%manager, lang_id, client%workspace_root) |
| 122 | + if (server_index <= 0) return |
| 101 | 123 | |
| 102 | 124 | ! Build URI |
| 103 | 125 | uri = file_path_to_uri(file_path) |
@@ -112,16 +134,16 @@ contains |
| 112 | 134 | new_documents(client%num_documents + 1)%file_path = file_path |
| 113 | 135 | new_documents(client%num_documents + 1)%language_id = lang_id |
| 114 | 136 | new_documents(client%num_documents + 1)%version = 1 |
| 115 | | - new_documents(client%num_documents + 1)%server => server |
| 137 | + new_documents(client%num_documents + 1)%server_index = server_index |
| 116 | 138 | |
| 117 | 139 | deallocate(client%documents) |
| 118 | 140 | client%documents = new_documents |
| 119 | 141 | client%num_documents = client%num_documents + 1 |
| 120 | 142 | |
| 121 | 143 | ! Send didOpen notification |
| 122 | | - if (server%initialized) then |
| 144 | + if (client%manager%servers(server_index)%initialized) then |
| 123 | 145 | msg = create_did_open_notification(uri, lang_id, 1, content) |
| 124 | | - call send_notification(server, msg) |
| 146 | + call send_notification(client%manager%servers(server_index), msg) |
| 125 | 147 | end if |
| 126 | 148 | end subroutine open_document |
| 127 | 149 | |
@@ -134,10 +156,10 @@ contains |
| 134 | 156 | do i = 1, client%num_documents |
| 135 | 157 | if (client%documents(i)%file_path == file_path) then |
| 136 | 158 | ! Send didClose notification |
| 137 | | - if (associated(client%documents(i)%server)) then |
| 138 | | - if (client%documents(i)%server%initialized) then |
| 159 | + if (client%documents(i)%server_index > 0) then |
| 160 | + if (client%manager%servers(client%documents(i)%server_index)%initialized) then |
| 139 | 161 | msg = create_did_close_notification(client%documents(i)%uri) |
| 140 | | - call send_notification(client%documents(i)%server, msg) |
| 162 | + call send_notification(client%manager%servers(client%documents(i)%server_index), msg) |
| 141 | 163 | end if |
| 142 | 164 | end if |
| 143 | 165 | |
@@ -160,14 +182,14 @@ contains |
| 160 | 182 | |
| 161 | 183 | do i = 1, client%num_documents |
| 162 | 184 | if (client%documents(i)%file_path == file_path) then |
| 163 | | - if (associated(client%documents(i)%server)) then |
| 164 | | - if (client%documents(i)%server%initialized) then |
| 185 | + if (client%documents(i)%server_index > 0) then |
| 186 | + if (client%manager%servers(client%documents(i)%server_index)%initialized) then |
| 165 | 187 | if (present(content)) then |
| 166 | 188 | msg = create_did_save_notification(client%documents(i)%uri, content) |
| 167 | 189 | else |
| 168 | 190 | msg = create_did_save_notification(client%documents(i)%uri) |
| 169 | 191 | end if |
| 170 | | - call send_notification(client%documents(i)%server, msg) |
| 192 | + call send_notification(client%manager%servers(client%documents(i)%server_index), msg) |
| 171 | 193 | end if |
| 172 | 194 | end if |
| 173 | 195 | exit |
@@ -185,11 +207,11 @@ contains |
| 185 | 207 | if (client%documents(i)%file_path == file_path) then |
| 186 | 208 | client%documents(i)%version = client%documents(i)%version + 1 |
| 187 | 209 | |
| 188 | | - if (associated(client%documents(i)%server)) then |
| 189 | | - if (client%documents(i)%server%initialized) then |
| 210 | + if (client%documents(i)%server_index > 0) then |
| 211 | + if (client%manager%servers(client%documents(i)%server_index)%initialized) then |
| 190 | 212 | msg = create_did_change_notification(client%documents(i)%uri, & |
| 191 | 213 | client%documents(i)%version, content) |
| 192 | | - call send_notification(client%documents(i)%server, msg) |
| 214 | + call send_notification(client%manager%servers(client%documents(i)%server_index), msg) |
| 193 | 215 | end if |
| 194 | 216 | end if |
| 195 | 217 | exit |
@@ -209,12 +231,12 @@ contains |
| 209 | 231 | |
| 210 | 232 | do i = 1, client%num_documents |
| 211 | 233 | if (client%documents(i)%file_path == file_path) then |
| 212 | | - if (associated(client%documents(i)%server)) then |
| 213 | | - if (client%documents(i)%server%initialized .and. & |
| 214 | | - client%documents(i)%server%supports_completion) then |
| 234 | + if (client%documents(i)%server_index > 0) then |
| 235 | + if (client%manager%servers(client%documents(i)%server_index)%initialized .and. & |
| 236 | + client%manager%servers(client%documents(i)%server_index)%supports_completion) then |
| 215 | 237 | msg = create_completion_request(client%documents(i)%uri, & |
| 216 | 238 | line - 1, column - 1) ! LSP is 0-based |
| 217 | | - call send_request(client%documents(i)%server, msg) |
| 239 | + call send_request(client%manager%servers(client%documents(i)%server_index), msg) |
| 218 | 240 | ! TODO: Wait for and process response |
| 219 | 241 | end if |
| 220 | 242 | end if |
@@ -235,12 +257,12 @@ contains |
| 235 | 257 | |
| 236 | 258 | do i = 1, client%num_documents |
| 237 | 259 | if (client%documents(i)%file_path == file_path) then |
| 238 | | - if (associated(client%documents(i)%server)) then |
| 239 | | - if (client%documents(i)%server%initialized .and. & |
| 240 | | - client%documents(i)%server%supports_hover) then |
| 260 | + if (client%documents(i)%server_index > 0) then |
| 261 | + if (client%manager%servers(client%documents(i)%server_index)%initialized .and. & |
| 262 | + client%manager%servers(client%documents(i)%server_index)%supports_hover) then |
| 241 | 263 | msg = create_hover_request(client%documents(i)%uri, & |
| 242 | 264 | line - 1, column - 1) ! LSP is 0-based |
| 243 | | - call send_request(client%documents(i)%server, msg) |
| 265 | + call send_request(client%manager%servers(client%documents(i)%server_index), msg) |
| 244 | 266 | ! TODO: Wait for and process response |
| 245 | 267 | end if |
| 246 | 268 | end if |
@@ -261,12 +283,12 @@ contains |
| 261 | 283 | |
| 262 | 284 | do i = 1, client%num_documents |
| 263 | 285 | if (client%documents(i)%file_path == file_path) then |
| 264 | | - if (associated(client%documents(i)%server)) then |
| 265 | | - if (client%documents(i)%server%initialized .and. & |
| 266 | | - client%documents(i)%server%supports_definition) then |
| 286 | + if (client%documents(i)%server_index > 0) then |
| 287 | + if (client%manager%servers(client%documents(i)%server_index)%initialized .and. & |
| 288 | + client%manager%servers(client%documents(i)%server_index)%supports_definition) then |
| 267 | 289 | msg = create_definition_request(client%documents(i)%uri, & |
| 268 | 290 | line - 1, column - 1) ! LSP is 0-based |
| 269 | | - call send_request(client%documents(i)%server, msg) |
| 291 | + call send_request(client%manager%servers(client%documents(i)%server_index), msg) |
| 270 | 292 | ! TODO: Wait for and process response |
| 271 | 293 | end if |
| 272 | 294 | end if |
@@ -291,12 +313,12 @@ contains |
| 291 | 313 | |
| 292 | 314 | do i = 1, client%num_documents |
| 293 | 315 | if (client%documents(i)%file_path == file_path) then |
| 294 | | - if (associated(client%documents(i)%server)) then |
| 295 | | - if (client%documents(i)%server%initialized .and. & |
| 296 | | - client%documents(i)%server%supports_references) then |
| 316 | + if (client%documents(i)%server_index > 0) then |
| 317 | + if (client%manager%servers(client%documents(i)%server_index)%initialized .and. & |
| 318 | + client%manager%servers(client%documents(i)%server_index)%supports_references) then |
| 297 | 319 | msg = create_references_request(client%documents(i)%uri, & |
| 298 | 320 | line - 1, column - 1, include_decl) |
| 299 | | - call send_request(client%documents(i)%server, msg) |
| 321 | + call send_request(client%manager%servers(client%documents(i)%server_index), msg) |
| 300 | 322 | ! TODO: Wait for and process response |
| 301 | 323 | end if |
| 302 | 324 | end if |
@@ -316,11 +338,11 @@ contains |
| 316 | 338 | |
| 317 | 339 | do i = 1, client%num_documents |
| 318 | 340 | if (client%documents(i)%file_path == file_path) then |
| 319 | | - if (associated(client%documents(i)%server)) then |
| 320 | | - if (client%documents(i)%server%initialized .and. & |
| 321 | | - client%documents(i)%server%supports_document_symbols) then |
| 341 | + if (client%documents(i)%server_index > 0) then |
| 342 | + if (client%manager%servers(client%documents(i)%server_index)%initialized .and. & |
| 343 | + client%manager%servers(client%documents(i)%server_index)%supports_document_symbols) then |
| 322 | 344 | msg = create_document_symbols_request(client%documents(i)%uri) |
| 323 | | - call send_request(client%documents(i)%server, msg) |
| 345 | + call send_request(client%manager%servers(client%documents(i)%server_index), msg) |
| 324 | 346 | ! TODO: Wait for and process response |
| 325 | 347 | end if |
| 326 | 348 | end if |
@@ -346,11 +368,11 @@ contains |
| 346 | 368 | |
| 347 | 369 | do i = 1, client%num_documents |
| 348 | 370 | if (client%documents(i)%file_path == file_path) then |
| 349 | | - if (associated(client%documents(i)%server)) then |
| 350 | | - if (client%documents(i)%server%initialized .and. & |
| 351 | | - client%documents(i)%server%supports_formatting) then |
| 371 | + if (client%documents(i)%server_index > 0) then |
| 372 | + if (client%manager%servers(client%documents(i)%server_index)%initialized .and. & |
| 373 | + client%manager%servers(client%documents(i)%server_index)%supports_formatting) then |
| 352 | 374 | msg = create_formatting_request(client%documents(i)%uri, tabs, spaces) |
| 353 | | - call send_request(client%documents(i)%server, msg) |
| 375 | + call send_request(client%manager%servers(client%documents(i)%server_index), msg) |
| 354 | 376 | ! TODO: Wait for and process response |
| 355 | 377 | end if |
| 356 | 378 | end if |
@@ -368,12 +390,12 @@ contains |
| 368 | 390 | |
| 369 | 391 | do i = 1, client%num_documents |
| 370 | 392 | if (client%documents(i)%file_path == file_path) then |
| 371 | | - if (associated(client%documents(i)%server)) then |
| 372 | | - if (client%documents(i)%server%initialized .and. & |
| 373 | | - client%documents(i)%server%supports_rename) then |
| 393 | + if (client%documents(i)%server_index > 0) then |
| 394 | + if (client%manager%servers(client%documents(i)%server_index)%initialized .and. & |
| 395 | + client%manager%servers(client%documents(i)%server_index)%supports_rename) then |
| 374 | 396 | msg = create_rename_request(client%documents(i)%uri, & |
| 375 | 397 | line - 1, column - 1, new_name) |
| 376 | | - call send_request(client%documents(i)%server, msg) |
| 398 | + call send_request(client%manager%servers(client%documents(i)%server_index), msg) |
| 377 | 399 | ! TODO: Wait for and process response |
| 378 | 400 | end if |
| 379 | 401 | end if |
@@ -395,13 +417,13 @@ contains |
| 395 | 417 | |
| 396 | 418 | do i = 1, client%num_documents |
| 397 | 419 | if (client%documents(i)%file_path == file_path) then |
| 398 | | - if (associated(client%documents(i)%server)) then |
| 399 | | - if (client%documents(i)%server%initialized .and. & |
| 400 | | - client%documents(i)%server%supports_code_actions) then |
| 420 | + if (client%documents(i)%server_index > 0) then |
| 421 | + if (client%manager%servers(client%documents(i)%server_index)%initialized .and. & |
| 422 | + client%manager%servers(client%documents(i)%server_index)%supports_code_actions) then |
| 401 | 423 | msg = create_code_action_request(client%documents(i)%uri, & |
| 402 | 424 | start_line - 1, start_col - 1, & |
| 403 | 425 | end_line - 1, end_col - 1) |
| 404 | | - call send_request(client%documents(i)%server, msg) |
| 426 | + call send_request(client%manager%servers(client%documents(i)%server_index), msg) |
| 405 | 427 | ! TODO: Wait for and process response |
| 406 | 428 | end if |
| 407 | 429 | end if |
@@ -474,26 +496,4 @@ contains |
| 474 | 496 | end if |
| 475 | 497 | end function file_path_to_uri |
| 476 | 498 | |
| 477 | | - ! Type stubs for return types (should be properly defined) |
| 478 | | - type :: lsp_completion_t |
| 479 | | - character(len=:), allocatable :: label |
| 480 | | - character(len=:), allocatable :: detail |
| 481 | | - end type lsp_completion_t |
| 482 | | - |
| 483 | | - type :: lsp_location_t |
| 484 | | - character(len=:), allocatable :: uri |
| 485 | | - integer :: line |
| 486 | | - integer :: column |
| 487 | | - end type lsp_location_t |
| 488 | | - |
| 489 | | - type :: lsp_document_symbol_t |
| 490 | | - character(len=:), allocatable :: name |
| 491 | | - integer :: kind |
| 492 | | - end type lsp_document_symbol_t |
| 493 | | - |
| 494 | | - type :: lsp_code_action_t |
| 495 | | - character(len=:), allocatable :: title |
| 496 | | - character(len=:), allocatable :: command |
| 497 | | - end type lsp_code_action_t |
| 498 | | - |
| 499 | 499 | end module lsp_client_module |