How to get type information on hover with VSCode ElixirLS

After defining @spec for a function, when I hover over a variable, I still get no information

Example code:

defmodule Testing do
  @type status :: :won | :lost

  @type t :: %__MODULE__{
          status: status()
        }
  defstruct(status: :won)

  @spec action(t()) :: status()
  def action(state) do
    state.sttus
  end
end

In the code above, it I hover over “state” (line 10 and 11), VsCode and Neovim only shows that it is a variable (no type information). Therefore the LSP is also unable to catch it when I typed the wrong field “stts” instead of “status”.

Is this the intended behavior or is my setup broken/incorrect?

I think that is the intended behavior. However, if your goal is to get some type of warning for accessing an unknown key on a struct, then you are in luck as elixir 1.17 can do this for you - check Elixir v1.17 released: set-theoretic types in patterns, calendar durations, and Erlang/OTP 27 support - The Elixir programming language.

defmodule Testing do
  @type status :: :won | :lost

  @type t :: %__MODULE__{
          status: status()
        }
  defstruct status: :won

  @spec action(t) :: status()
  def action(%__MODULE__{} = state) do
    state.sttus
  end
end