diff options
-rw-r--r-- | changelog.md | 2 | ||||
-rw-r--r-- | script/vm/infer.lua | 15 | ||||
-rw-r--r-- | test/diagnostics/undefined-field.lua | 10 | ||||
-rw-r--r-- | test/type_inference/common.lua | 2 |
4 files changed, 24 insertions, 5 deletions
diff --git a/changelog.md b/changelog.md index 0f1c2d10..a94410be 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,8 @@ ## Unreleased <!-- Add all new changes here. They will be moved under a version at release --> * `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) +* `NEW` `undefined-field` supports `enum` +* `CHG` Show enumed table as `enum X` instead of `table` * `FIX` Error `attempt to index a nil value` when `Lua.hint.semicolon == 'All'` [#2788](https://github.com/LuaLS/lua-language-server/issues/2788) * `FIX` Incorrect LuaCats parsing for `"'"` * `FIX` Incorrect indent fixings diff --git a/script/vm/infer.lua b/script/vm/infer.lua index bb06ee3a..35e17e5c 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -51,13 +51,20 @@ local viewNodeSwitch;viewNodeSwitch = util.switch() end) : case 'table' : call(function (source, infer, uri) - if source.type == 'table' then - if #source == 1 and source[1].type == 'varargs' then - local node = vm.getInfer(source[1]):view(uri) - return ('%s[]'):format(node) + local docs = source.bindDocs + if docs then + for _, doc in ipairs(docs) do + if doc.type == 'doc.enum' then + return 'enum ' .. doc.enum[1] + end end end + if #source == 1 and source[1].type == 'varargs' then + local node = vm.getInfer(source[1]):view(uri) + return ('%s[]'):format(node) + end + infer._hasTable = true end) : case 'function' diff --git a/test/diagnostics/undefined-field.lua b/test/diagnostics/undefined-field.lua index aff329fb..24232eb5 100644 --- a/test/diagnostics/undefined-field.lua +++ b/test/diagnostics/undefined-field.lua @@ -146,3 +146,13 @@ local t local n = t:upper() ]] + +TEST [[ +---@enum X +X = { + A = 1, + B = 2 +} + +print(X.<!C!>) +]] diff --git a/test/type_inference/common.lua b/test/type_inference/common.lua index 5fcec805..4a29454a 100644 --- a/test/type_inference/common.lua +++ b/test/type_inference/common.lua @@ -3609,7 +3609,7 @@ TEST '-2|-3|1' [[ local <?n?> ]] -TEST 'table' [[ +TEST 'enum A' [[ ---@enum A local m = {} |