diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/src/core/completion.lua | 14 | ||||
-rw-r--r-- | server/src/core/find_result.lua | 8 | ||||
-rw-r--r-- | server/test/completion/init.lua | 24 |
3 files changed, 42 insertions, 4 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index 13a36d94..6c49fbb0 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -547,6 +547,16 @@ local function clearList(list, source) end end +local function isValidResult(result) + if not result then + return false + end + if result.type == 'local' or result.type == 'field' then + return true + end + return false +end + return function (vm, pos, word) local list = {} local callback = makeList(list) @@ -558,10 +568,10 @@ return function (vm, pos, word) searchSpecial(vm, pos, callback) if not inString then local result, source = findResult(vm, pos) - if not result then + if not isValidResult(result) then result, source = findClosePos(vm, pos) end - if result then + if isValidResult(result) then callback = makeList(list, source) searchInResult(result, source, vm, pos, callback) searchAllWords(result.key, vm, callback) diff --git a/server/src/core/find_result.lua b/server/src/core/find_result.lua index ac8dc3f4..e4074879 100644 --- a/server/src/core/find_result.lua +++ b/server/src/core/find_result.lua @@ -5,12 +5,16 @@ local function isContainPos(obj, pos) return false end +local function isValidSource(source) + return source.type ~= 'simple' +end + local function findAtPos(results, pos, level) local res = {} for sources, object in pairs(results.sources) do if sources.type == 'multi-source' then for _, source in ipairs(sources) do - if source.type ~= 'simple' and isContainPos(source, pos) then + if isValidSource(source) and isContainPos(source, pos) then res[#res+1] = { object = object, source = source, @@ -20,7 +24,7 @@ local function findAtPos(results, pos, level) end else local source = sources - if source.type ~= 'simple' and isContainPos(source, pos) then + if isValidSource(source) and isContainPos(source, pos) then res[#res+1] = { object = object, source = source, diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua index e636e4f3..bb2199aa 100644 --- a/server/test/completion/init.lua +++ b/server/test/completion/init.lua @@ -536,3 +536,27 @@ tbl[ind@] kind = CompletionItemKind.Variable, }, } + +TEST [[ +return function () + local t = { + a = {}, + b = {}, + } + t.@ +end +]] +{ + { + label = 'a', + kind = CompletionItemKind.Field, + }, + { + label = 'b', + kind = CompletionItemKind.Field, + }, + { + label = 'end', + kind = CompletionItemKind.Field, + }, +} |