Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build-others.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ jobs:
ocaml-compiler: ${{ matrix.ocaml-compiler }}

- name: Opam dependencies
run: opam install --deps-only -t .
run: |
opam install -y --deps-only -t ./ocamlformat-lib.opam ./ocamlformat.opam ./ocamlformat-rpc-lib.opam

- name: Format
run: opam exec -- dune fmt
Expand Down
2 changes: 1 addition & 1 deletion lib/Conf_decl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ let pp_from_src fs = function
| `File loc -> ("file", loc)
| `Attribute loc -> ("attribute", loc)
in
let fname = Fpath.to_string ~relativize:true (Fpath.v pos_fname) in
let fname = normalized_path_to_string (Fpath.v pos_fname) in
Format.fprintf fs " (%s %s:%i)" kind fname pos_lnum
| `Env -> Format.fprintf fs " (environment variable)"
| `Commandline -> Format.fprintf fs " (command line)"
Expand Down
17 changes: 11 additions & 6 deletions lib/bin_conf/Bin_conf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,15 @@ let update_using_cmdline config =
| Ok (`Ok conf_modif) -> conf_modif config
| Error _ | Ok (`Version | `Help) -> config

let path_to_absolute f =
let f =
if Fpath.is_rel f then Fpath.append (Fpath.v (Stdlib.Sys.getcwd ())) f
else f
in
Fpath.normalize f

let build_config ~enable_outside_detected_project ~root ~file ~is_stdin =
let vfile = Fpath.v file in
let file_abs = Fpath.(vfile |> to_absolute |> normalize) in
let file_abs = path_to_absolute (Fpath.v file) in
let fs =
File_system.make ~enable_outside_detected_project
~disable_conf_files:!global_conf.disable_conf_files
Expand Down Expand Up @@ -579,7 +585,7 @@ let build_config ~enable_outside_detected_project ~root ~file ~is_stdin =
| Some root ->
Format.sprintf
"no [.ocamlformat] was found within the project (root: %s)"
(Fpath.to_string ~relativize:true root)
(normalized_path_to_string root)
| None -> "no project root was found"
in
warn ~loc:(Location.in_file file)
Expand All @@ -598,7 +604,7 @@ let build_config ~enable_outside_detected_project ~root ~file ~is_stdin =
if conf.opr_opts.disable.v then "enabled" else "ignored"
in
if conf.opr_opts.debug.v then
warn ~loc "%a is %s." Fpath.pp file_abs status ;
warn ~loc "%s is %s." (normalized_path_to_string file_abs) status ;
Operational.update conf ~f:(fun f ->
{f with disable= {f.disable with v= not f.disable.v}} )
| None -> conf
Expand Down Expand Up @@ -745,8 +751,7 @@ let validate_action () =

let validate () =
let root =
Option.map !global_conf.root
~f:Fpath.(fun x -> v x |> to_absolute |> normalize)
Option.map !global_conf.root ~f:Fpath.(fun x -> path_to_absolute (v x))
in
let enable_outside_detected_project =
!global_conf.enable_outside_detected_project && Option.is_none root
Expand Down
18 changes: 11 additions & 7 deletions lib/bin_conf/File_system.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@

let project_root_witness = [".git"; ".hg"; "dune-project"]

let file_exists p = Stdlib.Sys.file_exists (Fpath.to_string p)

let is_project_root ~root dir =
match root with
| Some root -> Fpath.equal dir root
| None ->
List.exists project_root_witness ~f:(fun name ->
Fpath.(exists (dir / name)) )
file_exists Fpath.(dir / name) )

let dot_ocp_indent = ".ocp-indent"

Expand All @@ -29,7 +31,9 @@ let dot_ocamlformat_enable = ".ocamlformat-enable"
type configuration_file = Ocamlformat of Fpath.t | Ocp_indent of Fpath.t

let root_ocamlformat_file ~root =
let root = Option.value root ~default:(Fpath.cwd ()) in
let root =
match root with Some p -> p | None -> Fpath.v (Stdlib.Sys.getcwd ())
in
Fpath.(root / dot_ocamlformat)

let xdg_config () =
Expand All @@ -44,7 +48,7 @@ let xdg_config () =
match xdg_config_home with
| Some xdg_config_home ->
let filename = Fpath.(xdg_config_home / "ocamlformat") in
if Fpath.exists filename then Some filename else None
if file_exists filename then Some filename else None
| None -> None

type t =
Expand All @@ -69,24 +73,24 @@ let make ~enable_outside_detected_project ~disable_conf_files
{ fs with
ignore_files=
(let filename = Fpath.(dir / dot_ocamlformat_ignore) in
if Fpath.exists filename then filename :: fs.ignore_files
if file_exists filename then filename :: fs.ignore_files
else fs.ignore_files )
; enable_files=
(let filename = Fpath.(dir / dot_ocamlformat_enable) in
if Fpath.exists filename then filename :: fs.enable_files
if file_exists filename then filename :: fs.enable_files
else fs.enable_files )
; configuration_files=
( if disable_conf_files then []
else
let f_1 = Fpath.(dir / dot_ocamlformat) in
let files =
if Fpath.exists f_1 then
if file_exists f_1 then
Ocamlformat f_1 :: fs.configuration_files
else fs.configuration_files
in
if ocp_indent_config then
let f_2 = Fpath.(dir / dot_ocp_indent) in
if Fpath.exists f_2 then Ocp_indent f_2 :: files
if file_exists f_2 then Ocp_indent f_2 :: files
else files
else files ) }
in
Expand Down
2 changes: 1 addition & 1 deletion test/cli/global_configuration.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
The user's global configuration should be used when [--enable-outside-detected-project] is passed.

$ mkdir -p root xdg
$ export XDG_CONFIG_HOME=$PWD/xdg
$ export XDG_CONFIG_HOME=../xdg
$ echo 'break-cases = vertical' > xdg/ocamlformat

$ cd root
Expand Down
16 changes: 0 additions & 16 deletions vendor/ocamlformat-stdlib/fpath_ext.ml

This file was deleted.

17 changes: 0 additions & 17 deletions vendor/ocamlformat-stdlib/fpath_ext.mli

This file was deleted.

7 changes: 6 additions & 1 deletion vendor/ocamlformat-stdlib/ocamlformat_stdlib.ml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
include Base
include Stdio

module Fpath = Fpath_ext
module Fpath = Fpath
module List = List_ext
module String = String_ext
module Warning = Warning
module Format = Stdlib.Format
module Filename = Stdlib.Filename

let normalized_path_to_string p =
let cwd = Fpath.v (Stdlib.Sys.getcwd ()) in
let p = match Fpath.relativize ~root:cwd p with Some p -> p | None -> p in
fst (Fpath.split_volume p) ^ String.concat ~sep:"/" (Fpath.segs p)

let ( >> ) f g x = g (f x)

let impossible msg = failwith msg
Expand Down
5 changes: 4 additions & 1 deletion vendor/ocamlformat-stdlib/ocamlformat_stdlib.mli
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
include module type of Base
include module type of Stdio
module Fpath = Fpath_ext
module List = List_ext
module String = String_ext
module Warning = Warning
module Format = Stdlib.Format
module Filename = Stdlib.Filename

val normalized_path_to_string : Fpath.t -> string
(** Render a path relative to the current directory using [/] as
separator on every platforms to ensure reproducible output in tests. *)

val ( >> ) : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c
(** Composition of functions: [(f >> g) x] is exactly equivalent to
[g (f (x))]. Left associative. *)
Expand Down
Loading