LuaLS / LuaLS/lua-language-server
No autocomplete for the "submodules" of a library when those included from init.lua
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:
and init.lua is
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:
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
Coc-config:
{
"suggest.noselect": true,
"Lua.workspace.library" : [
"/usr/local/share/lua/5.1"
]
}
The problem
If I write
local Button = require('likelihud.ImageButton')
I get autocomplete for Button.
But if instead I do
local ui = require('likelihud')
I get only those fields when I do ui., but the fields are unknown. :
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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