Skip to content

LSP textDocument/definition support for HEEX ~H sigils #74

@superhawk610

Description

@superhawk610

What would you like to see?

I'd like to be able to Go-to Definition on function components and expressions within Phoenix LiveView HEEX templates. For example, in the following LiveView, I'd like to be able to goto the definition of foo, Foo.bar, Baz, and class() from within the sigil's contents.

defmodule PageLive do
  use Phoenix.LiveView

  def render(assigns) do
    ~H"""
    <main>
      <.foo>
        <Foo.bar>Hello, world!</Foo.bar>
        <.live_component module={Baz} id="baz" />
        <span class={class()} />
      </.foo>
    </main>
    """
  end

  defp foo(assigns), do: ~H".."
  defp class, do: "w-full"
end

<Foo.bar> and <.foo> desugar to simple function calls, and HEEX expression interpolation (within {}) is just direct Elixir code that can be parsed with the existing parser.

Why?

When working within a Phoenix LiveView application, you spend as much time working within the render function as outside. Render functions are often composed of many other smaller function components and live components, and it improves navigation drastically when you can jump between them directly, without having to resort to Ctrl+F or jumping to the top of the page first to find the corresponding alias.

Alternatives considered

Navigating via the editor's built-in Find and Project Search work OK, as does */#-style Vim motions (find next/prev occurrence). Jumping to the top of the file and using go-to definition on the alias also works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions