lexical-lsp / lexical

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

Exception when hovering functions/assigns in heex templates #693

Closed nshafer closed 2 months ago

nshafer commented 2 months ago

Compiled on main commit 1e00d8e5de0326062c8283a142043d7d83bae620 but it also happened on the 927cb89135fe96b7e4b7d41cca4955a3a5e27f29 commit, compiled with mix package on elixir 1.14.5-otp-25.

When hovering over function calls or assigns in heex templates, a "Request testDocument/hover failed" error is thrown up in VS Code. It does not seem to affect function calls that have a Module prefix, like Application.spec(:phoenix, :vsn) This is logged in the Output panel as well as in lexical.log:

2024-04-12 14:58:03.850 [info] [Error - 2:58:03 PM] Request textDocument/hover failed.
2024-04-12 14:58:03.850 [info]   Message: ** (ErlangError) Erlang error: {:exception, {:badmatch, :error}, [{LXical.RemoteControl.CodeIntelligence.Entity, :resolve, 4, [file: ~c"lib/lexical/remote_control/code_intelligence/entity.ex", line: 157]}, {LXical.RemoteControl.CodeIntelligence.Entity, :resolve, 2, [file: ~c"lib/lexical/remote_control/code_intelligence/entity.ex", line: 36]}]}
    (kernel 9.1) erpc.erl:702: :erpc.call/5
    (lx_server 0.5.0) lib/lexical/server/provider/handlers/hover.ex:21: LXical.Server.Provider.Handlers.Hover.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:

  1. Create a new phoenix project with mix phx.new myapp
  2. Open "lib/myapp_web/components/layouts/root.html.heex" (and also app.html.heex)
  3. Hover mouse cursor over any @variable assigns or function calls, such as get_csrf_token() on line 6 or @inner_content on line 15.

Thanks!