-
Notifications
You must be signed in to change notification settings - Fork 5
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
Make worksheets work on root level with the same classpath as sbt console #173
Comments
Discussion on solutions are available here: scalameta/metals#2363 |
I did dig around a bit and this might be a bit more complex. Standalone files (outside source directories) are only compiled by Metals if a the build was reimported, because sbt treats them separately than source directories and they are not added if they do not exist. And if they have a package declared, a worksheet inside the source directories will actually pick them up, but not a worksheet outside them. What we might do here is treat worksheet the same as sbt would have treated normal scala files. In essence we should be able to add an additional condition that for sbt targets if a file is located inside the module directory it should be treated as a source file for that module. We should also suggest reimporting the build whenever a new file is added at root of a module. That however raises some questions:
I think it would be much safer to still teach people to use source directories, especially if they intend to work with sbt. Those directories are a bit complex for sure, but in that case we can use custom simpler source directories. Alternatively, they could use Mill, which does not follow the standard here and you can just use |
My opinion would probably be no. You hit on it in the last paragraph, but I think having a workspace that has a valid build plus random Scala files at the top level brings even more confusion since it gives the impression that it doesn't matter where your files are, which just isn't the case. As you also hit on, there is no guarantee that a user is using sbt, so not modeling worksheets off the way sbt console works also allows us to have consistency for worksheets across build tools. |
Hmmm. We also have the situation with a small projects with everything on top. This is very common among beginners (at least among my students). Another situation is when you just start a small project that does not need packages and you want to quickly get things done with minimal cruft. I'm thinking like this: How can we make it super easy to get going? After sbt got really easy for beginners with minimal fuzz my student started to feel comfortable with using it. Imagine starting a clean vscode dir and adding scala files and worksheets and it just works. That's a good user experience IMHO. Even if we "teach people" to jump over hoops with the src/main/scala ceremony, the simple and most intuitive option would still be to just put it on top level if you don't need packages and there is not that much code. That's what happens now in Scala 3 with top level definitions and Also, the empty package is part of the language spec so I think it should work IMHO.
I don't think scala-files on top are 'random'; they are/should be visible to the build as it inside the project dir. Consistency with how sbt interprets build.sbt would IMHO reduce confusion. |
Adding here for reference the text in the language spec about the empty package: |
As a note, if this issue was "looked into", it would be great to do alongside notebook support, which I assume would have a similar set of problems? |
Is your feature request related to a problem? Please describe.
This feature request is related to scalameta/metals#2363
With sbt you can put code on top level and get it to run without any src or together with stuff in src.
Currently, workshets in metals (server version 0.9.8) does not work outside src. This is problematic for the following reasons:
sbt console
at root project level. So code that works in the REPL using sbt'sconsole
will not work in a metals worksheet if it is placed on top level.src/main/scala
ceremony and just put all code files on top level in the project dir.Describe the solution you'd like
Relax the restriction that a worksheet must be inside
src
to see the code that gets compiled, by making worksheets at top-level also see the project code.test.worksheet.sc
, is placed at root level then it should have the same stuff on the classpath assbt console
and see all stuff compiled in top-level files such asMain.scala
in such a project:If
src/main/scala
exists that code should also be on the classpath.If there are several sub-projects, then the root level
build.sbt
should define the classpath as inThisBuild
Describe alternatives you've considered
src/main/scala
etc. This means that many existing projects with code on top level will not work with worksheet out of the box.src
.The Full solution means investigate what
sbt console
from project root level puts on the class path of the REPL-instance and use that classpath also on top-level worksheets in metals.Search terms:
worksheet, project directory structure, metals
The text was updated successfully, but these errors were encountered: