@@ -351,19 +351,55 @@ let get_document_proofs st =
351
351
let proofs, _ = List. partition is_theorem outline in
352
352
List. map mk_proof_block proofs
353
353
354
- let get_document_symbols st =
355
- let outline = Document. outline st.document in
354
+ let rec get_document_symbols outline (sec_or_m : DocumentSymbol.t option ) symbols =
355
+ let record_in_outline outline symbol sec_or_m =
356
+ match sec_or_m with
357
+ | None ->
358
+ let symbols = symbols @ [symbol] in
359
+ get_document_symbols outline sec_or_m symbols
360
+ | Some sec_or_m ->
361
+ let children = match sec_or_m.children with
362
+ | None -> Some [symbol]
363
+ | Some l -> Some (l @ [symbol])
364
+ in
365
+ let sec_or_m = Some {sec_or_m with children} in
366
+ get_document_symbols outline sec_or_m symbols
367
+ in
356
368
let to_document_symbol elem =
357
369
let Document. {name; statement; range; type_} = elem in
358
370
let kind = begin match type_ with
359
371
| TheoremKind _ -> SymbolKind. Function
360
372
| DefinitionType _ -> SymbolKind. Variable
361
373
| InductiveType _ -> SymbolKind. Struct
362
374
| Other -> SymbolKind. Null
375
+ | BeginSection | BeginModule -> SymbolKind. Class
376
+ | End -> SymbolKind. Null
363
377
end in
364
378
DocumentSymbol. {name; detail= (Some statement); kind; range; selectionRange= range; children= None ; deprecated= None ; tags= None ;}
365
379
in
366
- List. map to_document_symbol outline
380
+ match outline with
381
+ | [] -> symbols
382
+ | e :: l ->
383
+ let Document. {type_} = e in
384
+ match type_ with
385
+ | TheoremKind _ | DefinitionType _ | InductiveType _ | Other ->
386
+ let symbol = to_document_symbol e in
387
+ record_in_outline l symbol sec_or_m
388
+ | BeginSection ->
389
+ let symbol = to_document_symbol e in
390
+ get_document_symbols l (Some symbol) symbols
391
+ | BeginModule ->
392
+ let symbol = to_document_symbol e in
393
+ get_document_symbols l (Some symbol) symbols
394
+ | End ->
395
+ match sec_or_m with
396
+ | None -> log(fun () -> " Trying to end a module or section with no begin" ); get_document_symbols l None symbols
397
+ | Some symbol ->
398
+ get_document_symbols l None (symbols @ [symbol])
399
+
400
+ let get_document_symbols st =
401
+ let outline = List. rev @@ Document. outline st.document in
402
+ get_document_symbols outline None []
367
403
368
404
let interpret_to st id check_mode =
369
405
let observe_id = (Id id) in
0 commit comments