summaryrefslogtreecommitdiff
path: root/script/core/completion
diff options
context:
space:
mode:
authorkevinhwang91 <kevin.hwang@live.com>2022-04-04 02:15:00 +0800
committerkevinhwang91 <kevin.hwang@live.com>2022-04-04 02:15:00 +0800
commitbc8e292e3bedc423d31abdd4ce040fcf1143d46a (patch)
tree4bc8a641736d8e85250a731c53e873b4e7e02d81 /script/core/completion
parent7f9547be6881c16cdf6d0977acf4c726c6e15348 (diff)
downloadlua-language-server-bc8e292e3bedc423d31abdd4ce040fcf1143d46a.zip
fix(completion): optional arguments may not continued
If the arguments are all optional or variable until the end, we can truncate them directly.
Diffstat (limited to 'script/core/completion')
-rw-r--r--script/core/completion/completion.lua19
1 files changed, 15 insertions, 4 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index 05b035af..d751b727 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -157,15 +157,26 @@ local function buildFunctionSnip(source, value, oop)
local name = (getName(source) or ''):gsub('^.+[$.:]', '')
local args = getArg(value, oop)
local id = 0
+ local needTruncateId = 0
args = args:gsub('[^,]+', function (arg)
- if arg:match('^%s+[^?]+%?:') or arg:match('^%s+%.%.%.:') then
- return ''
- end
id = id + 1
+ if arg:match('^%s*[^?]+%?:') or arg:match('^%s*%.%.%.:') then
+ if needTruncateId == 0 then
+ needTruncateId = id
+ end
+ else
+ needTruncateId = 0
+ end
return arg:gsub('^(%s*)(.+)', function (sp, word)
return ('%s${%d:%s}'):format(sp, id, word)
end)
- end):gsub(',+$', '')
+ end)
+ if needTruncateId > 0 then
+ local start = args:find(',?%s*%${' .. needTruncateId)
+ if start then
+ args = start == 1 and '$1' or args:sub(1, start - 1)
+ end
+ end
return ('%s(%s)'):format(name, args)
end