diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-11-08 00:01:12 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-11-08 00:01:12 +0800 |
commit | 00dd1ed171beda2e892a2460d6e7eff321c775e8 (patch) | |
tree | 95a17424f070cc6d0ee7d458011519c82039a378 /script/core/completion | |
parent | 34d32a478bcd066baf49ccf36f5f26a132cbfab8 (diff) | |
download | lua-language-server-00dd1ed171beda2e892a2460d6e7eff321c775e8.zip |
support enums with runtime values
resolved #1411
Diffstat (limited to 'script/core/completion')
-rw-r--r-- | script/core/completion/completion.lua | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua index 39b54209..f87b55a6 100644 --- a/script/core/completion/completion.lua +++ b/script/core/completion/completion.lua @@ -1181,11 +1181,25 @@ local function insertDocEnum(state, pos, doc, enums) if not key then goto CONTINUE end - if field.value.type == 'integer' - or field.value.type == 'string' then - if parentName then - enums[#enums+1] = { - label = parentName .. '.' .. key, + if parentName then + enums[#enums+1] = { + label = parentName .. '.' .. key, + kind = define.CompletionItemKind.EnumMember, + id = stack(field, function (newField) ---@async + return { + detail = buildDetail(newField), + description = buildDesc(newField), + } + end), + } + end + for nd in vm.compileNode(field.value):eachObject() do + if nd.type == 'boolean' + or nd.type == 'number' + or nd.type == 'integer' + or nd.type == 'string' then + valueEnums[#valueEnums+1] = { + label = util.viewLiteral(nd[1]), kind = define.CompletionItemKind.EnumMember, id = stack(field, function (newField) ---@async return { @@ -1195,16 +1209,6 @@ local function insertDocEnum(state, pos, doc, enums) end), } end - valueEnums[#valueEnums+1] = { - label = util.viewLiteral(field.value[1]), - kind = define.CompletionItemKind.EnumMember, - id = stack(field, function (newField) ---@async - return { - detail = buildDetail(newField), - description = buildDesc(newField), - } - end), - } end ::CONTINUE:: end |