LuaLS / LuaLS/lua-language-server

Exact Classes Do Not Autocomplete Methods

Open
#2,919 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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?

Linux

### What is the issue affecting?

Completion

### Expected Behaviour

Autocomplete should complete methods on instances of (exact) classes.

Expected completion for a normal class:
![20241029_094227](https://github.com/user-attachments/assets/9e9667d0-3756-416e-bb68-4282128d4c7c)

### Actual Behaviour

Methods are not completed.

![20241029_094211](https://github.com/user-attachments/assets/e5745741-8774-4557-a667-d7a90a6a2ba3)

### Reproduction steps

VSCode project with v3.11.0 plugin.

All defaults, no `.luarc.json`.

Ctrl-space at last line.

```lua
---@class (exact) Point
--@class Point
---@field x number
---@field y number
local Point = {}

function Point:new(o)
o = o or {}

setmetatable(o, self)
self.__index = self ---@diagnostic disable-line: inject-field

return o
end

---@param i integer
function Point:add(i)
self.x = self.x + i
end

---@type Point
local point = Point:new({ x = 1, y = 2 })

point:
```

### Additional Notes

Many thanks for all the fantastic work - luals makes me so much more productive!

### Log File

[log.tar.gz](https://github.com/user-attachments/files/17549561/log.tar.gz)

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

Reproduce the issue in a Visual Studio Code project with the v3.11.0 plugin using the provided Point class and Ctrl-space at the final line. Compare completion for the exact class with the normal class example. Done means the add method is offered for completion on the Point instance.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.