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

Omit triggering warning about directives in multple files for "//> using file ..." directives #2377

Closed
swaldman opened this issue Sep 4, 2023 · 3 comments · Fixed by #2550
Assignees
Labels
enhancement New feature or request

Comments

@swaldman
Copy link

swaldman commented Sep 4, 2023

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

I'm playing with moving much of my sysadmin-ish scripting to Scala / scala-cli. I'd like to implement most of it with shebang style scripts.

The scripts would make use of published libraries, but also local out-factorings of shared code, for which I would like to retain script-like ergonomics. For example, I might bring them into a shebang script with //> using file shared.scala, and work with the imported code.

This all works! The problem is just a warning:

[warn] ./shared.scala:1:1                                                                                                                                                                                                                                                                        
[warn] Using directives detected in multiple files. It is recommended to keep them centralized in the /Users/swaldman/Sync/BaseFolders/development-why/playpen/scala-cli-directives-in-scripts/project.scala file.                                                                               
[warn] ./script2:1:1                                                                                                                                                                                                                                                                             
[warn] Using directives detected in multiple files. It is recommended to keep them centralized in the /Users/swaldman/Sync/BaseFolders/development-why/playpen/scala-cli-directives-in-scripts/project.scala file.

This is in general a good warning! I can centralize nearly all of my directives in project.scala, and bring them in as //> using file project.scala. So in general, my scripts can just have...

//> using file project.scala
//> using file shared.scala

and shared.scala can just contain

//> using file project.scala

The settings that describe everything other than the source set for the script can and should be centralized into project.scala.

But I need the //> using file ... in multiple files. So I still have the warning.

Describe the solution you'd like
The easiest solution might be just to omit //> using file ... from the set of directives that triggers the Using directives detected in multiple files. warning. //> using file ... directives can't be centralized in that way when the entry point to the project is a script.

Describe alternatives you've considered
Another approach might be an Ammonite-like or C-pre-processor-style textual include. Top-level shebang scripts could declare their full directive set, and shared source would be brought into a single logical file. But this seems less elegant.

Additional context

Very much a work in progress, but for an example of the kind of script-set I'm trying to build, see https://github.com/swaldman/mchange-sysadmin-scripts/tree/main/taskbin

@swaldman swaldman added the enhancement New feature or request label Sep 4, 2023
@MaciejG604
Copy link
Contributor

Thank you for reporting!
Removing the mentioned warnings in case of running scripts is something worth discussing, we'll take this into consideration.

As a quick solution You can suppress those warnings globally by using:

scala-cli config suppress-warning.directives-in-multiple-files true

@swaldman
Copy link
Author

swaldman commented Sep 5, 2023

Thank you for the fast response!

In general, I think the ideal policy would be to retain the warning for scripts, but just omit //> using file ... directives from consideration. Even in scripts, it's a good idea not to create circumstances where directives are spread over multiple files, when logically one set of directives applies to the full application.

In practice, I don't know how disruptive it might be to have to distinguish between directive types before emitting the warning, though. It might not be worth the trouble.

I'm unlikely to suppress the warning globally (I think it is a good warning!). But I see that a --suppress-directives-in-multiple-files-warning command line option exists, which will work great for me for now!

One simple approach might be to just make the default value of --suppress-directives-in-multiple-files-warning for shebang true. (I also think the default value of --server should be false for shebang.)

Thanks again! scala-cli is an amazing tool, a Scala renaissance.

@tgodzik
Copy link
Member

tgodzik commented Sep 20, 2023

For now let's try to reduce the number of warnings to one with a list of all files containing directives. Not showing the warning on using file creates some more complication, which we want to avoid currently.

As a follow up in the future we could try only report conflicting options, but that's a much harder case to solve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants