Skip to content

Jump to definition in HEEx templates #269

@katafrakt

Description

@katafrakt

At @Jump-App one of the most longed for features in Expert was ability to jump to definition in HEEx templates, when clicking on components. This works in cases like this:

~H"""
<MyComponents.my_button>Submit</MyComponents.my_button>
"""

... but not when using a "shorthand notation", i.e.:

import MyComponents

~H"""
<.my_button>Submit</.my_button>
"""

The reason why the former works is IIRC because ElixirSense interprets MyComponenets.my_button correctly as a function call, but obviously .my_button cannot be interpreted like a correct Elixir code.

I made a change to Expert that adds a "normalization" step for contents of ~H sigil, which detects the shorthand notation and replaces it as my_button(assigns) before sending to ElixirSense. You can see the change here (this is a PR against my fork). We released Expert binaries with this change internally and several people reported go to definition working just fine with it.

Now, we would like to upstream it. But I do know that this is a bit of a hacky change, so I want to discuss it first. Perhaps there is a better way to explore? Perhaps compiling contents of the sigil Phoenix.LiveView.TagEngine would be a better approach, but then it would require some kind of plugin system, to only activate it when LiveView is actually present.

Do you have any thoughts on this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions