@@ -195,16 +195,33 @@ fn nodeToCompletion(
195
195
const func = tree .fullFnProto (& buf , node ).? ;
196
196
if (func .name_token ) | name_token | {
197
197
const use_snippets = server .config .enable_snippets and server .client_capabilities .supports_snippets ;
198
- const use_placeholders = server .config .enable_argument_placeholders and server .client_capabilities .supports_snippets ;
199
- const insert_text = if (use_snippets ) blk : {
200
- if (use_placeholders ) {
201
- const skip_self_param = ! (parent_is_type_val orelse true ) and
202
- try analyser .hasSelfParam (handle , func );
203
- break :blk try Analyser .getFunctionSnippet (arena , tree , func , skip_self_param );
204
- } else {
205
- break :blk try std .fmt .allocPrint (arena , "{s}()" , .{tree .tokenSlice (func .name_token .? )});
198
+
199
+ const insert_text = blk : {
200
+ const func_name = tree .tokenSlice (func .name_token .? );
201
+
202
+ if (! use_snippets ) break :blk func_name ;
203
+
204
+ const skip_self_param = ! (parent_is_type_val orelse true ) and try analyser .hasSelfParam (handle , func );
205
+
206
+ const use_placeholders = server .config .enable_argument_placeholders ;
207
+ if (use_placeholders ) break :blk try Analyser .getFunctionSnippet (arena , tree , func , skip_self_param );
208
+
209
+ switch (func .ast .params .len ) {
210
+ // No arguments, leave cursor at the end
211
+ 0 = > break :blk try std .fmt .allocPrint (arena , "{s}()" , .{func_name }),
212
+ 1 = > {
213
+ if (skip_self_param ) {
214
+ // The one argument is a self parameter, leave cursor at the end
215
+ break :blk try std .fmt .allocPrint (arena , "{s}()" , .{func_name });
216
+ }
217
+
218
+ // Non-self parameter, leave the cursor in the parentheses
219
+ break :blk try std .fmt .allocPrint (arena , "{s}(${{1:}})" , .{func_name });
220
+ },
221
+ // Atleast one non-self parameter, leave the cursor in the parentheses
222
+ else = > break :blk try std .fmt .allocPrint (arena , "{s}(${{1:}})" , .{func_name }),
206
223
}
207
- } else tree . tokenSlice ( func . name_token .? ) ;
224
+ };
208
225
209
226
const is_type_function = Analyser .isTypeFunction (handle .tree , func );
210
227
0 commit comments