ElixirLS and GenServer handlers

I have a GenServer with an API function:

  def api_exit do
    GenServer.cast(@proc_name, :exit)

And a matching handler:

def handle_cast(:exit, state) do 
  # some logic here 
  {:noreply, newstate}

Running in Neovim, ElixirLS beautifully navigates to the API function.

But I don’t know of a way to auto-navigate to the handler. Is this even possible with LSP? Are there tricks or best practices to quickly jump to a particular handler?

PS I put a unique prefix on every request term (eg :exit:msg_exit) in the API and handlers. With that, Neovim # and * keys will quickly pop between matching functions. Still curious if there is an LSP way to jump to a handler signature, or other tricks that people may have…

There’s no such functionality in ElixirLS. To accurately jump to handle_* callback would require running your app inside the language server. A simple heuristic of jumping to the same module could work in limited number of cases but that would require compiling and executing the pattern match expressions. The closest is go to callback implementation but that will return all GenServer implementations.

1 Like