lua-language-server
lua-language-server copied to clipboard
inline `@class` does not work properly without empty line in between
How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
Which OS are you using?
Windows
What is the issue affecting?
Annotations
Expected Behaviour
I suppose @class
can be used inline like local ClassA = {} ---@class ClassA
?
(please correctly me if I am wrong)
So the following code should work, which 3 classes are defined
local ClassA = {} ---@class ClassA
local ClassB = {} ---@class ClassB
local ClassC = {} ---@class ClassC
Actual Behaviour
However, with the above test code, only the last class ClassC
is recognized.
And if I add empty lines in between, then it will work properly.
local ClassA = {} ---@class ClassA
local ClassB = {} ---@class ClassB
local ClassC = {} ---@class ClassC
Reproduction steps
As described with the minimal test code above.
Additional Notes
My actual use case is that I have a file defined some class namespace, to act as an common table reference. And the actual class implementation is spitted into multiple files, with each requires the type namespace then extend it from there to prevent circular require. Right now the workaround is to add blank line in between the namespace declaration.
- model/Type.lua
local Type = {
Pc = {}, ---@class Pc
Npc = {}, ---@class Npc
Item = {}, ---@class Item
}
return Type
- model/pc/Pc.lua
local Type = require "model.Type"
---@class Pc
local Pc = Type.Pc
function Pc.new() end
-- require all other pc.* module at the bottom of file
- model/pc/Hp.lua
local Type = require "model.Type"
---@class Pc
local Pc = Type.Pc
function Pc:setHp(hp) end
- logic/pccmd.lua
local Type = require "model.Type"
local Pc = Type.Pc
-- no completion for `Pc` here if I don't add blank line in `model/Type.lua`
Log File
No response