|
286 | 286 | const USE_REVISE = Ref(false)
|
287 | 287 |
|
288 | 288 | function request_wrapper(func, server::LanguageServerInstance)
|
| 289 | + return function (conn, params, token) |
| 290 | + if server.shutdown_requested |
| 291 | + # it's fine to always return a value here, even for notifications, because |
| 292 | + # JSONRPC discards it anyways in that case |
| 293 | + return JSONRPC.JSONRPCError( |
| 294 | + -32600, |
| 295 | + "LS shutdown was requested.", |
| 296 | + nothing |
| 297 | + ) |
| 298 | + end |
| 299 | + if USE_REVISE[] && isdefined(Main, :Revise) |
| 300 | + try |
| 301 | + Main.Revise.revise() |
| 302 | + catch e |
| 303 | + @warn "Reloading with Revise failed" exception = e |
| 304 | + end |
| 305 | + Base.invokelatest(func, params, server, conn) |
| 306 | + else |
| 307 | + func(params, server, conn) |
| 308 | + end |
| 309 | + end |
| 310 | +end |
| 311 | + |
| 312 | +function notification_wrapper(func, server::LanguageServerInstance) |
289 | 313 | return function (conn, params)
|
290 | 314 | if server.shutdown_requested
|
291 | 315 | # it's fine to always return a value here, even for notifications, because
|
@@ -394,24 +418,24 @@ function Base.run(server::LanguageServerInstance; timings = [])
|
394 | 418 | msg_dispatcher[julia_getDocAt_request_type] = request_wrapper(julia_getDocAt_request, server)
|
395 | 419 | msg_dispatcher[textDocument_hover_request_type] = request_wrapper(textDocument_hover_request, server)
|
396 | 420 | msg_dispatcher[initialize_request_type] = request_wrapper(initialize_request, server)
|
397 |
| - msg_dispatcher[initialized_notification_type] = request_wrapper(initialized_notification, server) |
| 421 | + msg_dispatcher[initialized_notification_type] = notification_wrapper(initialized_notification, server) |
398 | 422 | msg_dispatcher[shutdown_request_type] = request_wrapper(shutdown_request, server)
|
399 |
| - msg_dispatcher[cancel_notification_type] = request_wrapper(cancel_notification, server) |
400 |
| - msg_dispatcher[setTrace_notification_type] = request_wrapper(setTrace_notification, server) |
401 |
| - msg_dispatcher[setTraceNotification_notification_type] = request_wrapper(setTraceNotification_notification, server) |
| 423 | + msg_dispatcher[cancel_notification_type] = notification_wrapper(cancel_notification, server) |
| 424 | + msg_dispatcher[setTrace_notification_type] = notification_wrapper(setTrace_notification, server) |
| 425 | + msg_dispatcher[setTraceNotification_notification_type] = notification_wrapper(setTraceNotification_notification, server) |
402 | 426 | msg_dispatcher[julia_getCurrentBlockRange_request_type] = request_wrapper(julia_getCurrentBlockRange_request, server)
|
403 |
| - msg_dispatcher[julia_activateenvironment_notification_type] = request_wrapper(julia_activateenvironment_notification, server) |
404 |
| - msg_dispatcher[textDocument_didOpen_notification_type] = request_wrapper(textDocument_didOpen_notification, server) |
405 |
| - msg_dispatcher[textDocument_didClose_notification_type] = request_wrapper(textDocument_didClose_notification, server) |
406 |
| - msg_dispatcher[textDocument_didSave_notification_type] = request_wrapper(textDocument_didSave_notification, server) |
407 |
| - msg_dispatcher[textDocument_willSave_notification_type] = request_wrapper(textDocument_willSave_notification, server) |
| 427 | + msg_dispatcher[julia_activateenvironment_notification_type] = notification_wrapper(julia_activateenvironment_notification, server) |
| 428 | + msg_dispatcher[textDocument_didOpen_notification_type] = notification_wrapper(textDocument_didOpen_notification, server) |
| 429 | + msg_dispatcher[textDocument_didClose_notification_type] = notification_wrapper(textDocument_didClose_notification, server) |
| 430 | + msg_dispatcher[textDocument_didSave_notification_type] = notification_wrapper(textDocument_didSave_notification, server) |
| 431 | + msg_dispatcher[textDocument_willSave_notification_type] = notification_wrapper(textDocument_willSave_notification, server) |
408 | 432 | msg_dispatcher[textDocument_willSaveWaitUntil_request_type] = request_wrapper(textDocument_willSaveWaitUntil_request, server)
|
409 |
| - msg_dispatcher[textDocument_didChange_notification_type] = request_wrapper(textDocument_didChange_notification, server) |
410 |
| - msg_dispatcher[workspace_didChangeWatchedFiles_notification_type] = request_wrapper(workspace_didChangeWatchedFiles_notification, server) |
411 |
| - msg_dispatcher[workspace_didChangeConfiguration_notification_type] = request_wrapper(workspace_didChangeConfiguration_notification, server) |
412 |
| - msg_dispatcher[workspace_didChangeWorkspaceFolders_notification_type] = request_wrapper(workspace_didChangeWorkspaceFolders_notification, server) |
| 433 | + msg_dispatcher[textDocument_didChange_notification_type] = notification_wrapper(textDocument_didChange_notification, server) |
| 434 | + msg_dispatcher[workspace_didChangeWatchedFiles_notification_type] = notification_wrapper(workspace_didChangeWatchedFiles_notification, server) |
| 435 | + msg_dispatcher[workspace_didChangeConfiguration_notification_type] = notification_wrapper(workspace_didChangeConfiguration_notification, server) |
| 436 | + msg_dispatcher[workspace_didChangeWorkspaceFolders_notification_type] = notification_wrapper(workspace_didChangeWorkspaceFolders_notification, server) |
413 | 437 | msg_dispatcher[workspace_symbol_request_type] = request_wrapper(workspace_symbol_request, server)
|
414 |
| - msg_dispatcher[julia_refreshLanguageServer_notification_type] = request_wrapper(julia_refreshLanguageServer_notification, server) |
| 438 | + msg_dispatcher[julia_refreshLanguageServer_notification_type] = notification_wrapper(julia_refreshLanguageServer_notification, server) |
415 | 439 | msg_dispatcher[julia_getDocFromWord_request_type] = request_wrapper(julia_getDocFromWord_request, server)
|
416 | 440 | msg_dispatcher[textDocument_selectionRange_request_type] = request_wrapper(textDocument_selectionRange_request, server)
|
417 | 441 | msg_dispatcher[textDocument_documentLink_request_type] = request_wrapper(textDocument_documentLink_request, server)
|
|
0 commit comments