Skip to content

Commit 079c80a

Browse files
committed
Create command for printing magic numbers
1 parent b0cc0c7 commit 079c80a

File tree

12 files changed

+114
-11
lines changed

12 files changed

+114
-11
lines changed

src/commands/dune

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
(flags
55
:standard
66
-open Ocaml_parsing
7+
-open Ocaml_utils
78
-open Merlin_utils
89
-open Merlin_kernel)
910
(libraries
1011
merlin-lib.ocaml_parsing
1112
merlin-lib.utils
1213
merlin-lib.kernel
1314
merlin-lib.query_protocol
14-
merlin-lib.query_commands))
15+
merlin-lib.query_commands
16+
merlin-lib.ocaml_utils))

src/commands/new_commands.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,11 @@ let all_commands =
867867
run buffer (Query_protocol.Signature_help sh)
868868
end;
869869
(* Used only for testing *)
870+
command "version" ~spec:[] ~default:() ~doc:"Print version information"
871+
begin
872+
fun buffer () -> run buffer Query_protocol.Version
873+
end;
874+
(* Used only for testing *)
870875
command "dump"
871876
~spec:
872877
[ arg "-what"

src/commands/query_json.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,4 +514,8 @@ let json_of_response (type a) (query : a t) (response : a) : json =
514514
let with_file = scope = `Project in
515515
`List (List.map locations ~f:(fun loc -> with_location ~with_file loc []))
516516
| Signature_help _, s -> json_of_signature_help s
517-
| Version, version -> `String version
517+
| Version, (version, magic_numbers) ->
518+
`Assoc
519+
[ ("version", `String version);
520+
("magicNumbers", Config.Magic_numbers.to_json magic_numbers)
521+
]

src/frontend/dune

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
(name query_protocol)
33
(public_name merlin-lib.query_protocol)
44
(modules query_protocol)
5-
(flags :standard -open Merlin_utils -open Merlin_kernel -open Ocaml_parsing -open Merlin_kernel)
6-
(libraries merlin_kernel merlin_utils ocaml_parsing))
5+
(flags :standard -open Merlin_utils -open Merlin_kernel -open Ocaml_parsing -open Ocaml_utils)
6+
(libraries merlin_kernel merlin_utils ocaml_parsing ocaml_utils))
77

88
(library
99
(name query_commands)

src/frontend/query_commands.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -978,5 +978,9 @@ let dispatch pipeline (type a) : a Query_protocol.t -> a = function
978978
}
979979
| None -> None)
980980
| Version ->
981-
Printf.sprintf "The Merlin toolkit version %s, for Ocaml %s\n"
982-
Merlin_config.version Sys.ocaml_version
981+
let version =
982+
Printf.sprintf "The Merlin toolkit version %s, for Ocaml %s\n"
983+
Merlin_config.version Sys.ocaml_version
984+
in
985+
let magic_numbers = Config.Magic_numbers.current in
986+
(version, magic_numbers)

src/frontend/query_protocol.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,4 +272,4 @@ type _ t =
272272
(** In current version, Merlin only uses the parameter [position] to answer
273273
signature_help queries. The additionnal parameters are described in the
274274
LSP protocol and might enable finer behaviour in the future. *)
275-
| Version : string t
275+
| Version : (string * Config.Magic_numbers.t) t

src/ocaml-index/bin/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(name ocaml_index)
33
(public_name ocaml-index)
44
(package ocaml-index)
5-
(libraries lib ocaml_typing ocaml_utils merlin_index_format)
5+
(libraries lib ocaml_typing ocaml_utils merlin_index_format merlin_utils yojson)
66
(flags
77
:standard
88
-open Ocaml_typing

src/ocaml-index/bin/ocaml_index.ml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,21 @@ let rewrite_root = ref false
1515
let store_shapes = ref false
1616
let do_not_use_cmt_loadpath = ref false
1717

18-
type command = Aggregate | Dump | Dump_file_stats | Stats | Gather_shapes
18+
type command =
19+
| Aggregate
20+
| Dump
21+
| Dump_file_stats
22+
| Stats
23+
| Gather_shapes
24+
| Magic_numbers
1925

2026
let parse_command = function
2127
| "aggregate" -> Some Aggregate
2228
| "dump" -> Some Dump
2329
| "dump-file-stats" -> Some Dump_file_stats
2430
| "stats" -> Some Stats
2531
| "gather-shapes" -> Some Gather_shapes
32+
| "magic-numbers" -> Some Magic_numbers
2633
| _ -> None
2734

2835
let command = ref None
@@ -128,5 +135,9 @@ let () =
128135
(Hashtbl.length cu_shape)
129136
(Option.value ~default:"none" root_directory))
130137
(List.rev !input_files_rev)
131-
| _ -> Printf.printf "Nothing to do.\n%!");
138+
| Some Magic_numbers ->
139+
let json = Config.Magic_numbers.(to_json current) in
140+
Yojson.Basic.to_channel stdout json;
141+
print_newline ()
142+
| None -> Printf.printf "Nothing to do.\n%!");
132143
exit 0

src/ocaml/utils/config.ml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,38 @@ let reserved_header_bits = 8
4848
let runtime5 = true
4949

5050
let merlin = true
51+
52+
module Magic_numbers = struct
53+
type t =
54+
{ cmi_magic_number : string;
55+
ast_intf_magic_number : string;
56+
ast_impl_magic_number : string;
57+
cmt_magic_number : string;
58+
cms_magic_number : string;
59+
index_magic_number : string
60+
}
61+
62+
let current =
63+
{ cmi_magic_number;
64+
ast_intf_magic_number;
65+
ast_impl_magic_number;
66+
cmt_magic_number;
67+
cms_magic_number;
68+
index_magic_number
69+
}
70+
71+
let to_json t =
72+
let nums =
73+
[ ("cmi_magic_number", t.cmi_magic_number);
74+
("ast_intf_magic_number", t.ast_intf_magic_number);
75+
("ast_impl_magic_number", t.ast_impl_magic_number);
76+
("cmt_magic_number", t.cmt_magic_number);
77+
("cms_magic_number", t.cms_magic_number);
78+
("index_magic_number", t.index_magic_number)
79+
]
80+
in
81+
`Assoc
82+
(List.map
83+
(fun (key, value) -> (key, Merlin_utils.Std.Json.string value))
84+
nums)
85+
end

src/ocaml/utils/config.mli

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,19 @@ val runtime5 : bool
4646

4747
val merlin : bool
4848

49+
module Magic_numbers : sig
50+
type t =
51+
{ cmi_magic_number : string;
52+
ast_intf_magic_number : string;
53+
ast_impl_magic_number : string;
54+
cmt_magic_number : string;
55+
cms_magic_number : string;
56+
index_magic_number : string
57+
}
58+
59+
val current : t
60+
61+
val to_json : t -> Std.json
62+
end
63+
4964
(**/**)

0 commit comments

Comments
 (0)