summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md1
-rw-r--r--script/core/completion.lua5
-rw-r--r--test/completion/init.lua16
3 files changed, 21 insertions, 1 deletions
diff --git a/changelog.md b/changelog.md
index c455c90a..0babb4f8 100644
--- a/changelog.md
+++ b/changelog.md
@@ -2,6 +2,7 @@
## 1.16.1
* `FIX` signature: parameters may be misplaced
+* `FIX` completion: interface in nested table
* `FIX` [#400](https://github.com/sumneko/lua-language-server/issues/400)
* `FIX` runtime errors
diff --git a/script/core/completion.lua b/script/core/completion.lua
index 17ccb817..4d8c77b2 100644
--- a/script/core/completion.lua
+++ b/script/core/completion.lua
@@ -1370,6 +1370,9 @@ local function checkTableLiteralField(ast, text, offset, call, funcs, index, res
if source.type ~= 'table' then
tbl = source.parent
end
+ if tbl.parent ~= call.args then
+ return
+ end
for _, field in ipairs(vm.getDefFields(tbl, 0)) do
local name = guide.getKeyName(field)
if name then
@@ -1403,7 +1406,7 @@ local function checkTableLiteralField(ast, text, offset, call, funcs, index, res
results[#results+1] = {
label = guide.getKeyName(field),
kind = define.CompletionItemKind.Property,
- insertText = ('%s = $0,'):format(guide.getKeyName(field)),
+ insertText = ('%s = $0'):format(guide.getKeyName(field)),
id = stack(function ()
return {
detail = buildDetail(field),
diff --git a/test/completion/init.lua b/test/completion/init.lua
index a44b4a08..676480f5 100644
--- a/test/completion/init.lua
+++ b/test/completion/init.lua
@@ -2053,6 +2053,22 @@ f({
}
TEST [[
+---@class cc
+---@field aaa number # a1
+---@field bbb number # a2
+
+---@param x cc
+local function f(x) end
+
+f({
+ {
+ $
+ }
+})
+]]
+(nil)
+
+TEST [[
---@return string
local function f() end