Skip to content

Commit 55166a4

Browse files
committed
resolve #899 no longer generate parameter types
with setting `completion.callSnippet`
1 parent 2ab6187 commit 55166a4

File tree

3 files changed

+13
-67
lines changed

3 files changed

+13
-67
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 3.5.0
44
* `CHG` `---@diagnostic disable: <ERR_NAME>` can suppress syntax errors
5+
* `CHG` `completion.callSnippet` no longer generate parameter types
56
* `FIX` [#1278](https://github.com/sumneko/lua-language-server/issues/1278)
67

78
## 3.4.1

script/core/completion/completion.lua

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -160,32 +160,19 @@ local function buildFunctionSnip(source, value, oop)
160160
if oop then
161161
table.remove(args, 1)
162162
end
163-
local len = #args
164-
local truncated = false
165-
if len > 0 and args[len]:match('^%s*%.%.%.:') then
166-
table.remove(args)
167-
truncated = true
168-
end
169-
for i = #args, 1, -1 do
170-
if args[i]:match('^%s*[^?]+%?:')
171-
or args[i]:match('^%.%.%.') then
172-
table.remove(args)
173-
truncated = true
174-
else
175-
break
176-
end
177-
end
178163

179164
local snipArgs = {}
180165
for id, arg in ipairs(args) do
181-
local str = arg:gsub('^(%s*)(.+)', function (sp, word)
166+
local str, count = arg:gsub('^(%s*)(%.%.%.)(.+)', function (sp, word)
182167
return ('%s${%d:%s}'):format(sp, id, word)
183168
end)
169+
if count == 0 then
170+
str = arg:gsub('^(%s*)([^:]+)(.+)', function (sp, word)
171+
return ('%s${%d:%s}'):format(sp, id, word)
172+
end)
173+
end
184174
table.insert(snipArgs, str)
185175
end
186-
if truncated and #snipArgs == 0 then
187-
snipArgs = {'$1'}
188-
end
189176
return ('%s(%s)'):format(name, table.concat(snipArgs, ', '))
190177
end
191178

test/completion/common.lua

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ mt:f<??>
934934
{
935935
label = 'f(a, b, c)',
936936
kind = define.CompletionItemKind.Snippet,
937-
insertText = 'f(${1:a: any}, ${2:b: any}, ${3:c: any})',
937+
insertText = 'f(${1:a}, ${2:b}, ${3:c})',
938938
},
939939
}
940940

@@ -2688,7 +2688,7 @@ zzzz<??>
26882688
{
26892689
label = 'zzzz(a)',
26902690
kind = define.CompletionItemKind.Snippet,
2691-
insertText = 'zzzz(${1:a: any})',
2691+
insertText = 'zzzz(${1:a})',
26922692
},
26932693
{
26942694
label = 'zzzz(a, b)',
@@ -2698,7 +2698,7 @@ zzzz<??>
26982698
{
26992699
label = 'zzzz(a, b)',
27002700
kind = define.CompletionItemKind.Snippet,
2701-
insertText = 'zzzz(${1:a: any}, ${2:b: any})',
2701+
insertText = 'zzzz(${1:a}, ${2:b})',
27022702
},
27032703
}
27042704

@@ -2719,28 +2719,7 @@ foo<??>
27192719
{
27202720
label = 'foo(a, b, c, ...)',
27212721
kind = define.CompletionItemKind.Snippet,
2722-
insertText = 'foo(${1:a: any})',
2723-
},
2724-
}
2725-
2726-
TEST [[
2727-
---@param a any
2728-
---@param b? any
2729-
---@param c? any
2730-
---@vararg any
2731-
local function foo(a, b, c, ...) end
2732-
foo<??>
2733-
]]
2734-
{
2735-
{
2736-
label = 'foo(a, b, c, ...)',
2737-
kind = define.CompletionItemKind.Function,
2738-
insertText = 'foo',
2739-
},
2740-
{
2741-
label = 'foo(a, b, c, ...)',
2742-
kind = define.CompletionItemKind.Snippet,
2743-
insertText = 'foo(${1:a: any})',
2722+
insertText = 'foo(${1:a}, ${2:b?}, ${3:c?}, ${4:...})',
27442723
},
27452724
}
27462725

@@ -2761,28 +2740,7 @@ foo<??>
27612740
{
27622741
label = 'foo(a, b, c, ...)',
27632742
kind = define.CompletionItemKind.Snippet,
2764-
insertText = 'foo($1)',
2765-
},
2766-
}
2767-
2768-
TEST [[
2769-
---@param a? any
2770-
---@param b any
2771-
---@param c? any
2772-
---@vararg any
2773-
local function foo(a, b, c, ...) end
2774-
foo<??>
2775-
]]
2776-
{
2777-
{
2778-
label = 'foo(a, b, c, ...)',
2779-
kind = define.CompletionItemKind.Function,
2780-
insertText = 'foo',
2781-
},
2782-
{
2783-
label = 'foo(a, b, c, ...)',
2784-
kind = define.CompletionItemKind.Snippet,
2785-
insertText = 'foo(${1:a?: any}, ${2:b: any})',
2743+
insertText = 'foo(${1:a?}, ${2:b?}, ${3:c?}, ${4:...})',
27862744
},
27872745
}
27882746

@@ -2800,7 +2758,7 @@ foo<??>
28002758
{
28012759
label = 'foo(f)',
28022760
kind = define.CompletionItemKind.Snippet,
2803-
insertText = 'foo(${1:f: fun(a: any, b: any)})',
2761+
insertText = 'foo(${1:f})',
28042762
},
28052763
}
28062764
Cared['insertText'] = false

0 commit comments

Comments
 (0)