Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the @service macro #887

Merged
merged 12 commits into from
Apr 23, 2020
Merged

Refactor the @service macro #887

merged 12 commits into from
Apr 23, 2020

Conversation

cb372
Copy link
Member

@cb372 cb372 commented Apr 22, 2020

Split the monolithic macro implementation into a few files.

Note: to help the compiler out with the path-dependent types arising from use of Context, the helper classes must be of the form

class MyHelper[C <: Context](val c: C)

and when you instantiate the helper, you need to give it the Context instance's singleton type:

val myHelper = new MyHelper[c.type](c)

Ideally I'd like the Operation, RPCMethod and HttpOperation classes to be in separate files, but I started to hit the limits of scalac's path-dependent types support so I had to group them together.

Potentially a few more utility methods could be moved to the TreeHelpers class, but this refactoring is a good start.

Also tidied up the HTTP-related macro code:

  • removed an unnecessary line from the val httpOperations for-comprehension
  • fixed some code that relied on the service definition trait's type parameter being called F[_] (the macro would have failed if the user decided to name their type param G[_])

Fixes #874, fixes #844

@codecov
Copy link

codecov bot commented Apr 22, 2020

Codecov Report

Merging #887 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #887   +/-   ##
=======================================
  Coverage   86.28%   86.28%           
=======================================
  Files          57       57           
  Lines         824      824           
  Branches        5        5           
=======================================
  Hits          711      711           
  Misses        113      113           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 704b65b...bd3474e. Read the comment docs.

Copy link
Member

@BenFradet BenFradet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels less clunky 👍

Copy link
Member

@juanpedromoreno juanpedromoreno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

q"""
def $name(input: $reqType): $wrappedRespType =
${clientCallMethodFor("unary")}
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the four options here are identical, except the clientMethodName, maybe we can simplify the pattern matching to get that information and leave the rest outside just once?

@cb372 cb372 merged commit 8faf14a into master Apr 23, 2020
@cb372 cb372 deleted the refactor-macro branch April 23, 2020 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor the macro Review the HTTP-related code in serviceImpl.scala
3 participants