summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-07-20 16:45:44 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-07-20 16:45:49 +0800
commitd9687d8f1b6a55bdd97a65ba81d9ca2b6cb2357f (patch)
tree3be6554d16adef74e8c1d42d08c487d214d1928a /script/core
parent24b8ab8a1da3b8ae6f6c561ec58e9bd5fcff2c2b (diff)
downloadlua-language-server-d9687d8f1b6a55bdd97a65ba81d9ca2b6cb2357f.zip
improve completion label of table fields
Diffstat (limited to 'script/core')
-rw-r--r--script/core/completion/completion.lua17
1 files changed, 13 insertions, 4 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index 30c1899e..518c716e 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -1572,14 +1572,13 @@ local function checkTableLiteralField(state, position, tbl, fields, results)
end
end
if left then
- local hasResult = false
+ local fieldResults = {}
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] = {
+ local res = {
label = guide.getKeyName(field),
kind = define.CompletionItemKind.Property,
id = stack(field, function (newField) ---@async
@@ -1589,9 +1588,19 @@ local function checkTableLiteralField(state, position, tbl, fields, results)
}
end),
}
+ if field.optional then
+ res.insertText = res.label
+ res.label = res.label.. '?'
+ end
+ fieldResults[#fieldResults+1] = res
end
end
- return hasResult
+ util.sortByScore(fieldResults, {
+ function (r) return r.insertText and 0 or 1 end,
+ util.sortCallbackOfIndex(fieldResults),
+ })
+ util.arrayMerge(results, fieldResults)
+ return #fieldResults > 0
end
end