lexical-lsp / lexical

Lexical is a next-generation elixir language server
874 stars 80 forks source link

Undefined function in .html.heex files #639

Closed crbelaus closed 5 months ago

crbelaus commented 7 months ago

I am noticing a weird behaviour on Heex files. When I open any file and save I get a error on the first function call saying:

undefined function WHATEVER_FUNCTION (there is no such import)

I can consistently replicate this behaviour on a brand new Phoenix project. I ran the following command to create the project:

mix phx.new --no-ecto example

Then, navigated to the project root, ran mix do deps.get, compile and confirmed that it compiles cleanly.

$ mix compile --force --warnings-as-errors
Compiling 14 files (.ex)
Generated example app

When I open lib/example_web/controllers/page_html/home.html.heex in my editor (VSCode) and just save it I get the error mentioned above. It is interesting that the LSP works fine regardless including formatter, autocompletion and whatnot.

image

Not sure if this is a problem in Lexical or in the VSCode extension, so feel free to move the issue where it is more appropriate.

crbelaus commented 7 months ago

Just want to add that, if I call any function above the first error it disappears and shows in the new function call instead. For example:

image

crbelaus commented 6 months ago

In case anyone has the same problem. This has been discussed on #495 where it is explained that the autoformatting is causing this problem.

When you save the file it triggers a project recompilation. Then, the autoformat triggers a file recompilation which doesn't have enough information to figure out what functions have been imported in the HEEx template, causing the problems described above.

The immediate remedy to avoid this problems is to disable autoformat in your code editor.

scohen commented 5 months ago

Fixed by #662

Moosieus commented 5 months ago

As-you-type completions are disabled in heex for now, until we can create the environment scottming indicated here.