lua-language-server
lua-language-server copied to clipboard
关于enum的识别问题
Sumneko Lua translate bot
Title: = Issue about enum identification
这不是enum的设计用法
Sumneko Lua translate bot
This is not the design usage of enum
不寫 key 時,對應的 node type 為 tableexp
而目前代碼對於 doc.enum 的處理,似只會處理 tablefield 和 tableindex
即 a = 'a' 和 [1] = 'a' 這2種寫法 🤔
我嘗試對幾個地方,加上檢查 tableexp
好像就支持到了
但我不確定這個使用方式是否符合設計 😂
Patch 內容
有興趣可以測試 / 進一步修改 / 提交 PR
Details
diff --git forkSrcPrefix/script/core/completion/completion.lua forkDstPrefix/script/core/completion/completion.lua
index f751e53d50192cfbe8b7b83a6a6ac4005b0395fe..57674efc5609a830ddfe5b0baf1a344fa88832e5 100644
--- forkSrcPrefix/script/core/completion/completion.lua
+++ forkDstPrefix/script/core/completion/completion.lua
@@ -1210,7 +1210,8 @@ local function insertDocEnum(state, pos, doc, enums)
local valueEnums = {}
for _, field in ipairs(tbl) do
if field.type == 'tablefield'
- or field.type == 'tableindex' then
+ or field.type == 'tableindex'
+ or field.type == 'tableexp' then
if not field.value then
goto CONTINUE
end
@@ -1267,7 +1268,8 @@ local function insertDocEnumKey(doc, enums)
local keyEnums = {}
for _, field in ipairs(tbl) do
if field.type == 'tablefield'
- or field.type == 'tableindex' then
+ or field.type == 'tableindex'
+ or field.type == 'tableexp' then
if not field.value then
goto CONTINUE
end
diff --git forkSrcPrefix/script/core/hover/description.lua forkDstPrefix/script/core/hover/description.lua
index 368b311c9abc29c207e816ed4e4f6f0290b8faf7..9b2645951c51a5d8c588d1c09a96d069cd7aaf08 100644
--- forkSrcPrefix/script/core/hover/description.lua
+++ forkDstPrefix/script/core/hover/description.lua
@@ -497,7 +497,8 @@ local function tryDocEnum(source)
md:add('lua', '{')
for _, field in ipairs(tbl) do
if field.type == 'tablefield'
- or field.type == 'tableindex' then
+ or field.type == 'tableindex'
+ or field.type == 'tableexp' then
if not field.value then
goto CONTINUE
end
diff --git forkSrcPrefix/script/vm/compiler.lua forkDstPrefix/script/vm/compiler.lua
index 986e85e2dc462781b07e8d88978a25486c6b5b82..2f7aa6247cf5f5c5a2081e3b338e471234e6d03c 100644
--- forkSrcPrefix/script/vm/compiler.lua
+++ forkDstPrefix/script/vm/compiler.lua
@@ -266,7 +266,8 @@ local searchFieldSwitch = util.switch()
end
for _, field in ipairs(tbl) do
if field.type == 'tablefield'
- or field.type == 'tableindex' then
+ or field.type == 'tableindex'
+ or field.type == 'tableexp' then
if not field.value then
goto CONTINUE
end
diff --git forkSrcPrefix/script/vm/global.lua forkDstPrefix/script/vm/global.lua
index ed2b4802aa46c588daee30aafe929f4af0b8228e..21bfdc789964a9918c3a678d2f0a8c19cac6f9fe 100644
--- forkSrcPrefix/script/vm/global.lua
+++ forkDstPrefix/script/vm/global.lua
@@ -404,6 +404,10 @@ local compilerGlobalSwitch = util.switch()
local subType = vm.declareGlobal('type', name .. '.' .. field.index[1], uri)
subType:addSet(uri, field)
end
+ elseif field.type == 'tableexp' then
+ source._enums[#source._enums+1] = field
+ local subType = vm.declareGlobal('type', name .. '.' .. field.tindex, uri)
+ subType:addSet(uri, field)
end
end
end