Ocamlformat_lib.CmtsSourcePlacing and formatting comments in a parsetree.
This module provides an interface to the global mutable data structure that maintains the relationship between comments and Ast terms within a parsetree.
Each comment is placed, by one of the init functions, either before or after a location appearing in the parsetree. The relocate function can be used to adjust this placement.
When comments are formatted by one of the fmt functions, they are removed from the data structure. This is significant in cases where there are multiple Ast terms with the same location.
val init :
'a Extended_ast.t ->
debug:Ocamlformat_stdlib.bool ->
Source.t ->
'a ->
Cmt.t Ocamlformat_stdlib.list ->
tinit fragment source x comments associates each comment in comments with a source location appearing in x. It uses Source to help resolve ambiguities. Initializes the state used by the fmt functions.
val relocate :
t ->
src:Ocamlformat_ocaml_common.Location.t ->
before:Ocamlformat_ocaml_common.Location.t ->
after:Ocamlformat_ocaml_common.Location.t ->
Ocamlformat_stdlib.unitrelocate src before after moves (changes the association with locations) comments before src to before and comments after src to after.
val relocate_wrongfully_attached_cmts :
t ->
Source.t ->
Extended_ast.expression ->
Ocamlformat_stdlib.unitrelocate_wrongfully_attached_cmts relocates wrongfully attached comments, e.g. comments that should be attached to the whole pattern-matching expressions (match-with or try-with expressions) but are wrongfully attached to the matched expression.
val fmt_before :
t ->
Conf.t ->
fmt_code:Fmt_odoc.fmt_code ->
?pro:Fmt.t ->
?epi:Fmt.t ->
?eol:Fmt.t ->
?adj:Fmt.t ->
Ocamlformat_ocaml_common.Location.t ->
Fmt.tfmt_before loc formats the comments associated with loc that appear before loc.
val fmt_after :
t ->
Conf.t ->
fmt_code:Fmt_odoc.fmt_code ->
?pro:Fmt.t ->
?epi:Fmt.t ->
?filter:(Cmt.t -> Ocamlformat_stdlib.bool) ->
Ocamlformat_ocaml_common.Location.t ->
Fmt.tfmt_after loc formats the comments associated with loc that appear after loc.
val fmt_within :
t ->
Conf.t ->
fmt_code:Fmt_odoc.fmt_code ->
?pro:Fmt.t ->
?epi:Fmt.t ->
Ocamlformat_ocaml_common.Location.t ->
Fmt.tfmt_within loc formats the comments associated with loc that appear within loc.
has_before t loc holds if t contains some comment before loc.
has_within t loc holds if t contains some comment within loc.
has_after t loc holds if t contains some comment after loc.
Returns comments that have not been formatted yet.
val remaining_before :
t ->
Ocamlformat_ocaml_common.Location.t ->
Cmt.t Ocamlformat_stdlib.listremaining_before c loc returns the comments before loc
val preserve :
cache_key:layout_cache_key ->
(Ocamlformat_stdlib.unit -> Fmt.t) ->
t ->
Ocamlformat_stdlib.stringpreserve f t formats like f () but returns a string and does not consume comments from t.