next-ls icon indicating copy to clipboard operation
next-ls copied to clipboard

Crash with invalid JSON

Open NobbZ opened this issue 1 year ago • 5 comments

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.

NobbZ avatar Jun 12 '24 12:06 NobbZ

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.

mhanberg avatar Jun 12 '24 13:06 mhanberg

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

mhanberg avatar Jun 12 '24 13:06 mhanberg

Can I somehow increase log verbosity to perhaps see massages as they get created and consumed?

NobbZ avatar Jun 12 '24 13:06 NobbZ

In the VScode extension you can set one of the next LS options to trace and it'll print out a lot more stuff.

mhanberg avatar Jun 12 '24 14:06 mhanberg

CleanShot 2024-06-12 at 10 43 02@2x

mhanberg avatar Jun 12 '24 14:06 mhanberg