Closed sullivan- closed 7 years ago
It's worth noting that it is legal and equivalent to write this instead:
@persistent[DomainModel]
case class User(username: Username, email: Email, fullName: FullName)
object User extends longevity.model.PType[Domain, User] {
implicit val usernameKey = primaryKey(props.username)
}
This will remove many of the false errors that IDEA reports. Errors about User.props
, however, will still be present.
This ticket supercedes https://github.com/longevityframework/longevity/issues/36, which got bogged down with a lot of discussion of what turned out to be a false lead. I'm recreating the issue here so readers can quickly get a clear picture of the status of this issue.
This was completed by @mardo. You can find it in the idea plugins. I'll update the docs for this when I get the chance
I've updated the user manual to direct IDEA users to the plugin. Sorry for the delay on this; I was on a long vacation, and just recovering from being sick.
Thanks to @mardo for the hard work!
IDEA can't expand the longevity macro annotations, and consequently shows error messages for
primaryKey
andprops
in an example like this:For references to User in other source files, while implicit resolution of the generated
PEv
s and the keys seems to work fine, we still get compiler errors on things likeUser.props
andUser.queryDsl
(inherited fromPType
).It looks like the right way to handle this is to use the "IntelliJ API to build scala macros support": https://blog.jetbrains.com/scala/2015/10/14/intellij-api-to-build-scala-macros-support/
It seems that JetBrains is wisely skipping full-blown support for Scala macros in favor of supporting Scala.meta. See e.g. here:
https://blog.jetbrains.com/scala/2016/11/11/intellij-idea-2016-3-rc-scala-js-scala-meta-and-more/
We plan on migrating longevity from Scala macros to Scala meta as soon as possible. But the Scala.meta feature set is not quite developed enough for our needs as of yet. We're tracking progress on this front here: https://github.com/longevityframework/longevity/issues/37
So barring someone writing an IntelliJ plugin for the longevity macro annotations, we could alternatively wait and see how the situation looks after we migrate longevity to Scala.meta.