Skip to content

Commit 9f33972

Browse files
Merge pull request #49 from Nymphium/main
Add complete service path to service module
2 parents aa5d254 + 949d377 commit 9f33972

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

examples/echo/test.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ let do_request ~handler request =
4848
|> function | Ok v -> v | Error e -> failwith (Printf.sprintf "Could not reply request: %s" (Ocaml_protoc_plugin.Result.show_error e))
4949

5050
let () =
51+
let name = Echo.Echo.package_service_name in
5152
let request = mk_request () in
5253
let reply = do_request ~handler:handle_request request in
53-
Printf.printf "Reply: %s\n" reply
54+
Printf.printf "Reply to %s: %s\n" name reply

src/plugin/emit.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,19 @@ let emit_service_type ~scope ~comment_db ~type_db ServiceDescriptorProto.{ name;
147147

148148
let proto_path = Scope.get_proto_path scope in
149149
let ocaml_service_name = Type_db.get_service type_db ~proto_path name in
150+
let package_service_name =
151+
match String.split_on_char ~sep:'.' proto_path with
152+
| [] | "":: [] -> name
153+
| "" :: packages | packages ->
154+
(String.concat ~sep:"." packages) ^ "." ^ name
155+
in
150156
let signature = Code.init () in
151157
let implementation = Code.init () in
152158
Code.emit_comment ~position:`Leading signature (Comment_db.get_service_comments comment_db ~proto_path ~name);
153159
Code.emit signature `Begin "module %s : sig" ocaml_service_name;
154160
Code.emit implementation `Begin "module %s = struct" ocaml_service_name;
161+
Code.emit signature `None "val package_service_name : string";
162+
Code.emit implementation `None {|let package_service_name = "%s"|} package_service_name;
155163

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

0 commit comments

Comments
 (0)