LuaLS / LuaLS/lua-language-server

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

未关闭
#3,409 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Lua
星标
4.4k
派生
442
PR 合并指标
30 天内没有已合并 PR

描述

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 ?

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从提供的 init.lua 模块和 rockspec 开始,然后使用所示的 workspace.library 设置在 LuaLS 中复现两种 require 模式。跟踪动态 require 路径的解析方式,以及返回的表字段如何获得类型;当 ui. 为 init.lua 导出的模块提供已知且带类型的字段时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
lua
领域
developer-experience, tooling
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
52/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。