Skip to content

Proposal: target.platform directives should produce multiple BSP targets #3903

@keynmol

Description

@keynmol

Is your feature request related to a problem? Please describe.

I'm trying to find the simplest, dumbest possible way to produce a full-stack application with Scala CLI that has good support in metals.

The most general shape of an application I envision contains 3 files:

backend.scala - with purely JVM/Scala Native logic
shared.scala - with common logic and definitions between backend and frontend
frontend.scala - with purely frontend logic.

If you think of it in terms of SBT's build matrix, then shared has two "projects" - jvm and js, and backend and frontend depend on their platform-affine counterparts.

In Scala CLI, we can start simulating this by adding target.platform jvm|js to the directives – in this case only to backend and frontend, shared gets no target directive and will be compiled for both targets.

By adding those directives, the scala-cli compile command works: adding --js will only compile the JS specific files + shared.

The issue is that Metals just doesn't work. The only target created in the BSP is that for backend – frontend files have no target.

Image

The only way for this to work is to move files around in different folders, and have multiple metals instances (with no cross-navigation) – you can imagine how much worse that is.

Describe the solution you'd like

Without going the full multi-project mode, can we make this simple setup work?
Only using target.platform to produce compilation targets, similar to how -test target is created by Scala CLI when there are test files designated to test scope.

This will greatly improve the value of Scala CLI in demonstrating full stack scala, you can do quite a bit with just this setup.

Describe alternatives you've considered

This works flawlessly in SBT/Mill, albeit with more folders, but at least a single Metals instance can handle navigation between frontend-shared-backend, mostly correctly attributing definitions.

One can also move files to separate folders, setup BSP in them individually, and open each folder in a separate Metals instance. I've done this before and it's not a good way to live.

Metadata

Metadata

Assignees

No one assigned

    Labels

    IDEenhancementNew feature or requestexperimentalTickets tied to experimental features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions