Skip to content

Conversation

@katafrakt
Copy link
Contributor

Closes #269

The full-module notation (<MyMod.button>) was already supported in "go to definition", because when passed to ElixirSense, it correctly recognized the form and found the appropriate module and the function. However, with a shorthand notation it was not so simple, because .button is not valid Elixir and ElixirSense was not able to make anything of it.

This implements the support for shorthand notation by doing a preliminary step before sending the code to ElixirSense. It modifies the AST and the Document of ForgeAnalysis and replaces all the calls to <.button> with < button(assigns) so that ElixirSense can correctly interpret it as a local function call with arity 1. This only happens when phoenix_live_view is added as a dependency1.

This works for functions defined in the same module, but also for imported functions. Support for ending tag is also included.

While this might seem as a hacky solution, it makes handling shorthand notation as close as possible to handling the full-module notation, making sure these two stay conceptually close.

Footnotes

  1. I looked into making a more detailed check here, basically checking if Phoenix.Component is imported into current module, but there's just too many ways to do so. I don't think the code analysis can do that, we would need to actually compile the code (using ElixirSense?). But I settled for a much simpler condition in this case.

The full-module notation (`<MyMod.button>`) was already supported in "go
to definition", because when passed to ElixirSense, it correctly
recognized the form and found the appropriate module and the function.
However, with a shorthand notation it was not so simple, because
`.button` is not valid Elixir and ElixirSense was not able to make
anything of it.

This implements the support for shorthand notation by doing a
preliminary step before sending the code to ElixirSense. It modifies the
AST and the Document of ForgeAnalysis and replaces all the calls to
`<.button>` with `< button(assigns)` so that ElixirSense can correctly
interpret it as a local function call with arity 1.

This works for functions defined in the same module, but also for
imported functions. Support for ending tag is also included.

While this might seem as a hacky solution, it makes handling shorthand
notation as close as possible to handling the full-module notation,
making sure these two stay conceptually close.
The testing happens in Engine and there the presence of LiveView is mocked.
@katafrakt katafrakt changed the title Support jump to definition in HEEx templates feat(engine): support shorthand notation inside ~H sigil Dec 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Jump to definition in HEEx templates

1 participant