LuaLS / LuaLS/lua-language-server

No autocomplete for the "submodules" of a library when those included from init.lua

Open
#3,409 1 comment 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

Dear developers, I've read similar existing issues but didn't find the answer.

I have a library (which I am the developer of) which has this structure:

Image

and `init.lua` is

```lua
local UI = (...) .. '.'

return {
Block = require(UI .. 'Block'),
Image = require(UI .. 'Image'),
Label = require(UI .. 'Label'),
Layout = require(UI .. 'Layout'),
Rectangle = require(UI .. 'Rectangle'),
Stack = require(UI .. 'Stack'),

ImageButton = require(UI .. 'ImageButton'),
TextField = require(UI .. 'TextField'),

utils = require(UI .. 'utils')
}
```

and the rockspec contains this:

```lua
build = {
type = 'builtin',
modules = {
['likelihud'] = 'likelihud/init.lua',
['likelihud.Block'] = 'likelihud/Block.lua',
['likelihud.Image'] = 'likelihud/Image.lua',
['likelihud.Label'] = 'likelihud/Label.lua',
['likelihud.Layout'] = 'likelihud/Layout.lua',
['likelihud.Rectangle'] = 'likelihud/Rectangle.lua',
['likelihud.Stack'] = 'likelihud/Stack.lua',
['likelihud.ImageButton'] = 'likelihud/ImageButton.lua',
['likelihud.TextField'] = 'likelihud/TextField.lua',
['likelihud.utils'] = 'likelihud/utils.lua',
},
}
```
So after install I have

Image

Coc-config:

```json
{
"suggest.noselect": true,
"Lua.workspace.library" : [
"/usr/local/share/lua/5.1"
]
}
```

# The problem

If I write

```lua
local Button = require('likelihud.ImageButton')
```
I get autocomplete for `Button`.

But if instead I do

```lua
local ui = require('likelihud')
```
I get only those fields when I do `ui.`, _but the fields are unknown._ :

Image

So the problem LSP doesn't resolve this `(...) .. '.'` inside `init.lua`. Should I somehow change how `init.lua` provides those files or how to fix that ?

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

Start with the provided init.lua module and rockspec, then reproduce the two require patterns in LuaLS with the shown workspace.library setting. Trace how dynamic require paths are resolved and how returned table fields receive types; done means ui. offers known, typed fields for the modules exported by init.lua.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.