Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/echo/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ let do_request ~handler request =
|> function | Ok v -> v | Error e -> failwith (Printf.sprintf "Could not reply request: %s" (Ocaml_protoc_plugin.Result.show_error e))

let () =
let name = Echo.Echo.package_service_name in
let request = mk_request () in
let reply = do_request ~handler:handle_request request in
Printf.printf "Reply: %s\n" reply
Printf.printf "Reply to %s: %s\n" name reply
8 changes: 8 additions & 0 deletions src/plugin/emit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,19 @@ let emit_service_type ~scope ~comment_db ~type_db ServiceDescriptorProto.{ name;

let proto_path = Scope.get_proto_path scope in
let ocaml_service_name = Type_db.get_service type_db ~proto_path name in
let package_service_name =
match String.split_on_char ~sep:'.' proto_path with
| [] | "":: [] -> name
| "" :: packages | packages ->
(String.concat ~sep:"." packages) ^ "." ^ name
in
let signature = Code.init () in
let implementation = Code.init () in
Code.emit_comment ~position:`Leading signature (Comment_db.get_service_comments comment_db ~proto_path ~name);
Code.emit signature `Begin "module %s : sig" ocaml_service_name;
Code.emit implementation `Begin "module %s = struct" ocaml_service_name;
Code.emit signature `None "val package_service_name : string";
Code.emit implementation `None {|let package_service_name = "%s"|} package_service_name;

List.iter ~f:(emit_method ~scope:(Scope.push scope name) ~type_db signature implementation name) methods;
Code.emit signature `End "end%s" (Code.append_deprecaton_if ~deprecated `Item "");
Expand Down