summaryrefslogtreecommitdiff
path: root/script/core/hint.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-06-27 17:17:09 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-06-27 17:17:09 +0800
commitf8941022009468f7034e664615df70731a25c23e (patch)
treeae51112781246a53f368130b8f132354325d1fa1 /script/core/hint.lua
parent708bf5314377d8632a5759b27662aeda95c8020f (diff)
downloadlua-language-server-f8941022009468f7034e664615df70731a25c23e.zip
fix array index hint
Diffstat (limited to 'script/core/hint.lua')
-rw-r--r--script/core/hint.lua49
1 files changed, 28 insertions, 21 deletions
diff --git a/script/core/hint.lua b/script/core/hint.lua
index 043852ae..22bc5c50 100644
--- a/script/core/hint.lua
+++ b/script/core/hint.lua
@@ -189,38 +189,45 @@ local function arrayIndex(uri, results, start, finish)
return false
end
- local list = {}
- local max = 0
---@async
- guide.eachSourceBetween(state.ast, start, finish, function (source)
- if source.type ~= 'tableexp' then
+ guide.eachSourceType(state.ast, 'table', function (source)
+ if source.finish < start or source.start > finish then
return
end
await.delay()
if option == 'Auto' then
- if not isMixedOrLargeTable(source.parent) then
+ if not isMixedOrLargeTable(source) then
return
end
end
- list[#list+1] = source
- if source.tindex > max then
- max = source.tindex
+ local list = {}
+ local max = 0
+ for _, field in ipairs(source) do
+ if field.type == 'tableexp'
+ and field.start < finish
+ and field.finish > start then
+ list[#list+1] = field
+ if field.tindex > max then
+ max = field.tindex
+ end
+ end
end
- end)
- if #list > 0 then
- local length = #tostring(max)
- local fmt = '[%0' .. length .. 'd]'
- for _, source in ipairs(list) do
- results[#results+1] = {
- text = fmt:format(source.tindex),
- offset = source.start,
- kind = define.InlayHintKind.Other,
- where = 'left',
- source = source.parent,
- }
+ if #list > 0 then
+ local length = #tostring(max)
+ local fmt = '[%0' .. length .. 'd]'
+ for _, field in ipairs(list) do
+ results[#results+1] = {
+ text = fmt:format(field.tindex),
+ offset = field.start,
+ kind = define.InlayHintKind.Other,
+ where = 'left',
+ source = field.parent,
+ }
+ end
end
- end
+ end)
+
end
---@async