-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix cinaps comment formatting to not change multiline string contents. #2463
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,11 @@ open Odoc_parser.Ast | |
module Loc = Odoc_parser.Loc | ||
|
||
type fmt_code = | ||
Conf.t -> offset:int -> string -> (string, [`Msg of string]) Result.t | ||
Conf.t | ||
-> offset:int | ||
-> set_margin:bool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might get rid of the |
||
-> string | ||
-> (Fmt.t, [`Msg of string]) Result.t | ||
|
||
type c = {fmt_code: fmt_code; conf: Conf.t} | ||
|
||
|
@@ -119,8 +123,8 @@ let fmt_code_block c s1 s2 = | |
match s1 with | ||
| Some ({value= "ocaml"; _}, _) | None -> ( | ||
(* [offset] doesn't take into account code blocks nested into lists. *) | ||
match c.fmt_code c.conf ~offset:2 original with | ||
| Ok formatted -> fmt_code formatted | ||
match c.fmt_code c.conf ~offset:2 ~set_margin:true original with | ||
| Ok formatted -> formatted |> Format_.asprintf "%a" Fmt.eval |> fmt_code | ||
| Error (`Msg message) -> | ||
( match message with | ||
| "" -> () | ||
|
@@ -356,8 +360,8 @@ let fmt_parsed (conf : Conf.t) ~fmt_code ~input ~offset parsed = | |
let begin_offset = beginning_offset conf input in | ||
(* The offset is used to adjust the margin when formatting code blocks. *) | ||
let offset = offset + begin_offset in | ||
let fmt_code conf ~offset:offset' input = | ||
fmt_code conf ~offset:(offset + offset') input | ||
let fmt_code conf ~offset:offset' ~set_margin input = | ||
fmt_code conf ~offset:(offset + offset') ~set_margin input | ||
in | ||
let fmt_parsed parsed = | ||
str (String.make begin_offset ' ') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Warning: tests/cinaps.ml:24 exceeds the margin |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ let y = 2 | |
#use "import.cinaps" ;; | ||
|
||
List.iter all_fields ~f:(fun (name, type_) -> | ||
printf "\nexternal get_%s\n: unit -> %s = \"get_%s\"" name type_ name ) | ||
printf "\nexternal get_%s\n : unit -> %s = \"get_%s\"" name type_ name ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be intended but I'd like confirmation. The original comment is: (*$ ;; #use "import.cinaps"
;; List.iter all_fields ~f:(fun (name, type_) -> printf "\nexternal get_%s
: unit -> %s = \"get_%s\"" name type_ name) *) Are the two spaces on the last line part of the string constant ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, they are part of the string constant:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for confirming, I'll merge then! |
||
*) | ||
external get_name : unit -> string = "get_name" | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean this PR changed the formatting of cinaps comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. The new output looks more like the input. I don't think this patch would change already formatted code.