scala-3-migration-guide icon indicating copy to clipboard operation
scala-3-migration-guide copied to clipboard

Document editors (metals) support for cross-built projects

Open jto opened this issue 3 years ago • 9 comments

AFAIK there's no documentation available rn about using an editor (vscode) together with metals and have support for both Scala 2.x and Scala 3 in a single project. It would be nice if that rather common use case was supported and documented.

jto avatar Nov 30 '20 10:11 jto

I agree that we are lacking documentation on this side. But it is a general concern about cross-built project (version and platform).

@tgodzik Don't you think it should be documented in the Metals website? This way we could add a link from here and maybe elaborate further for the context of the migration.

adpi2 avatar Nov 30 '20 10:11 adpi2

Not sure where to add it, we are saying here that Scala 3 is supported. We could add it also to overview, but the default behaviour is that Metals supports multiple versions at the same time.

We could add a mention in migration guide that multiple versions are supported and link to Metals with a comment to check exactly what is supported.

tgodzik avatar Nov 30 '20 10:11 tgodzik

Thanks for your replies.

Metals does support both languages out of the box but as far as I can tell, it does not support a single project having sources in both Scala 2 and Scala 3. ie. if you have macros for both languages in different folders (src/scala-2 and src/scala-3).

Maybe something needs to be configured or a specific setting set in sbt, but I could not get it working.

jto avatar Dec 01 '20 10:12 jto

Metals does support both languages out of the box but as far as I can tell, it does not support a single project having sources in both Scala 2 and Scala 3. ie. if you have macros for both languages in different folders (src/scala-2 and src/scala-3).

I guess you are using a crossScalaVersions which is a stateful way of cross building (doc in sbt).

It means that, at any given time, sbt only knows about one scalaVersion and consequently bloopInstall configure Bloop for that single version. If you run ++<scalaVersion, Bloop won't be aware of it until bloopInstall is run again (or Import build in Metals).

It is slightly better with sbt as the build server because Metals will always be in-sync with sbt when compiling. But you still need to re-import the build so that Metals is aware of the new scala-version source directory. (That can be improved in future versions with buildChange notification in BSP, that is not yet supported by sbt).

Using sbt-projectmatrix (doc here) works a lot better with Metals because it creates one project (one BSP build target) for each scalaVersion.

So yes we should document that sbt-projectmatrix is well supported by Metals but crossScalaVersion is not really.

adpi2 avatar Dec 01 '20 11:12 adpi2

We could try to always run +bloopInstall, but we would need to do a change in Bloop to generate separate build targets for each scala version. It should be simple enough though.

tgodzik avatar Dec 01 '20 11:12 tgodzik

Indeed I'm using crossScalaVersions. I would guess most cross-built projects out there do the same so it'd be great if it could "just work".

jto avatar Dec 01 '20 13:12 jto

While all of the above is true, and it would be nice if it worked, none of this is specific to Scala 3. If you have sources in scala-2.12 and scala-2.13, only one of those will be recognized by Metals. I don't think IntelliJ fares any better.

sjrd avatar Dec 01 '20 14:12 sjrd

I did not know that. Although while it's correct it does not make it any less of an issue.

You are less likely to run into the issue between Scala 2.12 and 2.13 bc. they are mostly compatible. OTOH If you cross-build for 2.13 and 3.0, you are almost guaranteed to run into this since the languages are so different. I worry that this lack of ergonomics will in practice hinder the work to cross-publish and in the end encourage libs maintainers to just stick to Scala 2.

jto avatar Dec 01 '20 15:12 jto

@jto You are totally right. I think we should be able to work on it soon. Followed up with an issue here https://github.com/scalameta/metals/issues/2287

tgodzik avatar Dec 01 '20 16:12 tgodzik