fix(codegen): Fix Empty protobuf type and add unimplemented (#26)

* Add license attribute to tonic-build

* fix(codegen): Fix Empty protobuf type and add unimplemented

* Remove syn full feature
This commit is contained in:
Lucio Franco
2019-10-01 23:46:54 -04:00
committed by GitHub
parent 2734d3af28
commit 2670b349f9
6 changed files with 78 additions and 30 deletions
+11 -9
View File
@@ -2,7 +2,6 @@ use crate::generate_doc_comments;
use proc_macro2::TokenStream;
use prost_build::{Method, Service};
use quote::{format_ident, quote};
use syn::Path;
pub(crate) fn generate(service: &Service, proto: &str) -> TokenStream {
let service_ident = quote::format_ident!("{}Client", service.name);
@@ -97,8 +96,8 @@ fn generate_methods(service: &Service, proto: &str) -> TokenStream {
fn generate_unary(method: &Method, proto: &str, path: String) -> TokenStream {
let ident = format_ident!("{}", method.name);
let request: Path = syn::parse_str(&format!("{}::{}", proto, method.input_type)).unwrap();
let response: Path = syn::parse_str(&format!("{}::{}", proto, method.output_type)).unwrap();
let request = crate::replace_wellknown(proto, &method.input_type);
let response = crate::replace_wellknown(proto, &method.output_type);
quote! {
pub async fn #ident(&mut self, request: tonic::Request<#request>)
@@ -113,8 +112,9 @@ fn generate_unary(method: &Method, proto: &str, path: String) -> TokenStream {
fn generate_server_streaming(method: &Method, proto: &str, path: String) -> TokenStream {
let ident = format_ident!("{}", method.name);
let request: Path = syn::parse_str(&format!("{}::{}", proto, method.input_type)).unwrap();
let response: Path = syn::parse_str(&format!("{}::{}", proto, method.output_type)).unwrap();
let request = crate::replace_wellknown(proto, &method.input_type);
let response = crate::replace_wellknown(proto, &method.output_type);
quote! {
pub async fn #ident(&mut self, request: tonic::Request<#request>)
@@ -129,8 +129,9 @@ fn generate_server_streaming(method: &Method, proto: &str, path: String) -> Toke
fn generate_client_streaming(method: &Method, proto: &str, path: String) -> TokenStream {
let ident = format_ident!("{}", method.name);
let request: Path = syn::parse_str(&format!("{}::{}", proto, method.input_type)).unwrap();
let response: Path = syn::parse_str(&format!("{}::{}", proto, method.output_type)).unwrap();
let request = crate::replace_wellknown(proto, &method.input_type);
let response = crate::replace_wellknown(proto, &method.output_type);
quote! {
pub async fn #ident<S>(&mut self, request: tonic::Request<S>)
@@ -147,8 +148,9 @@ fn generate_client_streaming(method: &Method, proto: &str, path: String) -> Toke
fn generate_streaming(method: &Method, proto: &str, path: String) -> TokenStream {
let ident = format_ident!("{}", method.name);
let request: Path = syn::parse_str(&format!("{}::{}", proto, method.input_type)).unwrap();
let response: Path = syn::parse_str(&format!("{}::{}", proto, method.output_type)).unwrap();
let request = crate::replace_wellknown(proto, &method.input_type);
let response = crate::replace_wellknown(proto, &method.output_type);
quote! {
pub async fn #ident<S>(&mut self, request: tonic::Request<S>)