Crash with invalid JSON
After some while of working (usually about 30 to 60 minutes) next-ls crashes and can not recover.
After some digging I found the following logs in .elixir-tools/next-ls.log, but not in the "Next LS" output pane of VS Code, I am therefore unsure whether this is a problem of the VScode plugin or NextLS.
14:36:33.638 [error] GenServer NextLS.Buffer terminating
** (Jason.DecodeError) unexpected end of input at position 286
(jason 1.4.1) lib/jason.ex:92: Jason.decode!/2
(gen_lsp 0.10.0) lib/gen_lsp/buffer.ex:87: anonymous fn/3 in GenLSP.Buffer.handle_cast/2
(telemetry 1.2.1) /Users/runner/work/next-ls/next-ls/deps/telemetry/src/telemetry.erl:321: :telemetry.span/3
(gen_lsp 0.10.0) lib/gen_lsp/buffer.ex:85: GenLSP.Buffer.handle_cast/2
(stdlib 5.2) gen_server.erl:1121: :gen_server.try_handle_cast/3
(stdlib 5.2) gen_server.erl:1183: :gen_server.handle_msg/6
(stdlib 5.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
Last message: {:"$gen_cast", {:incoming, "\n{\"jsonrpc\":\"2.0\",\"id\":1112,\"method\":\"textDocument/completion\",\"params\":{\"textDocument\":{\"uri\":\"file:///home/nmelzer/Projects/BravoBike/**redacted****/apps/frontend/lib/frontend/live/**redacted****/overview.ex\"},\"position\":{\"line\":141,\"character\":21},\"context\":{\"triggerKind\":1}}"}}
State: %{lsp: #PID<0.256.0>, awaiting_response: %{}, comm_data: nil, comm: GenLSP.Communication.Stdio}
In fact the JSON snippet seen in the last message looks like this after clean up:
{
"jsonrpc":"2.0",
"id":1112,
"method":"textDocument/completion",
"params":{
"textDocument":{
"uri":""file:///home/nmelzer/Projects/BravoBike/**redacted****/apps/frontend/lib/frontend/live/**redacted****/overview.ex"
},
"position":{
"line":141,
"character":21
},
"context":{
"triggerKind":1
}
}
So there is a closing curly brace missing.
This is a GenLSP (the framework that Next LS uses for LSP protocol stuff) issue, not the vscode extension issue
I have seen this a couple of times, but haven't been able to reproduce. Its unclear to me if under the hood we are not executing the protocol correctly, or if the editor is sending the wrong Content-Length header.
The fact that it starts with a new line implies to me that an extra new line was sent or a new line was not properly consumed on the last message, so then it offset the payload by a character
Can I somehow increase log verbosity to perhaps see massages as they get created and consumed?
In the VScode extension you can set one of the next LS options to trace and it'll print out a lot more stuff.