lexical-lsp / lexical

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

String.starts_with?(nil, "Lexical") textDocument/completion exception #686

Closed nshafer closed 2 months ago

nshafer commented 2 months ago

With lexical compiled from main (07a132ae2d9827f8894bb26bda0a7351fa0912df) with Elixir 1.14.5-otp-25, when typing:

@callback a|

I get a popup from vs code that says, "Request textDocument/completion failed. Source: Lexical (Elixir Language Server)" and this in the output:

2024-04-04 15:06:34.810 [info] [Error - 3:06:34 PM] Request textDocument/completion failed.
2024-04-04 15:06:34.810 [info]   Message: ** (FunctionClauseError) no function clause matching in String.starts_with?/2
    (elixir 1.15.7) lib/string.ex:2392: String.starts_with?(nil, "Lexical")
    (lx_server 0.5.0) lib/lexical/server/code_intelligence/completion.ex:190: anonymous fn/3 in LXical.Server.CodeIntelligence.Completion.displayable?/2
    (elixir 1.15.7) lib/enum.ex:4830: Enumerable.List.reduce/3
    (elixir 1.15.7) lib/enum.ex:2564: Enum.reduce_while/3
    (lx_server 0.5.0) lib/lexical/server/code_intelligence/completion.ex:158: anonymous fn/5 in LXical.Server.CodeIntelligence.Completion.to_completion_items/4
    (elixir 1.15.7) lib/enum.ex:2510: Enum."-reduce/3-lists^foldl/2-0-"/3
    (lx_server 0.5.0) lib/lexical/server/code_intelligence/completion.ex:157: LXical.Server.CodeIntelligence.Completion.to_completion_items/4
    (lx_server 0.5.0) lib/lexical/server/code_intelligence/completion.ex:40: LXical.Server.CodeIntelligence.Completion.complete/4

  Code: -32603 

I was able to duplicate it in multiple projects.

Thanks!

scohen commented 2 months ago

I've been unable to duplicate this given your reproduction steps. What dependencies do you have in the project?

objectuser commented 2 months ago

I'm not sure if this is the only place I get it but I seem to get this same error when I'm creating a @spec. But I don't get it in a new mix new project. But I do get the error in a mix phx.new project! Ah, nice.

2024-04-09 13:55:05.504 [info] [Error - 1:55:05 PM] Request textDocument/completion failed.
2024-04-09 13:55:05.505 [info]   Message: ** (FunctionClauseError) no function clause matching in String.starts_with?/2
    (elixir 1.16.1) lib/string.ex:2517: String.starts_with?(nil, "Lexical")
    (lx_server 0.5.0) lib/lexical/server/code_intelligence/completion.ex:190: anonymous fn/3 in LXical.Server.CodeIntelligence.Completion.displayable?/2
    (elixir 1.16.1) lib/enum.ex:4842: Enumerable.List.reduce/3
    (elixir 1.16.1) lib/enum.ex:2582: Enum.reduce_while/3
    (lx_server 0.5.0) lib/lexical/server/code_intelligence/completion.ex:158: anonymous fn/5 in LXical.Server.CodeIntelligence.Completion.to_completion_items/4
    (elixir 1.16.1) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
    (lx_server 0.5.0) lib/lexical/server/code_intelligence/completion.ex:157: LXical.Server.CodeIntelligence.Completion.to_completion_items/4
    (lx_server 0.5.0) lib/lexical/server/code_intelligence/completion.ex:40: LXical.Server.CodeIntelligence.Completion.complete/4

  Code: -32603 
2024-04-09 13:55:11.771 [info]     error: spec for undefined function foo/2
    │
 10 │   @spec foo(integer(), integer()) :: integer()
    │   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    │
    └─ lib/poo.ex:10

2024-04-09 13:55:11.771 [info] 
== Compilation error in file lib/poo.ex ==
** (CompileError) lib/poo.ex: cannot compile file (errors have been logged)
    (stdlib 5.2) lists.erl:1594: :lists.foldl/3

Is that helpful at all?

scohen commented 2 months ago

Yes, I can reproduce this now. Thanks. Pretty easy error to fix, actually, but a tough one to exercise. ElixirSense is returning nil for the origin, which is quite annoying.

nshafer commented 2 months ago

Just want to verify this is fixed. Thanks!