diff --git a/CHANGES.md b/CHANGES.md index 4c839d0..1f8fe34 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +# 2021-02-28, version 0.2.1 + +- Fix #1: incompatibility with toplevel + (Reported by Daian Yue). + # 2020-05-21, version 0.2.0 - Reverse the parenthesis and the constructor name for single argument, diff --git a/COPYING b/COPYING index 12be29f..287b61f 100644 --- a/COPYING +++ b/COPYING @@ -1,6 +1,6 @@ BSD 2-Clause License -Copyright (c) 2019-2020, Thierry Martinez. +Copyright (c) 2019-2021, Thierry Martinez. All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/src/ppx_show.ml b/src/ppx_show.ml index d8efaf5..2523fc0 100644 --- a/src/ppx_show.ml +++ b/src/ppx_show.ml @@ -375,23 +375,23 @@ let show_type_of_type_decl (td : type_declaration) : value_description = Ast_helper.Val.mk name ty end -let make_str ~loc ~path (rec_flag, tds) (with_path : expression option) +let make_str ~ctxt (rec_flag, tds) (with_path : expression option) : structure = let with_path = match with_path with | Some [%expr false] -> None | _ -> - match String.split_on_char '.' (Filename.basename path) with - | filename :: "ml" :: path - | filename :: _ :: "ml" :: path -> - Some (String.capitalize_ascii filename :: path) - | _ -> prerr_endline path; assert false in + let code_path = Ppxlib.Expansion_context.Deriver.code_path ctxt in + let main_module_name = Ppxlib.Code_path.main_module_name code_path in + let submodule_path = Ppxlib.Code_path.submodule_path code_path in + Some (main_module_name :: submodule_path) in let vbs = tds |> List.map (pp_of_type_decl ~with_path) in + let loc = Ppxlib.Expansion_context.Deriver.derived_item_loc ctxt in [Ast_helper.Str.value ~loc rec_flag vbs; Ast_helper.Str.value ~loc Nonrecursive (tds |> List.map show_of_type_decl)] let str_type_decl = - Ppxlib.Deriving.Generator.make + Ppxlib.Deriving.Generator.V2.make Ppxlib.Deriving.Args.(empty +> arg "with_path" __) make_str