Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request textDocument/completion failed #805

Closed
sb8244 opened this issue Jul 30, 2024 · 17 comments
Closed

request textDocument/completion failed #805

sb8244 opened this issue Jul 30, 2024 · 17 comments

Comments

@sb8244
Copy link

sb8244 commented Jul 30, 2024

I'm receiving the following error every time I modify an Elixir file.

I traced this down to some code that I don't think should be running—a call to Code.Identifier.classify? It has a version match for Elixir 1.14, and I'm on 1.15.7.

I did not see this error until the latest lexical update.

iex(19)> Version.match?(System.version(), ">= 1.14.0-dev")
true
2024-07-30 02:31:37.099 [info] [Error - 2:31:37 AM] Request textDocument/completion failed.
2024-07-30 02:31:37.099 [info]   Message: ** (ErlangError) Erlang error: {:exception, :undef, [{Code.Identifier, :classify, [:idna], []}, {LXElixirSense.Providers.Completion.CompletionEngine, :usable_as_unquoted_module?, 1, [file: ~c"lib/elixir_sense/providers/completion/completion_engine.ex", line: 864]}, {LXElixirSense.Providers.Completion.CompletionEngine, :"-match_erlang_modules/3-fun-0-", 2, [file: ~c"lib/elixir_sense/providers/completion/completion_engine.ex", line: 562]}, {Enum, :"-reduce/3-lists^foldl/2-0-", 3, [file: ~c"lib/enum.ex", line: 2510]}, {LXElixirSense.Providers.Completion.CompletionEngine, :match_erlang_modules, 3, [file: ~c"lib/elixir_sense/providers/completion/completion_engine.ex", line: 561]}, {LXElixirSense.Providers.Completion.CompletionEngine, :expand_erlang_modules, 3, [file: ~c"lib/elixir_sense/providers/completion/completion_engine.ex", line: 557]}, {LXElixirSense.Providers.Completion.Reducers.CompleteEngine, :populate, 6, [file: ~c"lib/elixir_sense/providers/completion/reducers/complete_engine.ex", line: 32]}, {Enumerable.List, :reduce, 3, [file: ~c"lib/enum.ex", line: 4830]}]}
    (kernel 9.1) erpc.erl:702: :erpc.call/5
    (lx_server 0.5.0) lib/lexical/server/code_intelligence/completion.ex:73: LXical.Server.CodeIntelligence.Completion.completions/3
    (lx_server 0.5.0) lib/lexical/server/code_intelligence/completion.ex:38: LXical.Server.CodeIntelligence.Completion.complete/4
    (lx_server 0.5.0) lib/lexical/server/provider/handlers/completion.ex:15: LXical.Server.Provider.Handlers.Completion.handle/2
    (lx_server 0.5.0) lib/lexical/server/task_queue.ex:77: anonymous fn/4 in LXical.Server.TaskQueue.State.as_task/2
    (elixir 1.15.7) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2
    (elixir 1.15.7) lib/task/supervised.ex:36: Task.Supervised.reply/4

  Code: -32603 
@zachallaun
Copy link
Collaborator

Thanks for the report!

