diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-01-06 15:19:42 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-01-06 15:19:42 +0800 |
commit | 7f7061d2560db20a03d6a24dfd58c641fec554bb (patch) | |
tree | 927abb23ad37306361a3f6dcfc67059f6dd69a59 /script/core | |
parent | d2ee361bcf690a73c3f7f19eff927bf44df17fbc (diff) | |
download | lua-language-server-7f7061d2560db20a03d6a24dfd58c641fec554bb.zip |
`Lua.hint.arrayIndex`
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/hint.lua | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/script/core/hint.lua b/script/core/hint.lua index eebadb05..79ba5548 100644 --- a/script/core/hint.lua +++ b/script/core/hint.lua @@ -161,6 +161,56 @@ local function paramName(uri, results, start, finish) end ---@async +local function arrayIndex(uri, results, start, finish) + local state = files.getState(uri) + if not state then + return + end + local option = config.get(uri, 'Lua.hint.arrayIndex') + if option == 'Disable' then + return + end + + local mixedOrLargeTable = {} + local function isMixedOrLargeTable(tbl) + if mixedOrLargeTable[tbl] ~= nil then + return mixedOrLargeTable[tbl] + end + if #tbl > 3 then + mixedOrLargeTable[tbl] = true + return true + end + for _, child in ipairs(tbl) do + if child.type ~= 'tableexp' then + mixedOrLargeTable[tbl] = true + return true + end + end + mixedOrLargeTable[tbl] = false + return false + end + + ---@async + guide.eachSourceBetween(state.ast, start, finish, function (source) + if source.type ~= 'tableexp' then + return + end + await.delay() + if option == 'Auto' then + if not isMixedOrLargeTable(source.parent) then + return + end + end + results[#results+1] = { + text = ('[%d]'):format(source.tindex), + offset = source.start, + kind = define.InlayHintKind.Other, + where = 'left', + } + end) +end + +---@async local function awaitHint(uri, results, start, finish) local awaitConfig = config.get(uri, 'Lua.hint.await') if not awaitConfig then @@ -194,5 +244,6 @@ return function (uri, start, finish) typeHint(uri, results, start, finish) awaitHint(uri, results, start, finish) paramName(uri, results, start, finish) + arrayIndex(uri, results, start, finish) return results end |