bhuynhdev
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?
Marked As Solved
samba6
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
Popular in Questions
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
I would like to know what is the best IDE for elixir development?
New
Hey,
I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )
Hello all, this is ...
New
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size?
Thanks
New
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Other popular topics
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
New
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!)
This post collects co...
New
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
I would like to know what is the best IDE for elixir development?
New
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New








