elixir-lsp / elixir-lsp/elixir-ls

False positive ArgumentError for ColocatedHook macro component in .heex templates

Open
#1,256 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Elixir
Stars
1.8k
Forks
227
Avg merge
31m
Merged PRs (30d)
2

Description

## Environment

- ElixirLS: 0.30.0
- Elixir: 1.19.5
- Erlang/OTP: 28
- Phoenix LiveView: 1.1.25
- Editor: Zed

## Description

ElixirLS reports an `ArgumentError` diagnostic in `.html.heex` template files that use `` (macro components introduced in LiveView 1.1 via [PR #3810](https://github.com/phoenixframework/phoenix_live_view/pull/3810)).

The error appears at line 1 of the template:

```
** (ArgumentError) macro components are only supported in modules that `use Phoenix.Component`
(phoenix_live_view 1.1.25) lib/phoenix_live_view/tag_engine.ex:894: Phoenix.LiveView.TagEngine.handle_macro_component/3
(phoenix_live_view 1.1.25) lib/phoenix_live_view/tag_engine.ex:250: Phoenix.LiveView.TagEngine.handle_body/1
(language_server 0.30.0) lib/language_server/parser.ex:499: anonymous fn/3 in ElixirLS.LanguageServer.Parser.parse_file/3
```

The project compiles cleanly with `mix compile --force` (no warnings or errors).

## Reproduction

1. Create a Phoenix LiveView module with `use Phoenix.LiveView` (or via a helper like `use MyAppWeb, :live_view`)
2. In its colocated `.html.heex` template, add a colocated hook:

```heex
<div id="my-element" phx-hook=".MyHook">
<script :type={Phoenix.LiveView.ColocatedHook} name=".MyHook">
export default {
mounted() { console.log("mounted") }
}

```

3. ElixirLS reports the `ArgumentError` on line 1, even though `mix compile` succeeds

## Expected behavior

No diagnostic error, since the template compiles successfully.

## Actual behavior

ElixirLS shows the `ArgumentError` as a diagnostic in the editor.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.