lexical-lsp / lexical

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

Erlang error :case_clause when typing '@' before `@callback` lines #690

Closed nshafer closed 2 months ago

nshafer commented 2 months ago

While testing the resolution of #686 I ran across another crash with "Request testDocument/documentSystem failed" error in vs code. Like #686 this is in a new phoenix project. The error happens when typing a '@' on a new line before an existing @callback line. It doesn't happen when you type after the existing @callback.

defmodule Myapp.Backend do
  @|
  @callback test() :: :ok
end

The error:

2024-04-10 11:01:12.527 [info] [Error - 11:01:12 AM] Request textDocument/documentSymbol failed.
2024-04-10 11:01:12.527 [info]   Message: ** (ErlangError) Erlang error: {:exception, {:case_clause, ["Elixir.Myapp.Backend", "", ""]}, [{LXical.RemoteControl.CodeIntelligence.Symbols.Document, :name_and_type, 3, [file: ~c"lib/lexical/remote_control/code_intelligence/symbols/document.ex", line: 46]}, {LXical.RemoteControl.CodeIntelligence.Symbols.Document, :from, 3, [file: ~c"lib/lexical/remote_control/code_intelligence/symbols/document.ex", line: 9]}, {LXical.RemoteControl.CodeIntelligence.Symbols, :"-rebuild_structure/3-fun-1-", 3, [file: ~c"lib/lexical/remote_control/code_intelligence/symbols.ex", line: 64]}, {Enum, :flat_map_list, 2, [file: ~c"lib/enum.ex", line: 4317]}, {LXical.RemoteControl.CodeIntelligence.Symbols, :"-rebuild_structure/3-fun-1-", 3, [file: ~c"lib/lexical/remote_control/code_intelligence/symbols.ex", line: 47]}, {Enum, :flat_map_list, 2, [file: ~c"lib/enum.ex", line: 4317]}, {LXical.RemoteControl.CodeIntelligence.Symbols, :for_document, 1, []}]}
    (kernel 9.1) erpc.erl:702: :erpc.call/5
    (lx_server 0.5.0) lib/lexical/server/provider/handlers/document_symbols.ex:16: LXical.Server.Provider.Handlers.DocumentSymbols.handle/2
    (lx_server 0.5.0) lib/lexical/server/provider/queue.ex:99: anonymous fn/2 in LXical.Server.Provider.Queue.State.as_task/2
    (elixir 1.15.6) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2
    (elixir 1.15.6) lib/task/supervised.ex:36: Task.Supervised.reply/4

  Code: -32603 

Steps to reproduce:

This also seems to happen with @spec instead of @callback.

This happened prior to commit db866eff38ad66dc6182605f4aaa3cd1309c1edc that fixed #686, as well as after that commit. So I think it's a different bug, just somewhat related because it deals with type specs.

Thanks!