Skip to content

Commit 910211e

Browse files
authored
Merge pull request #1340 from julia-vscode/update-jsonrpc-v2
Update to JSONRPC.jl v2
2 parents fdcd7bf + 86b0543 commit 910211e

File tree

4 files changed

+41
-23
lines changed

4 files changed

+41
-23
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
2323
[compat]
2424
CSTParser = "3.3"
2525
JSON = "0.20, 0.21"
26-
JSONRPC = "1.1"
26+
JSONRPC = "2"
2727
JuliaFormatter = "1"
2828
PrecompileTools = "1"
2929
StaticLint = "8.0"

src/languageserverinstance.jl

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,30 @@ end
286286
const USE_REVISE = Ref(false)
287287

288288
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)
289313
return function (conn, params)
290314
if server.shutdown_requested
291315
# it's fine to always return a value here, even for notifications, because
@@ -394,24 +418,24 @@ function Base.run(server::LanguageServerInstance; timings = [])
394418
msg_dispatcher[julia_getDocAt_request_type] = request_wrapper(julia_getDocAt_request, server)
395419
msg_dispatcher[textDocument_hover_request_type] = request_wrapper(textDocument_hover_request, server)
396420
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)
398422
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)
402426
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)
408432
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)
413437
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)
415439
msg_dispatcher[julia_getDocFromWord_request_type] = request_wrapper(julia_getDocFromWord_request, server)
416440
msg_dispatcher[textDocument_selectionRange_request_type] = request_wrapper(textDocument_selectionRange_request, server)
417441
msg_dispatcher[textDocument_documentLink_request_type] = request_wrapper(textDocument_documentLink_request, server)

src/utilities.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ end
488488
end
489489

490490
# some timer utilities
491-
add_timer_message!(did_show_timer, timings, msg::Dict) = add_timer_message!(did_show_timer, timings, string("LSP/", get(msg, "method", "")))
491+
add_timer_message!(did_show_timer, timings, msg::JSONRPC.Request) = add_timer_message!(did_show_timer, timings, string("LSP/", msg.method))
492492
function add_timer_message!(did_show_timer, timings, msg::String)
493493
if did_show_timer[]
494494
return

test/test_communication.jl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,7 @@
5151
}
5252
""")
5353

54-
if Sys.iswindows()
55-
global_socket_name = "\\\\.\\pipe\\julia-language-server-testrun"
56-
elseif Sys.isunix()
57-
global_socket_name = joinpath(tempdir(), "julia-language-server-testrun")
58-
else
59-
error("Unknown operating system.")
60-
end
54+
global_socket_name = JSONRPC.generate_pipe_name()
6155

6256
@async try
6357
server = listen(global_socket_name)

0 commit comments

Comments
 (0)