Skip to content

Commit

Permalink
protocol: Factorize printing of locations
Browse files Browse the repository at this point in the history
  • Loading branch information
let-def committed Feb 19, 2013
1 parent f96ee3c commit 205d224
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
5 changes: 2 additions & 3 deletions browse.ml
Expand Up @@ -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
]
Expand Down
7 changes: 2 additions & 5 deletions command.ml
Expand Up @@ -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
| [] -> []
Expand Down
4 changes: 4 additions & 0 deletions protocol.ml
Expand Up @@ -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)
1 change: 1 addition & 0 deletions protocol.mli
Expand Up @@ -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

0 comments on commit 205d224

Please sign in to comment.