@@ -336,7 +336,7 @@ let get_document_proofs st =
336
336
let outline = Document. outline st.document in
337
337
let is_theorem Document. { type_ } =
338
338
match type_ with
339
- | TheoremKind _ -> true
339
+ | TheoremKind -> true
340
340
| _ -> false
341
341
in
342
342
let mk_proof_block Document. {statement; proof; range } =
@@ -351,19 +351,64 @@ 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
356
- let to_document_symbol elem =
357
- let Document. {name; statement; range; type_} = elem in
358
- let kind = begin match type_ with
359
- | TheoremKind _ -> SymbolKind. Function
360
- | DefinitionType _ -> SymbolKind. Variable
361
- | InductiveType _ -> SymbolKind. Struct
362
- | Other -> SymbolKind. Null
363
- end in
364
- DocumentSymbol. {name; detail= (Some statement); kind; range; selectionRange= range; children= None ; deprecated= None ; tags= None ;}
354
+ let to_document_symbol elem =
355
+ let Document. {name; statement; range; type_} = elem in
356
+ let kind = begin match type_ with
357
+ | TheoremKind -> SymbolKind. Function
358
+ | DefinitionType -> SymbolKind. Variable
359
+ | InductiveType -> SymbolKind. Struct
360
+ | Other -> SymbolKind. Null
361
+ | BeginSection | BeginModule -> SymbolKind. Class
362
+ | End -> SymbolKind. Null
363
+ end in
364
+ DocumentSymbol. {name; detail= (Some statement); kind; range; selectionRange= range; children= None ; deprecated= None ; tags= None ;}
365
+
366
+ let rec get_document_symbols outline (sec_or_m : DocumentSymbol.t list ) symbols =
367
+ let add_child (s_father : DocumentSymbol.t ) s_child =
368
+ let children = match s_father.children with
369
+ | None -> Some [s_child]
370
+ | Some l -> Some (l @ [s_child])
371
+ in
372
+ {s_father with children}
373
+ in
374
+ let record_in_outline outline symbol sec_or_m =
375
+ match sec_or_m with
376
+ | [] ->
377
+ let symbols = symbols @ [symbol] in
378
+ get_document_symbols outline sec_or_m symbols
379
+ | s :: l ->
380
+ let s = add_child s symbol in
381
+ get_document_symbols outline (s::l) symbols
365
382
in
366
- List. map to_document_symbol outline
383
+ match outline with
384
+ | [] -> symbols
385
+ | e :: l ->
386
+ let Document. {type_} = e in
387
+ match type_ with
388
+ | TheoremKind | DefinitionType | InductiveType | Other ->
389
+ let symbol = to_document_symbol e in
390
+ record_in_outline l symbol sec_or_m
391
+ | BeginSection ->
392
+ let symbol = to_document_symbol e in
393
+ get_document_symbols l (symbol :: sec_or_m) symbols
394
+ | BeginModule ->
395
+ let symbol = to_document_symbol e in
396
+ get_document_symbols l (symbol :: sec_or_m) symbols
397
+ | End ->
398
+ match sec_or_m with
399
+ | [] -> log(fun () -> " Trying to end a module or section with no begin" ); get_document_symbols l [] symbols
400
+ | symbol :: s_l ->
401
+ match s_l with
402
+ | [] ->
403
+ get_document_symbols l s_l (symbols @ [symbol])
404
+ | s_parent :: s_l ->
405
+ let s = add_child s_parent symbol in
406
+ get_document_symbols l (s :: s_l) symbols
407
+
408
+
409
+ let get_document_symbols st =
410
+ let outline = List. rev @@ Document. outline st.document in
411
+ get_document_symbols outline [] []
367
412
368
413
let interpret_to st id check_mode =
369
414
let observe_id = (Id id) in
0 commit comments