Open DavidDudson opened 6 years ago
Is it possible to configure SBT to treat the generated files differently? (i.e different scalac flags)
No, because then it masks real errors. With a lot of the macro annotations I have seen, the generated code makes up a small portion of the file. You still want compiler warnings for the parts which are untouched.
It would be nice if we could ignore scalac warnings for ranges in documents. I think the eventual approach will be to remove select unused imports though.
The original and expanded code should be in separate projects where you can tune the scalacOptions and logger level via sbt. In the generated sources you may want to filter out warnings which can be done with a
logLevel := Level.Error
You can also override the sbt compilerReporter
where you get positions of reported messages, but I don't think that's necessary.
The problem I see is something like
import scala.meta.generators.kase
import cats.NonEmptyList
@kase class Point(x: Int, y: Int)
In the above case:
After some thought, here's a few ideas I have.
Remove all unused imports in file. This would cause compiling when treating warnings as errors to pass.
Cons:
Remove any unused import of a Generator Subtype.
We only have to do this when detecting the unused imports flag, otherwise, we do not care.
Cons:
scala.meta.generators._
would not be removed, for example. (I do don't know enough about the semantic database to know if this restriction could truly be avoided, I presume the semantic database can figure out which imports are used from the wildcard, but have never experimented)The only reason we actually get this error is due to removing the annotation, thus leaving the import unused.
Cons:
import cats.NonEmptyList
@scala.meta.generators.kase class Point(x: Int, y: Int)
This becomes a non-issue and we do not have to change anything.
Cons:
Note: After some thought, we do not know where the import is, thus we cannot just ignore warnings for this. Even a compiler plugin would not be able to figure it out. So ranges do not help.
To be truly honest, I think this might be the last nail in the coffin for recursion because I like that idea best. Perhaps we should ask the community.
@olafurpg Do you agree?
IMHO, the best solutions is to not remove the annotations. The generator library should not be required to be in the classpath only the annotation declaration is required. About the recursion, we can mark in the cache which modification is executed so we have an order of already executed ones.
@apari that is the final solution at this stage... nearly complete. We are removing recursion, although you will be able to call other generators from yours, so you an do the same thing as recursion, just without the “discovery” phase.
Currently, we do not touch imports in generated files.
When we expand a generator, we remove the annotation.
Thus, code such as
will remove the annotation, leaving the import unused.
The solution to this problem is likely hard, but it should be noted somewhere in the docs at the least.