Lexical runs a second node that runs your project code, and it's theoretically possible that it was started with a different version of Elixir than the 1.15.7 that's visible in your stacktrace (that's from the server node).

To confirm this, I'd really appreciate it if you could follow these steps;

  1. Clone Lexical locally
  2. Open a single editor/project running Lexical
  3. In your terminal, cd into the cloned repo and run ./bin/debug_shell.sh - (this should open up an IEx shell with a prompt that looks something like iex([email protected])>)
  4. Run this command and report the result: LXical.RemoteControl.call(current_project(), System, :version, [])

@sb8244
Copy link
Author

sb8244 commented Jul 30, 2024

I get an error when I run that:

➜  lexical git:(main) ./bin/debug_shell.sh
Erlang/OTP 26 [erts-14.1.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]

Interactive Elixir (1.15.7) - press Ctrl+C to exit (type h() ENTER for help)
iex([email protected])1> LXical.RemoteControl.call(current_project(), System, :version, [])
** (CompileError) cannot compile code (errors have been logged)

@sb8244
Copy link
Author

sb8244 commented Jul 30, 2024

I was able to get it running by manually including the helpers. The response is 1.15.7:

iex([email protected])2> use LXical.Server.IEx.Helpers
{:ok, #PID<0.2240.0>}
iex([email protected])3> LXical.RemoteControl.call(current_project(), System, :version, [])
"1.15.7"

@zachallaun
Copy link
Collaborator

Thanks for that. I may know what's going on. Could you drop into that debug shell one more time and run this? LXical.VM.Versions.compiled()

@sb8244
Copy link
Author

sb8244 commented Jul 30, 2024

Your intuition appears correct @zachallaun :

iex([email protected])4> LXical.VM.Versions.compiled()
{:ok, %{erlang: "24.3.4.12", elixir: "1.13.4"}}

@zachallaun
Copy link
Collaborator

@sb8244 Thanks! I think this will require a fix in ElixirSense and am working on a PR for that now. When that's merged, we'll bump the dependency and get a patch release out!

In the meantime, to fix this, you can build Lexical yourself on Elixir >= 1.14 and use that version following the installation instructions for your editor.

@sb8244
Copy link
Author

sb8244 commented Jul 31, 2024

Thanks, I was able to get that running locally 👍

I appreciate your help!

@scohen
Copy link
Collaborator

scohen commented Aug 8, 2024

@sb8244 We've updated elixir_sense, can you pull main and confirm this is fixed for you?

@sb8244
Copy link
Author

sb8244 commented Aug 14, 2024

I can confirm no issues in the past week! Cheers.

@sb8244 sb8244 closed this as completed Aug 14, 2024
@sb8244
Copy link
Author

sb8244 commented Aug 14, 2024

Actually, this is happening still. I will make sure everything is up to date. Re-opening.

@scohen were you asking me to pull main and then do a custom build to test it out? Because doing a custom build fixed the issue even without a code change, so I don't think that would be a sufficient test.

@sb8244 sb8244 reopened this Aug 14, 2024
@scohen
Copy link
Collaborator

scohen commented Aug 14, 2024

I'm confused, @sb8244 you don't have the issue, but you're reopening?

@sb8244
Copy link
Author

sb8244 commented Aug 14, 2024

See my second comment @scohen . I thought it was not happening because autocomplete was working earlier. Then I was updating an Elixir file and every key stroke resulted in the error message popping up with the same error in output.

I think it may only happen in certain situations, and I mixed myself up.

@sb8244
Copy link
Author

sb8244 commented Aug 14, 2024

To be clear, this is the release version that's failing for me and not main branch of the repo. Generating the bin locally worked even before the fix, so I don't think that's a way for me to test if it's working.

@scohen
Copy link
Collaborator

scohen commented Aug 14, 2024

That's because the released version is compiled on elixir 1.13, and the version you build yourself is compiled on whatever version of elixir you have installed. The problem will only surface when lexical is compiled on 1.14 or earlier and run on 1.15 or later, which is why it resolved when you compiled without the change.

With the change, we removed the compile-time check in favor of a runtime check, so this can't happen.

@scohen
Copy link
Collaborator

scohen commented Aug 14, 2024

I've released 0.7.1 that includes this fix, you can update to that and close if the issue is gone.

@sb8244
Copy link
Author

sb8244 commented Aug 14, 2024

Yes I'm excited to test that out.

I apologize but I'm a bit unsure of what I should do to test out the new version. I thought it would be a VSCode release, although that's on 0.0.18, so my gut tells me that's not it.

@sb8244
Copy link
Author

sb8244 commented Aug 14, 2024

Aha!

I saw the 0.7.1 release come through the lexical extension once I disabled my custom override and reloaded VSCode. I tested the same thing that broke before the release and it's now working.

So I will call this closed for real. Thanks @scohen!

@sb8244 sb8244 closed this as completed Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants