From af95981164956dcafb4f4cd72358b5d0a4ad92ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ojeda=20B=C3=A4r?= Date: Fri, 18 Oct 2024 11:42:18 +0200 Subject: [PATCH] Tweak dune file formatting: avoid pure vertical layout when formatting wrapped lists (#10892) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * format-dune-file: use a hov box instead of a hv box for wrapped lists Signed-off-by: Nicolás Ojeda Bär Signed-off-by: Marek Kubica * Add test Signed-off-by: Nicolás Ojeda Bär Signed-off-by: Marek Kubica * Accept Signed-off-by: Nicolás Ojeda Bär Signed-off-by: Marek Kubica * Add changelog entry Signed-off-by: Marek Kubica --------- Signed-off-by: Nicolás Ojeda Bär Signed-off-by: Marek Kubica Co-authored-by: Marek Kubica --- doc/changes/10892.md | 2 + src/dune_lang/format.ml | 5 +- .../describe/describe-workspace-pp.t | 51 +++++++------------ .../test-cases/describe/describe.t | 24 +++------ .../formatting/format-dune-file.t/run.t | 14 ++++- .../test-cases/github7034.t/run.t | 40 ++++----------- 6 files changed, 54 insertions(+), 82 deletions(-) create mode 100644 doc/changes/10892.md diff --git a/doc/changes/10892.md b/doc/changes/10892.md new file mode 100644 index 00000000000..ce0dfc25218 --- /dev/null +++ b/doc/changes/10892.md @@ -0,0 +1,2 @@ +- Format long lists in s-expressions to fill the line instead of formatting + them in a vertical way (#10892, fixes #10860, @nojb) diff --git a/src/dune_lang/format.ml b/src/dune_lang/format.ml index f94dfac6427..00a4996c119 100644 --- a/src/dune_lang/format.ml +++ b/src/dune_lang/format.ml @@ -26,7 +26,10 @@ let print_wrapped_list ~version x = let inner = Pp.concat_map ~sep:Pp.space ~f:pp_simple x in if version < (2, 8) then Pp.char '(' ++ Pp.hovbox ~indent:1 inner ++ Pp.char ')' - else Pp.hvbox ~indent:1 (Pp.char '(' ++ inner ++ Pp.char ')') + else + (if version < (3, 17) then Pp.hvbox else Pp.hovbox) + ~indent:1 + (Pp.char '(' ++ inner ++ Pp.char ')') ;; let pp_comment_line l = Pp.char ';' ++ Pp.verbatim l diff --git a/test/blackbox-tests/test-cases/describe/describe-workspace-pp.t b/test/blackbox-tests/test-cases/describe/describe-workspace-pp.t index a017204273c..006932d1786 100644 --- a/test/blackbox-tests/test-cases/describe/describe-workspace-pp.t +++ b/test/blackbox-tests/test-cases/describe/describe-workspace-pp.t @@ -104,20 +104,13 @@ not stable across different setups. (executables ((names (exe)) (requires - (c39d8e11db2363236e69af7750ce7b9a - c9367091ddd9a70d99fc22ede348f17c - 1f2b5eb300ea716920494385a31bb5fb - 5014e215e204cf8da6c32644cda1b31e - 249b2edaf3cc552a247667041bb5f015 - ba85adfb1c97e7d7af3df35b16b2fc0d - 2363fd46dac995a1c79679dfa1a9881b - 43b7cbe1f93f4f502ec614971027cff9 - e68a558facd1546b51c7abdbf6aed1cb - 24f4eb12e3ff51b310dbf7443c6087be - 449445be7a24ce51e119d57e9e255d3f - 5ae836dcdead11d5c16815297c5a1ae6 - 2c61db8e94cb08e0fe642152aee8121a - 6fb5d46437c55abca48c8b995f8afa51 + (c39d8e11db2363236e69af7750ce7b9a c9367091ddd9a70d99fc22ede348f17c + 1f2b5eb300ea716920494385a31bb5fb 5014e215e204cf8da6c32644cda1b31e + 249b2edaf3cc552a247667041bb5f015 ba85adfb1c97e7d7af3df35b16b2fc0d + 2363fd46dac995a1c79679dfa1a9881b 43b7cbe1f93f4f502ec614971027cff9 + e68a558facd1546b51c7abdbf6aed1cb 24f4eb12e3ff51b310dbf7443c6087be + 449445be7a24ce51e119d57e9e255d3f 5ae836dcdead11d5c16815297c5a1ae6 + 2c61db8e94cb08e0fe642152aee8121a 6fb5d46437c55abca48c8b995f8afa51 f9851d3f8ae32391e7594cf97332a78c)) (modules (((name Exe) @@ -147,8 +140,7 @@ not stable across different setups. (uid f9851d3f8ae32391e7594cf97332a78c) (local true) (requires - (ba85adfb1c97e7d7af3df35b16b2fc0d - 2c61db8e94cb08e0fe642152aee8121a + (ba85adfb1c97e7d7af3df35b16b2fc0d 2c61db8e94cb08e0fe642152aee8121a 6fb5d46437c55abca48c8b995f8afa51)) (source_dir _build/default/dummy_ppx) (modules @@ -187,14 +179,10 @@ not stable across different setups. (uid 2c61db8e94cb08e0fe642152aee8121a) (local false) (requires - (ba85adfb1c97e7d7af3df35b16b2fc0d - 2363fd46dac995a1c79679dfa1a9881b - 5014e215e204cf8da6c32644cda1b31e - 43b7cbe1f93f4f502ec614971027cff9 - e68a558facd1546b51c7abdbf6aed1cb - 24f4eb12e3ff51b310dbf7443c6087be - 5ae836dcdead11d5c16815297c5a1ae6 - 249b2edaf3cc552a247667041bb5f015 + (ba85adfb1c97e7d7af3df35b16b2fc0d 2363fd46dac995a1c79679dfa1a9881b + 5014e215e204cf8da6c32644cda1b31e 43b7cbe1f93f4f502ec614971027cff9 + e68a558facd1546b51c7abdbf6aed1cb 24f4eb12e3ff51b310dbf7443c6087be + 5ae836dcdead11d5c16815297c5a1ae6 249b2edaf3cc552a247667041bb5f015 449445be7a24ce51e119d57e9e255d3f)) (source_dir /FINDLIB/ppxlib) (modules ()) @@ -296,8 +284,7 @@ not stable across different setups. (uid f9851d3f8ae32391e7594cf97332a78c) (local true) (requires - (ba85adfb1c97e7d7af3df35b16b2fc0d - 2c61db8e94cb08e0fe642152aee8121a + (ba85adfb1c97e7d7af3df35b16b2fc0d 2c61db8e94cb08e0fe642152aee8121a 6fb5d46437c55abca48c8b995f8afa51)) (source_dir _build/default/dummy_ppx) (modules @@ -349,14 +336,10 @@ not stable across different setups. (uid 2c61db8e94cb08e0fe642152aee8121a) (local false) (requires - (ba85adfb1c97e7d7af3df35b16b2fc0d - 2363fd46dac995a1c79679dfa1a9881b - 5014e215e204cf8da6c32644cda1b31e - 43b7cbe1f93f4f502ec614971027cff9 - e68a558facd1546b51c7abdbf6aed1cb - 24f4eb12e3ff51b310dbf7443c6087be - 5ae836dcdead11d5c16815297c5a1ae6 - 249b2edaf3cc552a247667041bb5f015 + (ba85adfb1c97e7d7af3df35b16b2fc0d 2363fd46dac995a1c79679dfa1a9881b + 5014e215e204cf8da6c32644cda1b31e 43b7cbe1f93f4f502ec614971027cff9 + e68a558facd1546b51c7abdbf6aed1cb 24f4eb12e3ff51b310dbf7443c6087be + 5ae836dcdead11d5c16815297c5a1ae6 249b2edaf3cc552a247667041bb5f015 449445be7a24ce51e119d57e9e255d3f)) (source_dir /FINDLIB/ppxlib) (modules ()) diff --git a/test/blackbox-tests/test-cases/describe/describe.t b/test/blackbox-tests/test-cases/describe/describe.t index 598fde3193d..d283af9e5f1 100644 --- a/test/blackbox-tests/test-cases/describe/describe.t +++ b/test/blackbox-tests/test-cases/describe/describe.t @@ -546,14 +546,10 @@ not stable across different setups. (uid 2c61db8e94cb08e0fe642152aee8121a) (local false) (requires - (ba85adfb1c97e7d7af3df35b16b2fc0d - 2363fd46dac995a1c79679dfa1a9881b - 5014e215e204cf8da6c32644cda1b31e - 43b7cbe1f93f4f502ec614971027cff9 - e68a558facd1546b51c7abdbf6aed1cb - 24f4eb12e3ff51b310dbf7443c6087be - 5ae836dcdead11d5c16815297c5a1ae6 - 249b2edaf3cc552a247667041bb5f015 + (ba85adfb1c97e7d7af3df35b16b2fc0d 2363fd46dac995a1c79679dfa1a9881b + 5014e215e204cf8da6c32644cda1b31e 43b7cbe1f93f4f502ec614971027cff9 + e68a558facd1546b51c7abdbf6aed1cb 24f4eb12e3ff51b310dbf7443c6087be + 5ae836dcdead11d5c16815297c5a1ae6 249b2edaf3cc552a247667041bb5f015 449445be7a24ce51e119d57e9e255d3f)) (source_dir /FINDLIB/ppxlib) (modules ()) @@ -1120,14 +1116,10 @@ not stable across different setups. (uid 2c61db8e94cb08e0fe642152aee8121a) (local false) (requires - (ba85adfb1c97e7d7af3df35b16b2fc0d - 2363fd46dac995a1c79679dfa1a9881b - 5014e215e204cf8da6c32644cda1b31e - 43b7cbe1f93f4f502ec614971027cff9 - e68a558facd1546b51c7abdbf6aed1cb - 24f4eb12e3ff51b310dbf7443c6087be - 5ae836dcdead11d5c16815297c5a1ae6 - 249b2edaf3cc552a247667041bb5f015 + (ba85adfb1c97e7d7af3df35b16b2fc0d 2363fd46dac995a1c79679dfa1a9881b + 5014e215e204cf8da6c32644cda1b31e 43b7cbe1f93f4f502ec614971027cff9 + e68a558facd1546b51c7abdbf6aed1cb 24f4eb12e3ff51b310dbf7443c6087be + 5ae836dcdead11d5c16815297c5a1ae6 249b2edaf3cc552a247667041bb5f015 449445be7a24ce51e119d57e9e255d3f)) (source_dir /FINDLIB/ppxlib) (modules ()) diff --git a/test/blackbox-tests/test-cases/formatting/format-dune-file.t/run.t b/test/blackbox-tests/test-cases/formatting/format-dune-file.t/run.t index 9fd4bab833b..42d6fcca263 100644 --- a/test/blackbox-tests/test-cases/formatting/format-dune-file.t/run.t +++ b/test/blackbox-tests/test-cases/formatting/format-dune-file.t/run.t @@ -49,7 +49,7 @@ When a list is indented, there is no extra space at the end. When there is a long list of atoms, quoted strings, templates and singletons, it gets wrapped. - $ echo '(library (name dune) (libraries unix stdune fiber xdg dune_re threads opam_file_format dune_lang ocaml_config which_program) (synopsis "Internal Dune library, do not use!") (preprocess (action (run %{project_root}/src/let-syntax/pp.exe %{input-file}))))' | dune format-dune-file + $ echo '(library (name dune) (libraries unix stdune fiber xdg dune_re threads opam_file_format dune_lang ocaml_config which_program) (synopsis "Internal Dune library, do not use!") (preprocess (action (run %{project_root}/src/let-syntax/pp.exe %{input-file}))))' | dune format-dune-file --dune-version 3.16 (library (name dune) (libraries @@ -68,6 +68,18 @@ it gets wrapped. (action (run %{project_root}/src/let-syntax/pp.exe %{input-file})))) +The same file, but in the current version: + + $ echo '(library (name dune) (libraries unix stdune fiber xdg dune_re threads opam_file_format dune_lang ocaml_config which_program) (synopsis "Internal Dune library, do not use!") (preprocess (action (run %{project_root}/src/let-syntax/pp.exe %{input-file}))))' | dune format-dune-file + (library + (name dune) + (libraries unix stdune fiber xdg dune_re threads opam_file_format dune_lang + ocaml_config which_program) + (synopsis "Internal Dune library, do not use!") + (preprocess + (action + (run %{project_root}/src/let-syntax/pp.exe %{input-file})))) + In multi-line strings, newlines are escaped, but their syntax is not preserved. $ dune format-dune-file <