@@ -762,29 +762,43 @@ module FormatCodeblocks = struct
762
762
max 0 (markdownBlockStartLine + currentLine - n)
763
763
in
764
764
let codeWithOffset = String. make newlinesNeeded '\n' ^ codeText in
765
-
765
+ let reportParseError diagnostics =
766
+ let buf = Buffer. create 1000 in
767
+ let formatter = Format. formatter_of_buffer buf in
768
+ Res_diagnostics. print_report ~formatter
769
+ ~custom_intro: (Some " Syntax error in code block in docstring" )
770
+ diagnostics codeWithOffset;
771
+ addError (Buffer. contents buf)
772
+ in
766
773
let formattedCode =
767
- let {Res_driver. parsetree; comments; invalid; diagnostics} =
768
- Res_driver. parse_implementation_from_source ~for_printer: true
769
- ~display_filename: displayFilename ~source: codeWithOffset
770
- in
771
- if invalid then (
772
- let buf = Buffer. create 1000 in
773
- let formatter = Format. formatter_of_buffer buf in
774
- Res_diagnostics. print_report ~formatter
775
- ~custom_intro: (Some " Syntax error in code block in docstring" )
776
- diagnostics codeWithOffset;
777
- addError (Buffer. contents buf);
778
- code)
774
+ if lang |> String. split_on_char ' ' |> List. hd = " resi" then
775
+ let {Res_driver. parsetree; comments; invalid; diagnostics} =
776
+ Res_driver. parse_interface_from_source ~for_printer: true
777
+ ~display_filename: displayFilename ~source: codeWithOffset
778
+ in
779
+ if invalid then (
780
+ reportParseError diagnostics;
781
+ code)
782
+ else
783
+ Res_printer. print_interface parsetree ~comments
784
+ |> String. trim |> Cmarkit.Block_line. list_of_string
779
785
else
780
- let parsetree =
781
- if transformAssertEqual then
782
- Transform. transform ~transforms: [AssertEqualFnToEquals ]
783
- parsetree
784
- else parsetree
786
+ let {Res_driver. parsetree; comments; invalid; diagnostics} =
787
+ Res_driver. parse_implementation_from_source ~for_printer: true
788
+ ~display_filename: displayFilename ~source: codeWithOffset
785
789
in
786
- Res_printer. print_implementation parsetree ~comments
787
- |> String. trim |> Cmarkit.Block_line. list_of_string
790
+ if invalid then (
791
+ reportParseError diagnostics;
792
+ code)
793
+ else
794
+ let parsetree =
795
+ if transformAssertEqual then
796
+ Transform. transform ~transforms: [AssertEqualFnToEquals ]
797
+ parsetree
798
+ else parsetree
799
+ in
800
+ Res_printer. print_implementation parsetree ~comments
801
+ |> String. trim |> Cmarkit.Block_line. list_of_string
788
802
in
789
803
790
804
let mappedCodeBlock =
0 commit comments