Skip to content

Commit f8a8167

Browse files
committed
undefined-field supports enum
close #2469
1 parent 080d672 commit f8a8167

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
## Unreleased
44
<!-- Add all new changes here. They will be moved under a version at release -->
55
* `NEW` Setting: `Lua.type.checkTableShape`: Add matching checks between the shape of tables and classes, during type checking. [#2768](https://github.com/LuaLS/lua-language-server/pull/2768)
6+
* `NEW` `undefined-field` supports `enum`
7+
* `CHG` Show enumed table as `enum X` instead of `table`
68
* `FIX` Error `attempt to index a nil value` when `Lua.hint.semicolon == 'All'` [#2788](https://github.com/LuaLS/lua-language-server/issues/2788)
79
* `FIX` Incorrect LuaCats parsing for `"'"`
810
* `FIX` Incorrect indent fixings

script/vm/infer.lua

+11-4
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,20 @@ local viewNodeSwitch;viewNodeSwitch = util.switch()
5151
end)
5252
: case 'table'
5353
: call(function (source, infer, uri)
54-
if source.type == 'table' then
55-
if #source == 1 and source[1].type == 'varargs' then
56-
local node = vm.getInfer(source[1]):view(uri)
57-
return ('%s[]'):format(node)
54+
local docs = source.bindDocs
55+
if docs then
56+
for _, doc in ipairs(docs) do
57+
if doc.type == 'doc.enum' then
58+
return 'enum ' .. doc.enum[1]
59+
end
5860
end
5961
end
6062

63+
if #source == 1 and source[1].type == 'varargs' then
64+
local node = vm.getInfer(source[1]):view(uri)
65+
return ('%s[]'):format(node)
66+
end
67+
6168
infer._hasTable = true
6269
end)
6370
: case 'function'

test/diagnostics/undefined-field.lua

+10
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,13 @@ local t
146146
147147
local n = t:upper()
148148
]]
149+
150+
TEST [[
151+
---@enum X
152+
X = {
153+
A = 1,
154+
B = 2
155+
}
156+
157+
print(X.<!C!>)
158+
]]

test/type_inference/common.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -3609,7 +3609,7 @@ TEST '-2|-3|1' [[
36093609
local <?n?>
36103610
]]
36113611

3612-
TEST 'table' [[
3612+
TEST 'enum A' [[
36133613
---@enum A
36143614
local m = {}
36153615

0 commit comments

Comments
 (0)