lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

[Feature Request] Add Lua config file support

Open goldenstein64 opened this issue 6 months ago • 3 comments

There are some Lua files that are used for configuration, such as .busted or *.rockspec files. It would be nice if:

  • Any globals defined in them are ignored by default
  • Global types and return types can be defined for them in a type definition file

This behavior could all be described by creating a type definition file with a special (config) option next to @meta. The require name is replaced by a Lua pattern that matches the filename or URI. Either that, or it could be specified as a config-specific option using ---@meta (config: PATTERN)

-- library/rockspec.d.lua

---@meta (config) "[%w%.%-%_]+%.rockspec$"

---the rockspec format
---@type string
_G.rockspec_format = nil

---the package name
---@type string
_G.package = nil

---the package version
---@type string
_G.version = nil

---a description of the rock
---@class luarocks.rockspec.description
---@field summary string? -- a short sentence that succinctly describes the rock
---@field description string? -- a paragraph-size description that describes the rock
---@field ...
_G.description = {}

For configurations that require returning a table, you could define a local variable with the right type and return it.

-- library/busted.d.lua

---@meta (config) "%.busted$"

---@class .busted.config
---@field coverage boolean? -- use luacov for coverage
---@field verbose boolean? -- print more things
---@field ...

---a dictionary of Busted configurations. You can specify which one using the
---`--run` option. Uses `default` if no configuration is specified
---@class .busted
---@field default .busted.config?
---@field [string] .busted.config?
local busted_config = {}

return busted_config

goldenstein64 avatar Jun 05 '25 17:06 goldenstein64

Then I think it would be better to add a tag called schema with the syntax ---@schema *.busted. You need to note that LSP clients usually only send files with specifically registered extensions to the language server, so when you edit busted files, the LS won't receive the messages.

CppCXY avatar Jun 06 '25 02:06 CppCXY

You need to note that LSP clients usually only send files with specifically registered extensions to the language server, so when you edit busted files, the LS won't receive the messages.

I don't think LSP clients consider only extensions when selecting files to send to the server. VSCode lets me choose which language to interpret any file in, which also changes the kind of language support used. e.g. my user settings file interprets .busted and *.rockspec as Lua.

{
  // ...
  "files.associations": {
    ".busted": "lua",
    "*.wlua": "lua",
    "*.rockspec": "lua",
    "*.mustache": "html",
    "*.fsproj": "xml"
  },
  // ...
}

This lets me feed those files into LuaLS.

goldenstein64 avatar Jun 06 '25 03:06 goldenstein64

Additionally, based on the current maintenance situation, no one will come to add this feature. LuaLS has effectively stopped updating for some time now.

CppCXY avatar Jun 06 '25 03:06 CppCXY