Skip to content

Commit b6e59aa

Browse files
committed
feat: support param snippets with space
Currently the LuaLS will expand: ```lua ---<??> local x = function (x, y) end ``` with: ```lua ---comment ---@param x any ---@param y any local x = function (x, y) end ``` This change adds a variation of this snippet to expand: ```lua --- <??> local x = function (x, y) end ``` with: ```lua --- comment --- @param x any --- @param y any local x = function (x, y) end ```
1 parent 00dc914 commit b6e59aa

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

script/core/completion/completion.lua

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,7 +2158,7 @@ local function tryluaDocByErr(state, position, err, docState, results)
21582158
end
21592159
end
21602160

2161-
local function buildluaDocOfFunction(func)
2161+
local function buildluaDocOfFunction(func, pad)
21622162
local index = 1
21632163
local buf = {}
21642164
buf[#buf+1] = '${1:comment}'
@@ -2182,7 +2182,8 @@ local function buildluaDocOfFunction(func)
21822182
local funcArg = func.args[n]
21832183
if funcArg[1] and funcArg.type ~= 'self' then
21842184
index = index + 1
2185-
buf[#buf+1] = ('---@param %s ${%d:%s}'):format(
2185+
buf[#buf+1] = ('---%s@param %s ${%d:%s}'):format(
2186+
pad and ' ' or '',
21862187
funcArg[1],
21872188
index,
21882189
arg
@@ -2200,7 +2201,7 @@ local function buildluaDocOfFunction(func)
22002201
return insertText
22012202
end
22022203

2203-
local function tryluaDocOfFunction(doc, results)
2204+
local function tryluaDocOfFunction(doc, results, pad)
22042205
if not doc.bindSource then
22052206
return
22062207
end
@@ -2222,7 +2223,7 @@ local function tryluaDocOfFunction(doc, results)
22222223
end
22232224
end
22242225
end
2225-
local insertText = buildluaDocOfFunction(func)
2226+
local insertText = buildluaDocOfFunction(func, pad)
22262227
results[#results+1] = {
22272228
label = '@param;@return',
22282229
kind = define.CompletionItemKind.Snippet,
@@ -2240,9 +2241,9 @@ local function tryLuaDoc(state, position, results)
22402241
end
22412242
if doc.type == 'doc.comment' then
22422243
local line = doc.originalComment.text
2243-
-- 尝试 ---$
2244-
if line == '-' then
2245-
tryluaDocOfFunction(doc, results)
2244+
-- 尝试 '---$' or '--- $'
2245+
if line == '-' or line == '- ' then
2246+
tryluaDocOfFunction(doc, results, line == '- ')
22462247
return
22472248
end
22482249
-- 尝试 ---@$

test/completion/common.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3863,6 +3863,12 @@ local x = function (x, y) end
38633863
]]
38643864
(EXISTS)
38653865

3866+
TEST [[
3867+
--- <??>
3868+
local x = function (x, y) end
3869+
]]
3870+
(EXISTS)
3871+
38663872
TEST [[
38673873
local x = {
38683874
<??>

0 commit comments

Comments
 (0)