-
Notifications
You must be signed in to change notification settings - Fork 186
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
Experimenting with scala.meta mirror #57
Conversation
👍 🎉 |
90228ba
to
f7f1f67
Compare
Replace(Symbol("_root_.cats.data.XorFunctions.left."), q"Left"), | ||
Replace(Symbol("_root_.cats.data.XorFunctions.right."), q"Right"), | ||
RemoveGlobalImport(importer"cats.data.Xor"), | ||
RemoveGlobalImport(importer"cats.data.XorT") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow. This looks amazingly concise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! This is pretty amazing. And it can easily be parsed from config files, making it easy for library authors to ship custom (simple) rewrites
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also make this interactive, i.e have a CLI app with a prompt where you can enter your refactorings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that would be doable. It would be cool to offer a preview of the diff of a single rewrite, so that you can reuse the same semantic db to run multiple rewrites.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next step, let's tie this into the @deprecated annotation. If my project has scalafix enabled, and I use a lib that has annotated a method with @deprecated while pointing it to a scalafix rewrite bundled with it, then offer to run the rewrite to remove the deprecated usage.
Type.Select(qual, Type.Name(name)) | ||
case _ => ref.syntax.parse[Type].get.asInstanceOf[Type.Ref] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this method used anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, but I was using it when I implemented organise imports with Mirror. This PR didn't manage to do the full transition.
implicit class XtensionSymbol(symbol: Symbol) { | ||
/** Returns simplified version of this Symbol. | ||
* | ||
* - No Symbol.Multi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if there are other non-trivial symbols in the multi?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then you need to write a custom rewrite. I made this normalized symbol to simplify the interface for authors writing basic rewrites, basically so it can be done via simple config file.
} | ||
tree.asInstanceOf[T] // should crash | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we add Symbol.name
and Symbol.fullName
, where the former always returns an XXX.Name
and the latter does what you implemented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be perfect 👍 I opened a ticket in scala.meta scalameta/scalameta#675
project/Build.scala
Outdated
@@ -5,12 +5,13 @@ style = defaultWithAlign | |||
}*/ | |||
|
|||
object Build { | |||
val scalametaV = "1.6.0-641" | |||
val scalametaV = "1.6.0-652.1486659769696" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this version do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Configurable fix for scalameta/scalameta#666
def unapply(tree: Tree): Option[(Tree, Tree)] = | ||
tree.parent.map(parent => tree -> parent) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was using it, and I have a similar one in scalafmt. Should probably be in contrib.
f7f1f67
to
06961c3
Compare
Doing .symbol on every Ref in a Traverser is apparently really slow. This provides a valuable lesson: scalafix should not run rewrites during compilation, scalafix should run rewrites against a semanticdb. Why? By dumping the semanticdb first, we compile as fast as possible AND it allows us to run rewrites on multiple compilation units in parallel.
06961c3
to
bf08436
Compare
I tracked down a performance issue with running the This provides a valuable lesson: scalafix should not run rewrites during compilation, scalafix should run rewrites against a pre-made semanticdb. Why?
|
163f496
to
aae9b93
Compare
This PR integrates the scala.meta mirror even more tightly into scalafix. It includes an example Xor2Either rewrite using the Symbol/Signature API.
cc/ #29 @ShaneDelmore