LuaLS / LuaLS/lua-language-server

Autocompletion is not offered for a parameter with a `@class` type

Open
#1,439 23 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

### How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

### Which OS are you using?

Windows

### What is the issue affecting?

Completion

### Expected Behaviour

When using a defined class as the type for a parameter, the fields of that table should be offered as an autocompletion when calling the function.

For an example, using `@alias` works like so:
![image](https://user-images.githubusercontent.com/61925890/182666707-4604246c-d5c6-4f00-b325-d0b63b66dc83.png)

### Actual Behaviour

No autocompletion is automatically offered when using `@class` as the type for a parameter. If you press CTRL + Space, you can make the completions appear, but they will not appear automatically.

Nothing is offered:
![image](https://user-images.githubusercontent.com/61925890/182667040-5db455a7-1c2b-4ee9-97c0-db98a972bcbc.png)
Until I press CTRL + Space:
![image](https://user-images.githubusercontent.com/61925890/182667128-2cf3aaad-de2d-4449-8198-503717acea9b.png)

### Reproduction steps

1. Use the below code:
```lua
---@class Options
---@field page number
---@field active boolean

---@param opts Options
local function acceptOptions(opts) end

acceptOptions()
```
2. Move your cursor to line 9 (`acceptOptions()`) and place it between the parentheses
![image](https://user-images.githubusercontent.com/61925890/182667557-19514c4a-8ba2-403c-b75c-e08f6677d75a.png)
3. Enter `{` to start a table literal
4. No completions are offered
5. Press CTRL + Space and notice that the first 2 options are actually proper completions from the `Options` class. These should automatically be offered.

### Additional Notes

_No response_

### Log File

_No response_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named in the issue. Start by running the supplied Lua reproduction in the VS Code extension and trace completion behavior after entering `{` for the `Options` parameter; done means the `@class` fields are offered automatically without pressing Ctrl+Space.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.