expert icon indicating copy to clipboard operation
expert copied to clipboard

FunctionClauseError when format in zed

Open Ljzn opened this issue 4 months ago • 2 comments

2025-09-05T22:22:48+08:00 WARN  [project::lsp_store] Get code actions via expert failed: ** (FunctionClauseError) no function clause matching in XPExpert.Protocol.Conversions.to_elixir/2
    (xp_expert 0.1.0-3f5914a) lib/expert/protocol/conversions.ex:22: XPExpert.Protocol.Conversions.to_elixir(%XPGenLSP.Structures.Range{end: %XPGenLSP.Structures.Position{character: 3, line: 80}, start: %XPGenLSP.Structures.Position{character: 3, line: 80}}, nil)
    (xp_forge 0.1.0-3f5914a) lib/forge/protocol/convertible.ex:52: anonymous fn/4 in XPForge.Protocol.Convertible.Helpers.apply/3
    (elixir 1.17.3) lib/enum.ex:4858: Enumerable.List.reduce/3
    (elixir 1.17.3) lib/enum.ex:2585: Enum.reduce_while/3
    (xp_forge 0.1.0-3f5914a) lib/forge/protocol/convertible.ex:182: XPForge.Protocol.Convertible.Any.to_native/2
    (xp_expert 0.1.0-3f5914a) lib/expert/protocol/convert.ex:22: XPExpert.Protocol.Convert.to_native/1
    (xp_expert 0.1.0-3f5914a) lib/expert.ex:93: XPExpert.handle_request/2
    (xp_gen_lsp 0.11.0) lib/gen_lsp.ex:372: anonymous fn/2 in XPGenLSP.loop/3

2025-09-05T22:22:48+08:00 ERROR [project] Get code actions via expert failed: ** (FunctionClauseError) no function clause matching in XPExpert.Protocol.Conversions.to_elixir/2
    (xp_expert 0.1.0-3f5914a) lib/expert/protocol/conversions.ex:22: XPExpert.Protocol.Conversions.to_elixir(%XPGenLSP.Structures.Range{end: %XPGenLSP.Structures.Position{character: 3, line: 80}, start: %XPGenLSP.Structures.Position{character: 3, line: 80}}, nil)
    (xp_forge 0.1.0-3f5914a) lib/forge/protocol/convertible.ex:52: anonymous fn/4 in XPForge.Protocol.Convertible.Helpers.apply/3
    (elixir 1.17.3) lib/enum.ex:4858: Enumerable.List.reduce/3
    (elixir 1.17.3) lib/enum.ex:2585: Enum.reduce_while/3
    (xp_forge 0.1.0-3f5914a) lib/forge/protocol/convertible.ex:182: XPForge.Protocol.Convertible.Any.to_native/2
    (xp_expert 0.1.0-3f5914a) lib/expert/protocol/convert.ex:22: XPExpert.Protocol.Convert.to_native/1
    (xp_expert 0.1.0-3f5914a) lib/expert.ex:93: XPExpert.handle_request/2
    (xp_gen_lsp 0.11.0) lib/gen_lsp.ex:372: anonymous fn/2 in XPGenLSP.loop/3

env

os: Mac editor: zed

Ljzn avatar Sep 05 '25 14:09 Ljzn

Different error, but similar "fail on format" experience for me.

Seems to pop up randomly -- and affects whole session from that point on.

In the LSP RPC, I observe 'it tries to format, and then cancels the request 5s later':

// Send:
{"jsonrpc":"2.0","id":5493,"method":"textDocument/formatting","params":{"textDocument":{"uri":"file:///Users/mrluc/projects/ex/make_together/lib/make_together_web/live/sec_live/index.ex"},"options":{"tabSize":2,"insertSpaces":true,"trimTrailingWhitespace":true,"insertFinalNewline":true,"trimFinalNewlines":true}}}

// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":5493}}

And the reason it's not getting the response back is the error:

** (FunctionClauseError) no function clause matching in XPForge.Ast.Tokens.get_start_pos/1
    (xp_forge 0.1.0-db67ba9) XPForge.Ast.Tokens.get_start_pos([{:"(", {52, 37, nil}}, {:alias, {52, 38, ~c"String"}, :String}, {:., {52, 44, nil}}, {:paren_identifier, {52, 45, ~c"length"}, :length}, {:"(", {52, 51, nil}}, {:at_op, {52, 52, nil}, :@}, {:identifier, {52, 53, ~c"ticker"}, :ticker}, {:")", {52, 59, nil}}, {:rel_op, {52, 61, nil}, :<}, {:int, {52, 63, 4}, ~c"4"}, {:")", {52, 64, nil}}, {:and_op, {52, 66, nil}, :&&}, {:bin_string, {52, 69, nil}, ["btn-disabled"]}])
    (xp_forge 0.1.0-db67ba9) lib/forge/ast/tokens.ex:158: anonymous fn/2 in XPForge.Ast.Tokens.interpolation_ranges/1
    (elixir 1.17.3) lib/enum.ex:2531: Enum."-reduce/3-lists^foldl/2-0-"/3
...

mrluc avatar Sep 05 '25 16:09 mrluc

Aaaaaaaand restarting the language servers from the UI in Zed also fixes it! For me anyway, YMMV.

mrluc avatar Sep 05 '25 16:09 mrluc

Same here. I installed expert and I had a similar error which was affecting the session and making the LSP unusable. Restarting the LSP server fixed it.

Btw, using neovim, i could restart it via :LspRestart .

Thanks for the great work ❤️

nickgnd avatar Sep 09 '25 08:09 nickgnd

@doorgan please check if this can be closed.

mhanberg avatar Nov 15 '25 18:11 mhanberg

I think this can be closed, I've been using code actions and formatting all the time lately. I think this was also caused by distribution issues, the document is missing on those stacktraces so the server can't convert anything.

doorgan avatar Nov 15 '25 18:11 doorgan