scala-cli icon indicating copy to clipboard operation
scala-cli copied to clipboard

Confusing interaction when you have a `*.worksheet.sc` in your workspace

Open ckipp01 opened this issue 2 years ago • 4 comments

Version(s) v0.1.18

Describe the bug So this isn't necessarily a bug because I understand why it happens, but I'm wondering if it makes sense to maybe change this behavior when working with a *.worksheet.sc file. The issue is that let's you have a very minimal build with a Main.scala and then also a test.worksheet.sc. Because there are both of these it thinks that there are two main methods and two files that are including imports in your project when that's not really the case. For example the user will see this when they try to scala-cli run .

Found several main classes. Which would you like to run?
[0] myapp.run
[1] test$u002Eworksheet_sc

And they'll also see a message about their using directives:

Diagnostics:
Using directives detected in multiple files. It is recommended to keep them centralized in the /Users/ckipp/Documents/scala-workspace/myapp/src/project.scala file.

In theory this is correct since the script is another main-ish thing, but not really what the user is expecting because it's a worksheet.

To Reproduce

  • Create a Main.scala with some directives
  • Create a *.worksheet.sc in the same directory
  • Either try to run and see the issue or setup an ide and also see the issue

Expected behaviour Again, I get why this happens but maybe we should special-case worksheets files to not do this.

ckipp01 avatar Dec 18 '22 15:12 ckipp01

Thanks for reporting! I think we should special case worksheet.sc and ignore them.

tgodzik avatar Dec 20 '22 19:12 tgodzik

What happens if you do "run" a worksheet? I could possibly imagine getting some utility from being able to execute some of my larger worksheets separately from an IDE.

stewSquared avatar Jun 05 '23 20:06 stewSquared

Hmm... currently the worksheets have a separate way of describing dependencies, but we want to standardize on the using directives across the board (Intellij, Metals, Scastie), there might be an intern project led by @ckipp01

When that is finished we could run worksheets separately and it should work alright.

tgodzik avatar Jun 15 '23 18:06 tgodzik

I see worksheets (especially VS Code metal worksheet) as better Scala REPL and use them regularly for rapid prototyping and giving code demo. It would be amazing to have scala-cli support for worksheets.

ganeshchand avatar Dec 29 '23 06:12 ganeshchand