lexical-lsp / lexical

Lexical is a next-generation elixir language server
781 stars 77 forks source link

Unsaved text buffers in vscode crash Lexical #641

Closed Moosieus closed 3 months ago

Moosieus commented 4 months ago

Relevant log, note the second parameter which should be %State{} is nil:

18:45:30.371 [error] GenServer LXical.Server terminating
** (FunctionClauseError) no function clause matching in LXical.Server.Provider.Queue.add/2
    (lx_server 0.5.0) lib/lexical/server/provider/queue.ex:154: LXical.Server.Provider.Queue.add(%LXical.Protocol.Requests.CodeLens{lsp: %LXical.Protocol.Requests.CodeLens.LSP{id: 68, jsonrpc: "2.0", method: "textDocument/codeLens", partial_result_token: nil, text_document: #Protocol.Types.TextDocument.Identifier<[uri: "untitled:Untitled-1"]>, work_done_token: nil}, document: nil, id: 68, jsonrpc: "2.0", method: "textDocument/codeLens", partial_result_token: nil, text_document: nil, work_done_token: nil}, nil)
    (lx_server 0.5.0) lib/lexical/server.ex:144: LXical.Server.handle_message/2
    (lx_server 0.5.0) lib/lexical/server.ex:67: LXical.Server.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", {:protocol_message, %LXical.Protocol.Requests.CodeLens{lsp: %LXical.Protocol.Requests.CodeLens.LSP{id: 68, jsonrpc: "2.0", method: "textDocument/codeLens", partial_result_token: nil, text_document: #Protocol.Types.TextDocument.Identifier<[uri: "untitled:Untitled-1"]>, work_done_token: nil}, document: nil, id: 68, jsonrpc: "2.0", method: "textDocument/codeLens", partial_result_token: nil, text_document: nil, work_done_token: nil}}}
State: %LXical.Server.State{configuration: nil, initialized?: false, shutdown_received?: false, in_flight_requests: %{}}

The URI appears as untitled:Untitled-1.

So far as I can immediately tell, these unsaved files are sent over as textDocument/didOpen notifications, followed by relevant textDocument/didChange events when edits are made:

2024-03-04 18:45:29.999 [info] [Trace - 6:45:29 PM] Sending notification 'textDocument/didOpen'.
2024-03-04 18:45:30.000 [info] Params: {
    "textDocument": {
        "uri": "untitled:Untitled-1",
        "languageId": "elixir",
        "version": 2,
        "text": "defmodule MyServer do\n    use GenServer\n    def handle_inf\nend"
    }
}
2024-03-04 18:50:06.864 [info] [Trace - 6:50:06 PM] Sending notification 'textDocument/didChange'.
2024-03-04 18:50:06.864 [info] Params: {
    "textDocument": {
        "uri": "untitled:Untitled-1",
        "version": 3
    },
    "contentChanges": [
        {
            "range": {
                "start": {
                    "line": 2,
                    "character": 18
                },
                "end": {
                    "line": 2,
                    "character": 18
                }
            },
            "rangeLength": 0,
            "text": "o"
        }
    ]
}
scohen commented 3 months ago

This is more of a symptom, the actual crash happened prior to this. Check the logs.