Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow treating every Scala CLI script as separate project. #408

Open
kasiaMarek opened this issue Dec 18, 2024 · 2 comments
Open

Allow treating every Scala CLI script as separate project. #408

kasiaMarek opened this issue Dec 18, 2024 · 2 comments

Comments

@kasiaMarek
Copy link

kasiaMarek commented Dec 18, 2024

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

Scala CLI scripts are often used a single file entities and people might have multiple of such scripts in a single directory for different tasks. Currently metals will treat all this scripts as single project, which is not always desired.

original issue: VirtusLab/scala-cli#3367

Describe the solution you'd like

Create a special script mode in Metals where each file would be considered as a separate project.

The solution could reuse FallbackMetalsLspService which is currently used for single file support. It starts a Scala CLI server for each file keeping a pool to up to 10 servers (this number could be configurable).

Alternatively

Metals should by default treat each script as a separate project. Plus add a setting that will disable this and .sc will be treated as part of the project (as currently).

Describe alternatives you've considered

  • Opening each script as a single file in the editor.
  • Keeping each script in a separate folder and opening them as workspace folders.
  • Adjusting definitions and imports in the script so they don't have conflicts and can be treated as single build.

Additional context

Starting a new server for each file isn't perfect but Scala CLI server are quite lightweight, since they mostly proxy things to Bloop. Other solution would require multi-module builds in Scala CLI, which is out of its designed scope.

Search terms

scala-cli, scripts

@SethTisue
Copy link

SethTisue commented Dec 18, 2024

Nice to see this is being considered. "Folder full of scripts" is actually my main use case for scala-cli.

@dragove
Copy link

dragove commented Jan 30, 2025

File dependency should also be considered.
For example, I have file util.sc as following

//> using scala 3.6.3
//> using dep com.lihaoyi::os-lib:0.11.3
def writeHello() = os.write(os.pwd / "x.txt", "hi\n")

and main.sc as following

//> using file util.sc
import util.writeHello
writeHello()

Currently run scala-cli main.sc generates warning:

[warn]  Using directives detected in multiple files:
- main.sc:1:1-23
- util.sc:1:1-2:41
It is recommended to keep them centralized in the /home/dove/Workspace/Scala/demo/project.scala file.

from the documentation, there is another problem: Custom source does not support chaining. sources are added only once, not recursively. This is supported by ammonite. It can be useful for managing scripts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants