A preprocessor that works with Scala tooling

Continuing the discussion from Sponsoring work on Scala 3 macro annotations:

I just to double-check: Lombok is a Java tool and there is (yet) no analogue for Scala. is that right?

Well, Lombok is a “plugin” of javac. I put it between quotes because it uses reflection to open up private api and alter the AST so it keeps breaking with every java version.

In that regard, if what you want is an analogue, then you’ll be happy to know that scala has excellent support for compiler plugins that can do just as much.
Plugins that can fundamentally change the language syntax can only be used in by using a non stable release of scala, if memory servers right.

Heh, unfortunately, if you click the link in my original post, you will see that it goes to a post where @odersky explicitly states that compiler plugins are not to be used for this purpose, and that “something like Lombok” should be used instead, hence the question.


In particular, this paragraph:

For experimentation and research, Scala 3 introduces research plugin. Research plugins are more powerful than scalac analyzer plugins as they let plugin authors customize the whole compiler pipeline. One can easily replace the standard typer by a custom one or create a parser for a domain-specific language. However, research plugins are only enabled for nightly or snaphot releases of Scala 3.

You can do it (if that documentation is to be believed), you just can’t ship it with stable scala today.

Right, I’m aware of this. “Just can’t ship it with stable Scala” is a very large limitation, hence my question. In particular, I think tooling support from e.g. Metals can’t be relied upon.

Thanks for the quick reply!

“Just can’t ship it with stable Scala” is a very large limitation, hence my question

Pardon me if I’m being pedantic, but the same is true for Lombok, there is no support from the jdk nor guarantees, every IDE that supports it has to do so manually because it can’t rely on javac’s plugin system.
Really, lombok is analogue to this kind of plugins, totally unsupported.

I was worried about this. The classic “the old way is deprecated and the new way isn’t ready.”

I think in this case what is being talked about is source code transformation - this can be done with Scalafix by scanning for specific annotations to activate some code generation. Or whatever other tool you find works. I know sbt has support for source code generators built in.

An example of this is a simulacrum port for scala 3 using Scalafix - if you don’t want to see the generated boilerplate then you could set up your build so you only see the pretty source code, and then use code generators for what gets imported at use site

Thanks. Do I understand correctly that tooling (Metals) doesn’t work terribly well with Scalafix because e.g. code nav will be broken, taking you to the generated code instead of the base code?

Am I right that the best current option if you want tooling to work well is to mutably run scalafix right on your source as in Installation · Scalafix with scalafixOnCompile?