Skip to content

Commit

Permalink
Merge pull request #2346 from lewis6991/feat/snipspace
Browse files Browse the repository at this point in the history
feat: support param snippets with space
  • Loading branch information
sumneko authored Sep 26, 2023
2 parents 00dc914 + 18989b4 commit f4548b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 8 additions & 7 deletions script/core/completion/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2158,7 +2158,7 @@ local function tryluaDocByErr(state, position, err, docState, results)
end
end

local function buildluaDocOfFunction(func)
local function buildluaDocOfFunction(func, pad)
local index = 1
local buf = {}
buf[#buf+1] = '${1:comment}'
Expand All @@ -2182,7 +2182,8 @@ local function buildluaDocOfFunction(func)
local funcArg = func.args[n]
if funcArg[1] and funcArg.type ~= 'self' then
index = index + 1
buf[#buf+1] = ('---@param %s ${%d:%s}'):format(
buf[#buf+1] = ('---%s@param %s ${%d:%s}'):format(
pad and ' ' or '',
funcArg[1],
index,
arg
Expand All @@ -2200,7 +2201,7 @@ local function buildluaDocOfFunction(func)
return insertText
end

local function tryluaDocOfFunction(doc, results)
local function tryluaDocOfFunction(doc, results, pad)
if not doc.bindSource then
return
end
Expand All @@ -2222,7 +2223,7 @@ local function tryluaDocOfFunction(doc, results)
end
end
end
local insertText = buildluaDocOfFunction(func)
local insertText = buildluaDocOfFunction(func, pad)
results[#results+1] = {
label = '@param;@return',
kind = define.CompletionItemKind.Snippet,
Expand All @@ -2240,9 +2241,9 @@ local function tryLuaDoc(state, position, results)
end
if doc.type == 'doc.comment' then
local line = doc.originalComment.text
-- 尝试 ---$
if line == '-' then
tryluaDocOfFunction(doc, results)
-- 尝试 '---$' or '--- $'
if line == '-' or line == '- ' then
tryluaDocOfFunction(doc, results, line == '- ')
return
end
-- 尝试 ---@$
Expand Down
6 changes: 6 additions & 0 deletions test/completion/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3863,6 +3863,12 @@ local x = function (x, y) end
]]
(EXISTS)

TEST [[
--- <??>
local x = function (x, y) end
]]
(EXISTS)

TEST [[
local x = {
<??>
Expand Down

0 comments on commit f4548b5

Please sign in to comment.