lexical-lsp / lexical

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

Lexical crash when typing capital letter after lowercase word with period #741

Closed nshafer closed 1 month ago

nshafer commented 1 month ago

OK this is a weird one. If you type a capital letter after a lowercase word followed by a period, lexical crashes and I get the "Request testDocument/completion failed" error popup in vs code. Example:

This is a test. I|

It doesn't seem to happen for non-lowercase words, such as:

This is Fine. I can keep typing with no crash.

The error that is shown in View->Output is:

2024-05-15 15:45:48.333 [info] [Error - 3:45:48 PM] Request textDocument/completion failed.
2024-05-15 15:45:48.334 [info]   Message: ** (CaseClauseError) no case clause matching: {:alias, {:local_or_var, ~c"test"}, ~c"I"}
    (lx_server 0.5.0) lib/lexical/server/code_intelligence/completion/builder.ex:107: LXical.Server.CodeIntelligence.Completion.Builder.prefix_length/1
    (lx_server 0.5.0) lib/lexical/server/code_intelligence/completion/builder.ex:101: LXical.Server.CodeIntelligence.Completion.Builder.prefix_range/1
    (lx_server 0.5.0) lib/lexical/server/code_intelligence/completion/builder.ex:34: LXical.Server.CodeIntelligence.Completion.Builder.plain_text/3
    (lx_server 0.5.0) lib/lexical/server/code_intelligence/completion/translations/module_or_behaviour.ex:112: LXical.Server.CodeIntelligence.Completion.Translations.ModuleOrBehaviour.completion/4
    (lx_server 0.5.0) lib/lexical/server/code_intelligence/completion.ex:170: LXical.Server.CodeIntelligence.Completion.to_completion_item/2
    (lx_server 0.5.0) lib/lexical/server/code_intelligence/completion.ex:163: anonymous fn/5 in LXical.Server.CodeIntelligence.Completion.to_completion_items/4
    (elixir 1.15.6) lib/enum.ex:2510: Enum."-reduce/3-lists^foldl/2-0-"/3
    (lx_server 0.5.0) lib/lexical/server/code_intelligence/completion.ex:159: LXical.Server.CodeIntelligence.Completion.to_completion_items/4

  Code: -32603 

This is on main as of e74ceeca3421bfc9c46296a5f648ba08797ec0cd compiled with:

elixir          1.14.5-otp-25
erlang          25.3.2.10

I hit this while just typing sentences in a .heex file, but I can duplicate it in an .ex file if it's not in a string or comment. I think that's just not a thing anyone does since it's not valid code.

It can be duplicated in any file I think. I duplicated it in a mix new project. LMK if you need more info.

scohen commented 1 month ago

Confirmed