Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

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

还没有人认领这个 Issue。

评估

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

调研方向

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

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

描述

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

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

Image

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. :

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 ?

主要语言
Lua
星标
4.4k
派生
442
平均合并
8 天 9 小时
30 天内合并 PR
1

贡献指南

打开贡献指南

从这里开始

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

LuaLS/lua-language-server 的其他 Issue

查看 LuaLS/lua-language-server 的全部 Issue

相似的 Issue

更多 Lua Issue

把新 issue 发到你的邮箱

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