-
Notifications
You must be signed in to change notification settings - Fork 409
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(melange): run melc ppx with merlin #6476
Changes from 6 commits
0d971e5
c866b7e
5de0797
b5c979e
993c0ff
4fd850e
7abc35c
4acd9e1
858dac6
c4a6d2b
5c34973
f2b7a96
c16eec2
c6e8bd6
f698bd6
9146f1b
e759821
97c0115
437fabd
dfff493
dadc896
9bc6c7d
8bacbb7
2d27c73
8ac63ba
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 | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -33,6 +33,7 @@ module Processed = struct | |||||||||||||||||||||
; src_dirs : Path.Set.t | ||||||||||||||||||||||
; flags : string list | ||||||||||||||||||||||
; extensions : string Ml_kind.Dict.t list | ||||||||||||||||||||||
; mode : [ `Ocaml | `Melange ] | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
(* ...but modules can have different preprocessing specifications*) | ||||||||||||||||||||||
|
@@ -68,7 +69,7 @@ module Processed = struct | |||||||||||||||||||||
|
||||||||||||||||||||||
let serialize_path = Path.to_absolute_filename | ||||||||||||||||||||||
|
||||||||||||||||||||||
let to_sexp ~pp { stdlib_dir; obj_dirs; src_dirs; flags; extensions } = | ||||||||||||||||||||||
let to_sexp ~pp { stdlib_dir; obj_dirs; src_dirs; flags; extensions; mode } = | ||||||||||||||||||||||
let make_directive tag value = Sexp.List [ Atom tag; value ] in | ||||||||||||||||||||||
let make_directive_of_path tag path = | ||||||||||||||||||||||
make_directive tag (Sexp.Atom (serialize_path path)) | ||||||||||||||||||||||
|
@@ -94,11 +95,20 @@ module Processed = struct | |||||||||||||||||||||
(Sexp.List (List.map ~f:(fun s -> Sexp.Atom s) flags)) | ||||||||||||||||||||||
] | ||||||||||||||||||||||
in | ||||||||||||||||||||||
match pp with | ||||||||||||||||||||||
| None -> flags | ||||||||||||||||||||||
| Some { flag; args } -> | ||||||||||||||||||||||
let flags = | ||||||||||||||||||||||
match pp with | ||||||||||||||||||||||
| None -> flags | ||||||||||||||||||||||
| Some { flag; args } -> | ||||||||||||||||||||||
make_directive "FLG" | ||||||||||||||||||||||
(Sexp.List [ Atom (Pp_kind.to_flag flag); Atom args ]) | ||||||||||||||||||||||
:: flags | ||||||||||||||||||||||
in | ||||||||||||||||||||||
match mode with | ||||||||||||||||||||||
| `Ocaml -> flags | ||||||||||||||||||||||
| `Melange -> | ||||||||||||||||||||||
make_directive "FLG" | ||||||||||||||||||||||
(Sexp.List [ Atom (Pp_kind.to_flag flag); Atom args ]) | ||||||||||||||||||||||
(Sexp.List | ||||||||||||||||||||||
[ Atom (Pp_kind.to_flag Ppx); Atom "melc -as-ppx -bs-jsx 3" ]) | ||||||||||||||||||||||
:: flags | ||||||||||||||||||||||
in | ||||||||||||||||||||||
let suffixes = | ||||||||||||||||||||||
|
@@ -120,7 +130,8 @@ module Processed = struct | |||||||||||||||||||||
in | ||||||||||||||||||||||
if String.need_quoting s then Filename.quote s else s | ||||||||||||||||||||||
|
||||||||||||||||||||||
let to_dot_merlin stdlib_dir pp_configs flags obj_dirs src_dirs extensions = | ||||||||||||||||||||||
let to_dot_merlin stdlib_dir pp_configs flags obj_dirs src_dirs extensions | ||||||||||||||||||||||
(* TODO print melange flag *) _mode = | ||||||||||||||||||||||
let b = Buffer.create 256 in | ||||||||||||||||||||||
let printf = Printf.bprintf b in | ||||||||||||||||||||||
let print = Buffer.add_string b in | ||||||||||||||||||||||
|
@@ -183,32 +194,42 @@ module Processed = struct | |||||||||||||||||||||
| Error msg -> Printf.eprintf "%s\n" msg | ||||||||||||||||||||||
| Ok [] -> Printf.eprintf "No merlin configuration found.\n" | ||||||||||||||||||||||
| Ok (init :: tl) -> | ||||||||||||||||||||||
let pp_configs, obj_dirs, src_dirs, flags, extensions = | ||||||||||||||||||||||
let pp_configs, obj_dirs, src_dirs, flags, extensions, mode = | ||||||||||||||||||||||
(* We merge what is easy to merge and ignore the rest *) | ||||||||||||||||||||||
List.fold_left tl | ||||||||||||||||||||||
~init: | ||||||||||||||||||||||
( [ init.pp_config ] | ||||||||||||||||||||||
, init.config.obj_dirs | ||||||||||||||||||||||
, init.config.src_dirs | ||||||||||||||||||||||
, [ init.config.flags ] | ||||||||||||||||||||||
, init.config.extensions ) | ||||||||||||||||||||||
, init.config.extensions | ||||||||||||||||||||||
, init.config.mode ) | ||||||||||||||||||||||
~f:(fun | ||||||||||||||||||||||
(acc_pp, acc_obj, acc_src, acc_flags, acc_ext) | ||||||||||||||||||||||
(acc_pp, acc_obj, acc_src, acc_flags, acc_ext, acc_mode) | ||||||||||||||||||||||
{ modules = _ | ||||||||||||||||||||||
; pp_config | ||||||||||||||||||||||
; config = | ||||||||||||||||||||||
{ stdlib_dir = _; obj_dirs; src_dirs; flags; extensions } | ||||||||||||||||||||||
{ stdlib_dir = _ | ||||||||||||||||||||||
; obj_dirs | ||||||||||||||||||||||
; src_dirs | ||||||||||||||||||||||
; flags | ||||||||||||||||||||||
; extensions | ||||||||||||||||||||||
; mode | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
-> | ||||||||||||||||||||||
( pp_config :: acc_pp | ||||||||||||||||||||||
, Path.Set.union acc_obj obj_dirs | ||||||||||||||||||||||
, Path.Set.union acc_src src_dirs | ||||||||||||||||||||||
, flags :: acc_flags | ||||||||||||||||||||||
, extensions @ acc_ext )) | ||||||||||||||||||||||
, extensions @ acc_ext | ||||||||||||||||||||||
, match acc_mode with | ||||||||||||||||||||||
| `Melange -> `Melange | ||||||||||||||||||||||
| `Ocaml -> mode )) | ||||||||||||||||||||||
in | ||||||||||||||||||||||
Printf.printf "%s\n" | ||||||||||||||||||||||
(to_dot_merlin init.config.stdlib_dir pp_configs flags obj_dirs src_dirs | ||||||||||||||||||||||
extensions) | ||||||||||||||||||||||
extensions mode) | ||||||||||||||||||||||
end | ||||||||||||||||||||||
|
||||||||||||||||||||||
let obj_dir_of_lib kind mode obj_dir = | ||||||||||||||||||||||
|
@@ -418,7 +439,7 @@ module Unprocessed = struct | |||||||||||||||||||||
Path.Set.union src_dirs | ||||||||||||||||||||||
(Path.Set.of_list_map ~f:Path.source more_src_dirs) | ||||||||||||||||||||||
in | ||||||||||||||||||||||
{ Processed.stdlib_dir; src_dirs; obj_dirs; flags; extensions } | ||||||||||||||||||||||
{ Processed.stdlib_dir; src_dirs; obj_dirs; flags; extensions; mode } | ||||||||||||||||||||||
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. Processed shouldn't include the mode. The flags should already contain what's needed. 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. Sorry, I spent some time trying to implement this, but I don't understand how it is possible.
Lines 92 to 95 in 75d5b40
We want melange 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. Why does it need to be a separate 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. I don't think so, there were two separate One for the OCaml flags: Lines 93 to 95 in 0280c9e
Another for the Lines 100 to 102 in 0280c9e
I don't understand how to inject the Do you or @anmonteiro see a way to "blend" it with any of the two other existing directives? 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. @rgrinberg Any thoughts on the above? Considering there were already two 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 is hacky but it looks good enough for now. A few points:
In any case, if @anmonteiro is fine with this temporary hack then we can merge it. 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. I agree we should fix 1. & 2. before merging. What's the temporary hack? the 2 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. I would expect all these melange ppx's to be ported to ppxlib and enabled explicitly. 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. that's the goal for the ReactJS PPX, as highlighted in #6476 (comment). I don't yet have a clear plan for the builtin PPX, which currently is very tightly integrated into the compiler. |
||||||||||||||||||||||
and+ pp_config = pp_config t sctx ~expander in | ||||||||||||||||||||||
let modules = | ||||||||||||||||||||||
(* And copy for each module the resulting pp flags *) | ||||||||||||||||||||||
|
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.
Shouldn't the melange ppx come first?
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.
Isn't the merlin syntax something like
FLG -ppx melc -as-ppx -bs-jsx 3
? The first atom is what renders the-ppx
flag next toFLG
.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.
We should make a note to remove the
-bs-jsx-3
stuff eventually. Here's my rough plan:(preprocess (pps reactjs_jsx_ppx))
rather than(flags :standard -bs-jsx 3)