@@ -68,6 +68,8 @@ fn typeToCompletion(
68
68
.{ .node = n , .handle = type_handle .handle },
69
69
field_access .unwrapped ,
70
70
orig_handle ,
71
+ null ,
72
+ null ,
71
73
type_handle .type .is_type_val ,
72
74
null ,
73
75
either_descriptor ,
@@ -123,6 +125,8 @@ fn nodeToCompletion(
123
125
node_handle : Analyser.NodeWithHandle ,
124
126
unwrapped : ? Analyser.TypeWithHandle ,
125
127
orig_handle : * const DocumentStore.Handle ,
128
+ orig_name : ? []const u8 ,
129
+ orig_doc : ? []const u8 ,
126
130
is_type_val : bool ,
127
131
parent_is_type_val : ? bool ,
128
132
either_descriptor : ? []const u8 ,
@@ -137,11 +141,19 @@ fn nodeToCompletion(
137
141
const datas = tree .nodes .items (.data );
138
142
const token_tags = tree .tokens .items (.tag );
139
143
140
- var doc_comments = try Analyser .getDocComments (arena , handle .tree , node );
141
- if (doc_comments == null ) {
142
- if (try analyser .resolveVarDeclAlias (node_handle )) | result | {
143
- doc_comments = try result .docComments (arena );
144
- }
144
+ var doc_comments = orig_doc orelse (try Analyser .getDocComments (arena , handle .tree , node ));
145
+ if (try analyser .resolveVarDeclAlias (node_handle )) | result | {
146
+ const context = DeclToCompletionContext {
147
+ .server = server ,
148
+ .analyser = analyser ,
149
+ .arena = arena ,
150
+ .completions = list ,
151
+ .orig_handle = orig_handle ,
152
+ .orig_name = Analyser .getDeclName (tree , node ),
153
+ .orig_doc = doc_comments ,
154
+ .either_descriptor = either_descriptor ,
155
+ };
156
+ return try declToCompletion (context , result );
145
157
}
146
158
147
159
const doc = try completionDoc (
@@ -194,17 +206,20 @@ fn nodeToCompletion(
194
206
var buf : [1 ]Ast.Node.Index = undefined ;
195
207
const func = tree .fullFnProto (& buf , node ).? ;
196
208
if (func .name_token ) | name_token | {
209
+ const func_name = orig_name orelse tree .tokenSlice (name_token );
197
210
const use_snippets = server .config .enable_snippets and server .client_capabilities .supports_snippets ;
198
211
199
212
const insert_text = blk : {
200
- const func_name = tree .tokenSlice (func .name_token .? );
201
-
202
213
if (! use_snippets ) break :blk func_name ;
203
214
204
215
const skip_self_param = ! (parent_is_type_val orelse true ) and try analyser .hasSelfParam (handle , func );
205
216
206
217
const use_placeholders = server .config .enable_argument_placeholders ;
207
- if (use_placeholders ) break :blk try Analyser .getFunctionSnippet (arena , tree , func , skip_self_param );
218
+ if (use_placeholders ) {
219
+ var it = func .iterate (& tree );
220
+ if (skip_self_param ) _ = ast .nextFnParam (& it );
221
+ break :blk try Analyser .getFunctionSnippet (arena , func_name , & it );
222
+ }
208
223
209
224
switch (func .ast .params .len ) {
210
225
// No arguments, leave cursor at the end
@@ -226,7 +241,7 @@ fn nodeToCompletion(
226
241
const is_type_function = Analyser .isTypeFunction (handle .tree , func );
227
242
228
243
try list .append (arena , .{
229
- .label = handle . tree . tokenSlice ( name_token ) ,
244
+ .label = func_name ,
230
245
.kind = if (is_type_function ) .Struct else .Function ,
231
246
.documentation = doc ,
232
247
.detail = Analyser .getFunctionSignature (handle .tree , func ),
@@ -241,14 +256,15 @@ fn nodeToCompletion(
241
256
.simple_var_decl ,
242
257
= > {
243
258
const var_decl = tree .fullVarDecl (node ).? ;
259
+ const name = orig_name orelse tree .tokenSlice (var_decl .ast .mut_token + 1 );
244
260
const is_const = token_tags [var_decl .ast .mut_token ] == .keyword_const ;
245
261
246
262
try list .append (arena , .{
247
- .label = handle . tree . tokenSlice ( var_decl . ast . mut_token + 1 ) ,
263
+ .label = name ,
248
264
.kind = if (is_const ) .Constant else .Variable ,
249
265
.documentation = doc ,
250
266
.detail = try Analyser .getVariableSignature (arena , tree , var_decl ),
251
- .insertText = tree . tokenSlice ( var_decl . ast . mut_token + 1 ) ,
267
+ .insertText = name ,
252
268
.insertTextFormat = .PlainText ,
253
269
});
254
270
},
@@ -257,12 +273,13 @@ fn nodeToCompletion(
257
273
.container_field_init ,
258
274
= > {
259
275
const field = tree .fullContainerField (node ).? ;
276
+ const name = tree .tokenSlice (field .ast .main_token );
260
277
try list .append (arena , .{
261
- .label = handle . tree . tokenSlice ( field . ast . main_token ) ,
278
+ .label = name ,
262
279
.kind = if (field .ast .tuple_like ) .EnumMember else .Field ,
263
280
.documentation = doc ,
264
281
.detail = Analyser .getContainerFieldSignature (handle .tree , field ),
265
- .insertText = tree . tokenSlice ( field . ast . main_token ) ,
282
+ .insertText = name ,
266
283
.insertTextFormat = .PlainText ,
267
284
});
268
285
},
@@ -357,6 +374,8 @@ const DeclToCompletionContext = struct {
357
374
arena : std.mem.Allocator ,
358
375
completions : * std .ArrayListUnmanaged (types .CompletionItem ),
359
376
orig_handle : * const DocumentStore.Handle ,
377
+ orig_name : ? []const u8 = null ,
378
+ orig_doc : ? []const u8 = null ,
360
379
parent_is_type_val : ? bool = null ,
361
380
either_descriptor : ? []const u8 = null ,
362
381
};
@@ -393,12 +412,15 @@ fn declToCompletion(context: DeclToCompletionContext, decl_handle: Analyser.Decl
393
412
.{ .node = node , .handle = decl_handle .handle },
394
413
null ,
395
414
context .orig_handle ,
415
+ context .orig_name ,
416
+ context .orig_doc ,
396
417
false ,
397
418
context .parent_is_type_val ,
398
419
context .either_descriptor ,
399
420
),
400
421
.param_payload = > | pay | {
401
422
const param = pay .param ;
423
+ const name = tree .tokenSlice (param .name_token .? );
402
424
const doc = try completionDoc (
403
425
context .server ,
404
426
context .arena ,
@@ -407,11 +429,11 @@ fn declToCompletion(context: DeclToCompletionContext, decl_handle: Analyser.Decl
407
429
);
408
430
409
431
try context .completions .append (context .arena , .{
410
- .label = tree . tokenSlice ( param . name_token .? ) ,
432
+ .label = name ,
411
433
.kind = .Constant ,
412
434
.documentation = doc ,
413
435
.detail = ast .paramSlice (tree , param ),
414
- .insertText = tree . tokenSlice ( param . name_token .? ) ,
436
+ .insertText = name ,
415
437
.insertTextFormat = .PlainText ,
416
438
});
417
439
},
@@ -792,11 +814,12 @@ pub fn collectContainerFields(
792
814
const container_decl = Ast .fullContainerDecl (container .handle .tree , & buffer , node ) orelse return ;
793
815
for (container_decl .ast .members ) | member | {
794
816
const field = container .handle .tree .fullContainerField (member ) orelse continue ;
817
+ const name = container .handle .tree .tokenSlice (field .ast .main_token );
795
818
try completions .append (arena , .{
796
- .label = container . handle . tree . tokenSlice ( field . ast . main_token ) ,
819
+ .label = name ,
797
820
.kind = if (field .ast .tuple_like ) .EnumMember else .Field ,
798
821
.detail = Analyser .getContainerFieldSignature (container .handle .tree , field ),
799
- .insertText = container . handle . tree . tokenSlice ( field . ast . main_token ) ,
822
+ .insertText = name ,
800
823
.insertTextFormat = .PlainText ,
801
824
});
802
825
}
0 commit comments