Skip to content

Commit bf1969f

Browse files
committed
feat: adding sections and modules in outlines
We now support sections and modules which contain document symbols in the outline.
1 parent 54562da commit bf1969f

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

language-server/dm/document.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ type proof_block_type =
2626
| TheoremKind of Decls.theorem_kind
2727
| DefinitionType of Decls.definition_object_kind
2828
| InductiveType of Vernacexpr.inductive_kind
29+
| BeginSection
30+
| BeginModule
31+
| End
2932
| Other
3033

3134
type proof_step = {
@@ -210,6 +213,11 @@ let record_outline document id (ast : Synterp.vernac_control_entry) classif (out
210213
let vernac_gen_expr = ast.v.expr in
211214
let type_, statement = match vernac_gen_expr with
212215
| VernacSynterp (Synterp.EVernacExtend _) when names <> [] -> Some Other, "external"
216+
| VernacSynterp (Synterp.EVernacBeginSection _) -> log (fun () -> Format.sprintf "BEGIN SECTION %s" (string_of_id document id)); Some BeginSection, ""
217+
| VernacSynterp (Synterp.EVernacDeclareModuleType _) -> log (fun () -> Format.sprintf "BEGIN MODULE %s" (string_of_id document id)); Some BeginModule, ""
218+
| VernacSynterp (Synterp.EVernacDefineModule _) -> log (fun () -> Format.sprintf "BEGIN MODULE %s" (string_of_id document id)); Some BeginModule, ""
219+
| VernacSynterp (Synterp.EVernacDeclareModule _) -> log (fun () -> Format.sprintf "BEGIN MODULE %s" (string_of_id document id)); Some BeginModule, ""
220+
| VernacSynterp (Synterp.EVernacEndSegment _) -> log (fun () -> Format.sprintf "END SEGMENT"); Some End, ""
213221
| VernacSynterp _ -> None, ""
214222
| VernacSynPure pure ->
215223
match pure with

language-server/dm/document.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ type proof_block_type =
2626
| TheoremKind of Decls.theorem_kind
2727
| DefinitionType of Decls.definition_object_kind
2828
| InductiveType of Vernacexpr.inductive_kind
29+
| BeginSection
30+
| BeginModule
31+
| End
2932
| Other
3033

3134
type proof_step = {

language-server/dm/documentManager.ml

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,19 +351,55 @@ let get_document_proofs st =
351351
let proofs, _ = List.partition is_theorem outline in
352352
List.map mk_proof_block proofs
353353

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
356368
let to_document_symbol elem =
357369
let Document.{name; statement; range; type_} = elem in
358370
let kind = begin match type_ with
359371
| TheoremKind _ -> SymbolKind.Function
360372
| DefinitionType _ -> SymbolKind.Variable
361373
| InductiveType _ -> SymbolKind.Struct
362374
| Other -> SymbolKind.Null
375+
| BeginSection | BeginModule -> SymbolKind.Class
376+
| End -> SymbolKind.Null
363377
end in
364378
DocumentSymbol.{name; detail=(Some statement); kind; range; selectionRange=range; children=None; deprecated=None; tags=None;}
365379
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 []
367403

368404
let interpret_to st id check_mode =
369405
let observe_id = (Id id) in

0 commit comments

Comments
 (0)