summaryrefslogtreecommitdiff
path: root/script/vm/global.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-07-18 01:07:30 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-07-18 01:07:30 +0800
commitdca751cf110a96a351c8cadc049ac364dc41a4dd (patch)
tree785d41633d4ee6bfa3e97ec25043c5cedbc6da28 /script/vm/global.lua
parent04c671114d1d4c4bcfbad74c8341b24844552865 (diff)
downloadlua-language-server-dca751cf110a96a351c8cadc049ac364dc41a4dd.zip
#1255
diagnostic for enum
Diffstat (limited to 'script/vm/global.lua')
-rw-r--r--script/vm/global.lua24
1 files changed, 24 insertions, 0 deletions
diff --git a/script/vm/global.lua b/script/vm/global.lua
index 3fe1bee8..d9509fe7 100644
--- a/script/vm/global.lua
+++ b/script/vm/global.lua
@@ -130,6 +130,7 @@ end
---@class parser.object
---@field _globalNode vm.global|false
+---@field _enums? (string|integer)[]
---@type table<string, vm.global>
local allGlobals = {}
@@ -329,6 +330,29 @@ local compilerGlobalSwitch = util.switch()
local enum = vm.declareGlobal('type', name, uri)
enum:addSet(uri, source)
source._globalNode = enum
+
+ local tbl = source.bindSource and source.bindSource.value
+ if not tbl or tbl.type ~= 'table' then
+ return
+ end
+ source._enums = {}
+ for _, field in ipairs(tbl) do
+ if field.type == 'tablefield'
+ or field.type == 'tableindex' then
+ if not field.value then
+ goto CONTINUE
+ end
+ local key = guide.getKeyName(field)
+ if not key then
+ goto CONTINUE
+ end
+ if field.value.type == 'integer'
+ or field.value.type == 'string' then
+ source._enums[#source._enums+1] = field.value[1]
+ end
+ ::CONTINUE::
+ end
+ end
end)
: case 'doc.type.name'
: call(function (source)