Skip to content
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

[New Command] Expand PPX nodes #1745

Merged
merged 19 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 7 additions & 3 deletions src/analysis/ppx_expand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,13 @@ let get_ppxed_source ~ppxed_parsetree ~pos ppx_kind_with_attr :
| Sig_item original_sg, _ -> (
let signature_item (self : Ast_iterator.iterator)
(new_sg : Parsetree.signature_item) =
match check_at_pos pos new_sg.psig_loc && original_sg <> new_sg with
| true -> signature := new_sg :: !signature
| false -> Ast_iterator.default_iterator.signature_item self new_sg
let included =
Location_aux.included new_sg.psig_loc ~into:original_sg.psig_loc
in
match included && original_sg <> new_sg, new_sg.psig_loc.loc_ghost with
| true, _ -> signature := new_sg :: !signature
PizieDust marked this conversation as resolved.
Show resolved Hide resolved
| false, false -> Ast_iterator.default_iterator.signature_item self new_sg
| false, true -> () (* We don't enter nested ppxes *)
in
let iterator = { Ast_iterator.default_iterator with signature_item } in
match ppxed_parsetree with
Expand Down
38 changes: 4 additions & 34 deletions tests/test-dirs/expand_node/ppx-tests.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -381,44 +381,14 @@ Module type declaration in signature
$ dune build

on attribute name deriving of type t
TODO: a cursor here should only output the derived t and now the whole module
a cursor here should only output the derived t
$ $MERLIN single expand-ppx -position 2:14 -filename ./apc.mli < ./apc.mli
{
"class": "return",
"value": {
"code": "module type Stack =
sig
type t[@@deriving rename]
include sig [@@@ocaml.warning \"-32\"] type t_renamed end[@@ocaml.doc
\"@inline\"]
[@@merlin.hide ]
type stack
val empty : stack
val is_empty : stack -> bool
val push : t -> stack -> stack
val pop : stack -> stack
val peek : stack -> t
end[@@deriving rename]
include
sig
[@@@ocaml.warning \"-32\"]
module type Stack_renamed =
sig
type t[@@deriving rename]
include sig [@@@ocaml.warning \"-32\"] type t_renamed end[@@ocaml.doc
\"@inline\"]
[@@merlin.hide ]
include sig [@@@ocaml.warning \"-32\"] type t_renamed end[@@ocaml.doc
\"@inline\"]
[@@merlin.hide ]
type stack
val empty : stack
val is_empty : stack -> bool
val push : t -> stack -> stack
val pop : stack -> stack
val peek : stack -> t
end
end[@@ocaml.doc \"@inline\"][@@merlin.hide ]",
"code": "include sig [@@@ocaml.warning \"-32\"] type t_renamed end[@@ocaml.doc
\"@inline\"][@@merlin.hide
]",
"deriver": {
"start": {
"line": 2,
Expand Down
Loading