summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-09-15 16:22:42 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-09-15 16:22:42 +0800
commit353b5e3085fd7dd5f6b659917540096d3792b42c (patch)
tree3de8833c9baadc4158353b208c70cbfe478fe946
parente2df6d85fb15c50b96811d1923079d003e7f52d4 (diff)
downloadlua-language-server-353b5e3085fd7dd5f6b659917540096d3792b42c.zip
fix #1439
-rw-r--r--changelog.md1
-rw-r--r--script/core/completion/completion.lua16
-rw-r--r--script/core/look-backward.lua3
-rw-r--r--test/completion/common.lua27
4 files changed, 42 insertions, 5 deletions
diff --git a/changelog.md b/changelog.md
index 1ad26d4e..5806ff89 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,6 +1,7 @@
# changelog
## 3.6.0
+* `FIX` [#1439](https://github.com/sumneko/lua-language-server/issues/1439)
* `FIX` [#1467](https://github.com/sumneko/lua-language-server/issues/1467)
* `FIX` [#1506](https://github.com/sumneko/lua-language-server/issues/1506)
* `FIX` [#1537](https://github.com/sumneko/lua-language-server/issues/1537)
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index 149e073b..8f42226a 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -749,7 +749,7 @@ local function checkKeyWord(state, start, position, word, hasSpace, afterLocal,
local text = state.lua
local snipType = config.get(state.uri, 'Lua.completion.keywordSnippet')
local symbol = lookBackward.findSymbol(text, guide.positionToOffset(state, start))
- local isExp = symbol == '(' or symbol == ',' or symbol == '=' or symbol == '['
+ local isExp = symbol == '(' or symbol == ',' or symbol == '=' or symbol == '[' or symbol == '{'
local info = {
hasSpace = hasSpace,
isExp = isExp,
@@ -1485,11 +1485,13 @@ local function checkTableLiteralField(state, position, tbl, fields, results)
end
end
if left then
+ local hasResult = false
for _, field in ipairs(fields) do
local name = guide.getKeyName(field)
if name
and not mark[name]
and matchKey(left, tostring(name)) then
+ hasResult = true
results[#results+1] = {
label = guide.getKeyName(field),
kind = define.CompletionItemKind.Property,
@@ -1502,6 +1504,7 @@ local function checkTableLiteralField(state, position, tbl, fields, results)
}
end
end
+ return hasResult
end
end
@@ -1553,7 +1556,7 @@ end
local function tryTable(state, position, results)
local source = findNearestTableField(state, position)
if not source then
- return
+ return false
end
if source.type ~= 'table'
and (not source.parent or source.parent.type ~= 'table') then
@@ -1574,7 +1577,10 @@ local function tryTable(state, position, results)
fields[#fields+1] = field
end
end
- checkTableLiteralField(state, position, tbl, fields, results)
+ if checkTableLiteralField(state, position, tbl, fields, results) then
+ return true
+ end
+ return false
end
local function tryArray(state, position, results)
@@ -2152,9 +2158,11 @@ local function tryCompletions(state, position, triggerCharacter, results)
if postfix(state, position, results) then
return
end
+ if tryTable(state, position, results) then
+ return
+ end
trySpecial(state, position, results)
tryCallArg(state, position, results)
- tryTable(state, position, results)
tryArray(state, position, results)
tryWord(state, position, triggerCharacter, results)
tryIndex(state, position, results)
diff --git a/script/core/look-backward.lua b/script/core/look-backward.lua
index 8d3e3439..d90c4fff 100644
--- a/script/core/look-backward.lua
+++ b/script/core/look-backward.lua
@@ -58,7 +58,8 @@ function m.findSymbol(text, offset)
or char == '('
or char == ','
or char == '['
- or char == '=' then
+ or char == '='
+ or char == '{' then
return char, i
else
return nil
diff --git a/test/completion/common.lua b/test/completion/common.lua
index 02e57b80..8fa8c26a 100644
--- a/test/completion/common.lua
+++ b/test/completion/common.lua
@@ -3750,3 +3750,30 @@ TEST [[
local x = function (x, y) end
]]
(EXISTS)
+
+TEST [[
+local x = {
+<??>
+})
+]]
+(function (results)
+ for _, res in ipairs(results) do
+ assert(res.label ~= 'do')
+ end
+end)
+
+TEST [[
+---@class Options
+---@field page number
+---@field active boolean
+
+---@param opts Options
+local function acceptOptions(opts) end
+
+acceptOptions({
+<??>
+})
+]]
+(function (results)
+ assert(#results == 2)
+end)