elixir-lsp / elixir-lsp/elixir-ls

No suggestions for `@spec`ed function params

Open
#1,125 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Elixir
Stars
1.8k
Forks
227
Avg merge
31m
Merged PRs (30d)
2

Description

### Environment
Elixir & Erlang versions (elixir --version):
```
Erlang/OTP 26 [erts-14.2.5.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns]
Elixir 1.17.3 (compiled with Erlang/OTP 26)
```
VSCode ElixirLS version: `v0.24.2`
Operating System Version: `Ubuntu 22.04.5 LTS`

### Troubleshooting

- [x] Restart your editor (which will restart ElixirLS) sometimes fixes issues
- [x] Stop your editor, remove the entire `.elixir_ls` directory, then restart your editor

### Details

Given this code:
```elixir
defmodule MyMod do
@type t :: %MyMod{
id: pos_integer(),
name: binary()
}
defstruct id: 0,
name: ""

@spec hello1(person :: MyMod.t()) :: MyMod.t()
defp hello1(person) do
IO.inspect(person)
end

@spec hello2(person :: MyMod.t()) :: MyMod.t()
defp hello2(%MyMod{} = person) do
IO.inspect(person)
end

@spec hello3(person :: MyMod.t()) :: MyMod.t()
defp hello3(person) do
p1 = hello1(person)
IO.inspect(p1)
end

def say_hello() do
person = %MyMod{
id: 123,
name: "Bob"
}

hello1(person)
hello2(person)
hello3(person)
end
end
```
#### Problem
Autocomplete/suggestions for the `person` variable do **not** work in the `hello1()` function
![image](https://github.com/user-attachments/assets/321567af-c8c6-4108-a779-b26779bc26f1)

#### Expected result
Autocomplete/suggestions should work for the `person` variable in `hello1()` the same way they work in the `hello2()` function
![image](https://github.com/user-attachments/assets/19bd65a3-a877-49da-bdd9-3e7578b01f76)

#### Relevant info
Strangely enough, suggestions work for the `p1` variable in the `hello3()` function
![image](https://github.com/user-attachments/assets/7e50ab16-1af2-40d9-8613-b39ff4f1c27c)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.