diff options
-rw-r--r-- | server/src/core/completion.lua | 23 | ||||
-rw-r--r-- | server/test/completion/init.lua | 14 |
2 files changed, 31 insertions, 6 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index 7da54412..3b6e67e7 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -216,12 +216,7 @@ local function sortPairs(t) end end -local function searchFields(vm, source, word, callback) - local parent = source:get 'parent' - if not parent then - return - end - local map = {} +local function searchFieldsByInfo(parent, word, source, map) parent:eachInfo(function (info, src) local k = info[1] if src == source then @@ -250,6 +245,22 @@ local function searchFields(vm, source, word, callback) map[k] = v end end) +end + +local function searchFields(vm, source, word, callback) + local parent = source:get 'parent' + if not parent then + return + end + local map = {} + local current = parent + for _ = 1, 3 do + searchFieldsByInfo(current, word, source, map) + current = current:getMetaMethod('__index') + if not current then + break + end + end parent:eachChild(function (k, v) if map[k] then return diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua index ed68dec5..6c1fe7ad 100644 --- a/server/test/completion/init.lua +++ b/server/test/completion/init.lua @@ -755,3 +755,17 @@ local *tocl@ kind = CompletionItemKind.Keyword, } } + +TEST [[ +local mt = {} +mt.__index = mt +local t = setmetatable({}, mt) + +t.@ +]] +{ + { + label = '__index', + kind = CompletionItemKind.Field, + } +} |