Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

protocol: Factorize printing of locations

  • Loading branch information...
commit 205d224da426c54f603066170a717b0db6458276 1 parent f96ee3c
@def-lkb def-lkb authored
Showing with 9 additions and 8 deletions.
  1. +2 −3 browse.ml
  2. +2 −5 command.ml
  3. +4 −0 protocol.ml
  4. +1 −0  protocol.mli
View
5 browse.ml
@@ -263,9 +263,8 @@ let rec dump_envs envs =
| Envs.Modtype _ -> "modtype"
| Envs.Other -> "??"
in
- `Assoc [
- "start", Protocol.pos_to_json l.Location.loc_start;
- "end", Protocol.pos_to_json l.Location.loc_end;
+ Protocol.with_location l
+ [
"kind", `String kind;
"children", dump_envs children
]
View
7 command.ml
@@ -219,11 +219,8 @@ let command_type = {
| Browse.Envs.T (loc,_,Browse.Envs.Expr e,_) :: rest ->
let ppf, to_string = Misc.ppf_to_string () in
Printtyp.type_expr ppf e;
- let item = `Assoc [
- "start", Protocol.pos_to_json loc.Location.loc_start;
- "end", Protocol.pos_to_json loc.Location.loc_end;
- "type", `String (to_string ());
- ] in
+ let item = Protocol.with_location loc ["type", `String (to_string ())]
+ in
item :: aux rest
| _ :: rest -> aux rest
| [] -> []
View
4 protocol.ml
@@ -48,3 +48,7 @@ let pos_of_json = function
end
| _ -> failwith "Incorrect position"
+let with_location loc assoc =
+ `Assoc (("start", pos_to_json loc.Location.loc_start) ::
+ ("end", pos_to_json loc.Location.loc_end) ::
+ assoc)
View
1  protocol.mli
@@ -15,3 +15,4 @@ val error_catcher : (exn -> Json.json option) ref
val make_pos : int * int -> Lexing.position
val pos_to_json : Lexing.position -> Json.json
val pos_of_json : Json.json -> Lexing.position
+val with_location : Location.t -> (string * Json.json) list -> Json.json
Please sign in to comment.
Something went wrong with that request. Please try again.