Skip to content
Snippets Groups Projects
Commit e11ff79e authored by David Bühler's avatar David Bühler
Browse files

[server] Logsource: also exports basename and dirname using prettified path.

parent 5e840bb7
No related branches found
No related tags found
No related merge requests found
...@@ -82,23 +82,37 @@ module LogSource = Collection ...@@ -82,23 +82,37 @@ module LogSource = Collection
(struct (struct
type t = Filepath.position type t = Filepath.position
let syntax = Sy.publish ~page:Data.page ~name:"source" let synopsis =
~synopsis:(Sy.record [ "file" , Sy.string ; "line" , Sy.int ]) Sy.record [ "dir", Sy.string; "base", Sy.string;
"file", Sy.string; "line", Sy.int ]
let syntax = Sy.publish ~page:Data.page ~name:"source" ~synopsis
~descr:(Md.plain "Source file positions.") ~descr:(Md.plain "Source file positions.")
~details:Md.([Block [Text (plain "The file path is normalized, \ ~details:Md.([Block [Text (plain "The file path is normalized, \
and the line number starts at one.")]]) and the line number starts at one.")]])
() ()
let to_json p = `Assoc [ let to_json p =
let path = Filepath.(Normalized.to_pretty_string p.pos_path) in
`Assoc [
"dir" , `String (Filename.dirname path) ;
"base" , `String (Filename.basename path) ;
"file" , `String (p.Filepath.pos_path :> string) ; "file" , `String (p.Filepath.pos_path :> string) ;
"line" , `Int p.Filepath.pos_lnum ; "line" , `Int p.Filepath.pos_lnum ;
] ]
let of_json = function let of_json js =
| `Assoc [ "file" , `String path ; "line" , `Int line ] let fail () = failure_from_type_error "Invalid source format" js in
| `Assoc [ "line" , `Int line ; "file" , `String path ] match js with
-> Log.source ~file:(Filepath.Normalized.of_string path) ~line | `Assoc assoc ->
| js -> failure_from_type_error "Invalid source format" js begin
match List.assoc "file" assoc, List.assoc "line" assoc with
| `String path, `Int line ->
Log.source ~file:(Filepath.Normalized.of_string path) ~line
| _, _ -> fail ()
| exception Not_found -> fail ()
end
| _ -> fail ()
end) end)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment