@@ -173,7 +173,7 @@ pub(crate) fn document_symbols(
173
173
ctx. include_assignments_in_blocks = state. config . symbols . include_assignments_in_blocks ;
174
174
175
175
// Extract and process all symbols from the AST
176
- if let Err ( err) = collect_symbols ( & mut ctx, & root_node, contents, 0 , & mut result) {
176
+ if let Err ( err) = collect_symbols ( & mut ctx, & root_node, contents, & mut result) {
177
177
log:: error!( "Failed to collect symbols: {err:?}" ) ;
178
178
return Ok ( Vec :: new ( ) ) ;
179
179
}
@@ -186,16 +186,15 @@ fn collect_symbols(
186
186
ctx : & mut CollectContext ,
187
187
node : & Node ,
188
188
contents : & Rope ,
189
- current_level : usize ,
190
189
symbols : & mut Vec < DocumentSymbol > ,
191
190
) -> anyhow:: Result < ( ) > {
192
191
match node. node_type ( ) {
193
192
NodeType :: Program => {
194
- collect_list_sections ( ctx, node, contents, current_level , symbols) ?;
193
+ collect_list_sections ( ctx, node, contents, symbols) ?;
195
194
} ,
196
195
197
196
NodeType :: BracedExpression => {
198
- collect_list_sections ( ctx, node, contents, current_level , symbols) ?;
197
+ collect_list_sections ( ctx, node, contents, symbols) ?;
199
198
} ,
200
199
201
200
NodeType :: IfStatement => {
@@ -205,7 +204,7 @@ fn collect_symbols(
205
204
// } else {
206
205
// x <- top_level_assignment
207
206
// }
208
- collect_if_statement ( ctx, node, contents, current_level , symbols) ?;
207
+ collect_if_statement ( ctx, node, contents, symbols) ?;
209
208
} ,
210
209
211
210
NodeType :: BinaryOperator ( BinaryOperatorType :: LeftAssignment ) |
@@ -214,15 +213,15 @@ fn collect_symbols(
214
213
} ,
215
214
216
215
NodeType :: ForStatement => {
217
- collect_for_statement ( ctx, node, contents, current_level , symbols) ?;
216
+ collect_for_statement ( ctx, node, contents, symbols) ?;
218
217
} ,
219
218
220
219
NodeType :: WhileStatement => {
221
- collect_while_statement ( ctx, node, contents, current_level , symbols) ?;
220
+ collect_while_statement ( ctx, node, contents, symbols) ?;
222
221
} ,
223
222
224
223
NodeType :: RepeatStatement => {
225
- collect_repeat_statement ( ctx, node, contents, current_level , symbols) ?;
224
+ collect_repeat_statement ( ctx, node, contents, symbols) ?;
226
225
} ,
227
226
228
227
NodeType :: Call => {
@@ -235,7 +234,7 @@ fn collect_symbols(
235
234
NodeType :: FunctionDefinition => {
236
235
let old = ctx. top_level ;
237
236
ctx. top_level = false ;
238
- collect_function ( ctx, node, contents, current_level , symbols) ?;
237
+ collect_function ( ctx, node, contents, symbols) ?;
239
238
ctx. top_level = old;
240
239
} ,
241
240
@@ -250,17 +249,16 @@ fn collect_if_statement(
250
249
ctx : & mut CollectContext ,
251
250
node : & Node ,
252
251
contents : & Rope ,
253
- current_level : usize ,
254
252
symbols : & mut Vec < DocumentSymbol > ,
255
253
) -> anyhow:: Result < ( ) > {
256
254
if let Some ( condition) = node. child_by_field_name ( "condition" ) {
257
- collect_symbols ( ctx, & condition, contents, current_level , symbols) ?;
255
+ collect_symbols ( ctx, & condition, contents, symbols) ?;
258
256
}
259
257
if let Some ( consequent) = node. child_by_field_name ( "consequence" ) {
260
- collect_symbols ( ctx, & consequent, contents, current_level , symbols) ?;
258
+ collect_symbols ( ctx, & consequent, contents, symbols) ?;
261
259
}
262
260
if let Some ( alternative) = node. child_by_field_name ( "alternative" ) {
263
- collect_symbols ( ctx, & alternative, contents, current_level , symbols) ?;
261
+ collect_symbols ( ctx, & alternative, contents, symbols) ?;
264
262
}
265
263
266
264
Ok ( ( ) )
@@ -270,17 +268,16 @@ fn collect_for_statement(
270
268
ctx : & mut CollectContext ,
271
269
node : & Node ,
272
270
contents : & Rope ,
273
- current_level : usize ,
274
271
symbols : & mut Vec < DocumentSymbol > ,
275
272
) -> anyhow:: Result < ( ) > {
276
273
if let Some ( variable) = node. child_by_field_name ( "variable" ) {
277
- collect_symbols ( ctx, & variable, contents, current_level , symbols) ?;
274
+ collect_symbols ( ctx, & variable, contents, symbols) ?;
278
275
}
279
276
if let Some ( iterator) = node. child_by_field_name ( "iterator" ) {
280
- collect_symbols ( ctx, & iterator, contents, current_level , symbols) ?;
277
+ collect_symbols ( ctx, & iterator, contents, symbols) ?;
281
278
}
282
279
if let Some ( body) = node. child_by_field_name ( "body" ) {
283
- collect_symbols ( ctx, & body, contents, current_level , symbols) ?;
280
+ collect_symbols ( ctx, & body, contents, symbols) ?;
284
281
}
285
282
286
283
Ok ( ( ) )
@@ -290,14 +287,13 @@ fn collect_while_statement(
290
287
ctx : & mut CollectContext ,
291
288
node : & Node ,
292
289
contents : & Rope ,
293
- current_level : usize ,
294
290
symbols : & mut Vec < DocumentSymbol > ,
295
291
) -> anyhow:: Result < ( ) > {
296
292
if let Some ( condition) = node. child_by_field_name ( "condition" ) {
297
- collect_symbols ( ctx, & condition, contents, current_level , symbols) ?;
293
+ collect_symbols ( ctx, & condition, contents, symbols) ?;
298
294
}
299
295
if let Some ( body) = node. child_by_field_name ( "body" ) {
300
- collect_symbols ( ctx, & body, contents, current_level , symbols) ?;
296
+ collect_symbols ( ctx, & body, contents, symbols) ?;
301
297
}
302
298
303
299
Ok ( ( ) )
@@ -307,11 +303,10 @@ fn collect_repeat_statement(
307
303
ctx : & mut CollectContext ,
308
304
node : & Node ,
309
305
contents : & Rope ,
310
- current_level : usize ,
311
306
symbols : & mut Vec < DocumentSymbol > ,
312
307
) -> anyhow:: Result < ( ) > {
313
308
if let Some ( body) = node. child_by_field_name ( "body" ) {
314
- collect_symbols ( ctx, & body, contents, current_level , symbols) ?;
309
+ collect_symbols ( ctx, & body, contents, symbols) ?;
315
310
}
316
311
317
312
Ok ( ( ) )
@@ -321,14 +316,13 @@ fn collect_function(
321
316
ctx : & mut CollectContext ,
322
317
node : & Node ,
323
318
contents : & Rope ,
324
- current_level : usize ,
325
319
symbols : & mut Vec < DocumentSymbol > ,
326
320
) -> anyhow:: Result < ( ) > {
327
321
if let Some ( parameters) = node. child_by_field_name ( "parameters" ) {
328
322
collect_function_parameters ( ctx, & parameters, contents, symbols) ?;
329
323
}
330
324
if let Some ( body) = node. child_by_field_name ( "body" ) {
331
- collect_symbols ( ctx, & body, contents, current_level , symbols) ?;
325
+ collect_symbols ( ctx, & body, contents, symbols) ?;
332
326
}
333
327
334
328
Ok ( ( ) )
@@ -383,7 +377,6 @@ fn collect_sections<F>(
383
377
ctx : & mut CollectContext ,
384
378
node : & Node ,
385
379
contents : & Rope ,
386
- current_level : usize ,
387
380
symbols : & mut Vec < DocumentSymbol > ,
388
381
mut handle_child : F ,
389
382
) -> anyhow:: Result < ( ) >
@@ -404,11 +397,8 @@ where
404
397
405
398
// If we have a section comment, add it to our stack and close any sections if needed
406
399
if let Some ( ( level, title) ) = parse_comment_as_section ( & comment_text) {
407
- let absolute_level = current_level + level;
408
-
409
400
// Close any sections with equal or higher level
410
- while !active_sections. is_empty ( ) &&
411
- active_sections. last ( ) . unwrap ( ) . level >= absolute_level
401
+ while !active_sections. is_empty ( ) && active_sections. last ( ) . unwrap ( ) . level >= level
412
402
{
413
403
// Set end position for the section being closed
414
404
if let Some ( section) = active_sections. last_mut ( ) {
@@ -420,7 +410,7 @@ where
420
410
421
411
let section = Section {
422
412
title,
423
- level : absolute_level ,
413
+ level,
424
414
start_position : child. start_position ( ) ,
425
415
end_position : None ,
426
416
children : Vec :: new ( ) ,
@@ -473,18 +463,14 @@ fn collect_list_sections(
473
463
ctx : & mut CollectContext ,
474
464
node : & Node ,
475
465
contents : & Rope ,
476
- current_level : usize ,
477
466
symbols : & mut Vec < DocumentSymbol > ,
478
467
) -> anyhow:: Result < ( ) > {
479
468
collect_sections (
480
469
ctx,
481
470
node,
482
471
contents,
483
- current_level,
484
472
symbols,
485
- |ctx, child, contents, symbols| {
486
- collect_symbols ( ctx, child, contents, current_level, symbols)
487
- } ,
473
+ |ctx, child, contents, symbols| collect_symbols ( ctx, child, contents, symbols) ,
488
474
)
489
475
}
490
476
@@ -525,7 +511,6 @@ fn collect_call_arguments(
525
511
ctx,
526
512
& arguments,
527
513
contents,
528
- 0 ,
529
514
symbols,
530
515
|ctx, child, contents, symbols| {
531
516
let Some ( arg_value) = child. child_by_field_name ( "value" ) else {
@@ -541,7 +526,7 @@ fn collect_call_arguments(
541
526
// else fallthrough
542
527
}
543
528
544
- collect_symbols ( ctx, & arg_value, contents, 0 , symbols) ?;
529
+ collect_symbols ( ctx, & arg_value, contents, symbols) ?;
545
530
546
531
Ok ( ( ) )
547
532
} ,
@@ -558,7 +543,6 @@ fn collect_function_parameters(
558
543
ctx,
559
544
& node,
560
545
contents,
561
- 0 ,
562
546
symbols,
563
547
|_ctx, _child, _contents, _symbols| {
564
548
// Only collect sections
@@ -583,7 +567,7 @@ fn collect_method(
583
567
let end = convert_point_to_position ( contents, arg_value. end_position ( ) ) ;
584
568
585
569
let mut children = vec ! [ ] ;
586
- collect_symbols ( ctx, arg_value, contents, 0 , & mut children) ?;
570
+ collect_symbols ( ctx, arg_value, contents, & mut children) ?;
587
571
588
572
let mut symbol = new_symbol_node (
589
573
arg_name_str,
@@ -631,7 +615,7 @@ fn collect_call_test_that(
631
615
let mut cursor = arguments. walk ( ) ;
632
616
for child in arguments. children_by_field_name ( "argument" , & mut cursor) {
633
617
if let Some ( value) = child. child_by_field_name ( "value" ) {
634
- collect_symbols ( ctx, & value, contents, 0 , & mut children) ?;
618
+ collect_symbols ( ctx, & value, contents, & mut children) ?;
635
619
}
636
620
}
637
621
@@ -683,13 +667,13 @@ fn collect_assignment(
683
667
684
668
// Now recurse into RHS
685
669
let mut children = Vec :: new ( ) ;
686
- collect_symbols ( ctx, & rhs, contents, 0 , & mut children) ?;
670
+ collect_symbols ( ctx, & rhs, contents, & mut children) ?;
687
671
688
672
let symbol = new_symbol_node ( name, SymbolKind :: VARIABLE , Range { start, end } , children) ;
689
673
symbols. push ( symbol) ;
690
674
} else {
691
675
// Recurse into RHS
692
- collect_symbols ( ctx, & rhs, contents, 0 , symbols) ?;
676
+ collect_symbols ( ctx, & rhs, contents, symbols) ?;
693
677
}
694
678
695
679
Ok ( ( ) )
@@ -726,7 +710,7 @@ fn collect_assignment_with_function(
726
710
727
711
// Process the function body to extract child symbols
728
712
let mut children = Vec :: new ( ) ;
729
- collect_symbols ( ctx, & rhs, contents, 0 , & mut children) ?;
713
+ collect_symbols ( ctx, & rhs, contents, & mut children) ?;
730
714
731
715
let mut symbol = new_symbol_node ( name, SymbolKind :: FUNCTION , range, children) ;
732
716
symbol. detail = Some ( detail) ;
@@ -801,7 +785,6 @@ mod tests {
801
785
& mut CollectContext :: new ( ) ,
802
786
& node,
803
787
& doc. contents ,
804
- 0 ,
805
788
& mut symbols,
806
789
)
807
790
. unwrap ( ) ;
@@ -1172,7 +1155,7 @@ outer <- 4
1172
1155
ctx. include_assignments_in_blocks = true ;
1173
1156
1174
1157
let mut symbols = Vec :: new ( ) ;
1175
- collect_symbols ( ctx, & node, & doc. contents , 0 , & mut symbols) . unwrap ( ) ;
1158
+ collect_symbols ( ctx, & node, & doc. contents , & mut symbols) . unwrap ( ) ;
1176
1159
1177
1160
insta:: assert_debug_snapshot!( symbols) ;
1178
1161
}
0 commit comments