@@ -3307,7 +3307,32 @@ let gen_annot outputprefix sourcefile annots =
3307
3307
Cmt2annot. gen_annot (Some (outputprefix ^ " .annot" ))
3308
3308
~sourcefile: (Some sourcefile) ~use_summaries: false annots
3309
3309
3310
- let type_implementation sourcefile outputprefix modulename initial_env ast =
3310
+ let cms_register_toplevel_attributes ~sourcefile ~uid ~f ast =
3311
+ (* Cms files do not store the typetree. This can be a problem for Merlin has
3312
+ it uses attributes - which is why we manually construct a mapping from uid
3313
+ to attributes while typing.
3314
+ Generally `Pstr_attribute` and `Psig_attribute` are not needed by Merlin,
3315
+ except if it is the first element of the compilation unit structure or
3316
+ signature. *)
3317
+ let attr =
3318
+ match ast with
3319
+ | x :: _ -> f x
3320
+ | [] -> None
3321
+ in
3322
+ match attr with
3323
+ | None -> ()
3324
+ | Some attr ->
3325
+ Env. register_uid uid
3326
+ ~loc: (Location. in_file sourcefile)
3327
+ ~attributes: [ attr ]
3328
+
3329
+ let cms_register_toplevel_struct_attributes ~sourcefile ~uid ast =
3330
+ cms_register_toplevel_attributes ~sourcefile ~uid ast
3331
+ ~f: (function
3332
+ | { pstr_desc = Pstr_attribute attr ; _ } -> Some attr
3333
+ | _ -> None )
3334
+
3335
+ let type_implementation ~sourcefile outputprefix modulename initial_env ast =
3311
3336
let error e =
3312
3337
raise (Error (Location. in_file sourcefile, initial_env, e))
3313
3338
in
@@ -3322,10 +3347,10 @@ let type_implementation sourcefile outputprefix modulename initial_env ast =
3322
3347
let (str, sg, names, shape, finalenv) =
3323
3348
Profile. record_call " infer" (fun () ->
3324
3349
type_structure initial_env ast) in
3325
- let shape =
3326
- Shape. set_uid_if_none shape
3327
- ( Uid. of_compilation_unit_id modulename)
3328
- in
3350
+ let uid = Uid. of_compilation_unit_id modulename in
3351
+ let shape = Shape. set_uid_if_none shape uid in
3352
+ if ! Clflags. binary_annotations_cms then
3353
+ cms_register_toplevel_struct_attributes ~sourcefile ~uid ast;
3329
3354
let simple_sg = Signature_names. simplify finalenv names sg in
3330
3355
if ! Clflags. print_types then begin
3331
3356
remove_mode_and_jkind_variables finalenv sg;
@@ -3447,10 +3472,21 @@ let save_signature modname tsg outputprefix source_file initial_env cmi =
3447
3472
Cms_format. save_cms (outputprefix ^ " .cmsi" ) modname
3448
3473
(Some source_file) None
3449
3474
3450
- let type_interface modulename env ast =
3475
+ let cms_register_toplevel_signature_attributes ~sourcefile ~uid ast =
3476
+ cms_register_toplevel_attributes ~sourcefile ~uid ast
3477
+ ~f: (function
3478
+ | { psig_desc = Psig_attribute attr ; _ } -> Some attr
3479
+ | _ -> None )
3480
+
3481
+
3482
+ let type_interface ~sourcefile modulename env ast =
3451
3483
if ! Clflags. as_parameter && Compilation_unit. is_packed modulename then begin
3452
3484
raise(Error (Location. none, Env. empty, Cannot_pack_parameter ))
3453
3485
end ;
3486
+ if ! Clflags. binary_annotations_cms then begin
3487
+ let uid = Shape.Uid. of_compilation_unit_id modulename in
3488
+ cms_register_toplevel_signature_attributes ~uid ~sourcefile ast
3489
+ end ;
3454
3490
transl_signature env ast
3455
3491
3456
3492
(* "Packaging" of several compilation units into one unit
0 commit comments