longevityframework / longevity

A Persistence Framework for Scala and NoSQL
http://longevityframework.org
Other
102 stars 6 forks source link

Add IDEA support for the longevity annotations #38

Closed sullivan- closed 7 years ago

sullivan- commented 7 years ago

IDEA can't expand the longevity macro annotations, and consequently shows error messages for primaryKey and props in an example like this:

@persistent[DomainModel]
case class User(username: Username, email: Email, fullName: FullName)

object User {
  implicit val usernameKey = primaryKey(props.username)
}

For references to User in other source files, while implicit resolution of the generated PEvs and the keys seems to work fine, we still get compiler errors on things like User.props and User.queryDsl (inherited from PType).

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.

sullivan- commented 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.

sullivan- commented 7 years ago

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.

sullivan- commented 7 years ago

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

sullivan- commented 7 years ago

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!