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

Basic support for new .mill and .mill.scala source files #6752

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

lolgab
Copy link
Contributor

@lolgab lolgab commented Sep 3, 2024

Mill is migrating from the .sc suffix to .mill to distinguish its files from ammonite and scala-cli script files.
.sc will be still supported in a migration period

PR which introduced the new suffix: com-lihaoyi/mill#3426

Mill is migrating from the `.sc` suffix to `.mill` to distinguish its files from
ammonite and scala-cli script files.
`.sc` will be still supported in a migration period
@tgodzik
Copy link
Contributor

tgodzik commented Sep 4, 2024

We might also need to update the Scala syntax extension and Metals vs code extension

@lihaoyi
Copy link

lihaoyi commented Oct 4, 2024

@lolgab are you going to continue with this? If not I might pick it up and try to get it over the finish line

@lolgab
Copy link
Contributor Author

lolgab commented Oct 4, 2024

@lihaoyi You can complete it. Sorry for holding it so long. I was wanting for the extensions discussion to stabilize, but then I forgot about it.

@lihaoyi
Copy link

lihaoyi commented Oct 4, 2024

@lolgab no worries, I decided to put a bounty on it (com-lihaoyi/mill#3664), in case you or anyone else wants to give it a try. If nobody does I'll take a crack at it myself

@lolgab
Copy link
Contributor Author

lolgab commented Oct 4, 2024

@lihaoyi Ok, let me try to finish it.
@tgodzik opened a new PR in metals-vscode: scalameta/metals-vscode#1543

@@ -46,7 +46,7 @@ class SemanticdbTextDocumentProvider(

val explicitDialect = if (filePath.isSbt) {
Some(dialects.Sbt1)
} else if (filePath.isScalaScript) {
} else if (filePath.isMill || filePath.isScalaScript) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though we try to consider .mill not scala scripts, they are actually Scala 2.13 files with top level terms, so I believe this should stay.

@lolgab lolgab changed the title Basic support for new .mill source files Basic support for new .mill and .mill.scala source files Oct 4, 2024
Comment on lines 120 to 121
// hack for mill build sources until a proper BSP wrapped sources mapping gets into
// the official protocol
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tgodzik I managed to recreate MappedSources without BSP. The values seem to be set correctly, but still metals doesn't work correctly...
I think I need some help.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will take a look!

Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add the source mapping in this PR? I checked and it seems to work worse with it currently even when skipping checking the generated bit.

Maybe it's ok to merge without it for now. Things will work at the current level for Mill, we can improve slowly later.

generatedSourcesDirectory <- sources
.find(item =>
item
.getGenerated() && item.getKind() == b.SourceItemKind.DIRECTORY
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's not actually marked as generated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.... with Mill BSP it's actually generated correctly.

.iterator()
.asScala
.collect {
case t if t.getName().endsWith("mill-build/") =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
case t if t.getName().endsWith("mill-build/") =>
case t if t.getName().endsWith("mill-build-") =>

weirdly it's this way for Bloop. With Mill BSP it works, but it seems BSP breaks on newest mill :sigh:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is not production-ready yet. I was hacking it to make source mapping work, but I will leave it to another PR as you suggested.

@tgodzik
Copy link
Contributor

tgodzik commented Oct 10, 2024

Looks like after the changes the generated code typechecks but sometimes doesn't return completions, not sure why though. Might be worth creating a completion test and investigating, but as I said might not be neccessary for this PR.

@tgodzik
Copy link
Contributor

tgodzik commented Oct 10, 2024

And btw. my experiments are here https://github.com/scalameta/metals/compare/main...tgodzik:metals:support-mill-suffix?expand=1

Things look to work most of the time (only the completions seem to be wrong) and those are pretty big hacks

@@ -24,7 +24,7 @@ class MillifyDependencyCodeAction(buffers: Buffers) extends CodeAction {
val range = params.getRange()

val tokenized =
if (path.isScalaScript && range.getStart == range.getEnd)
if ((path.isScalaScript || path.isMill) && range.getStart == range.getEnd)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will work currently with Mill, it's for //> using dep org.something %% name % version to change it.

We could add that option to Mill build files, but it would require a bit of work (not much I think)

@@ -174,7 +174,7 @@ final class Trees(
val skipFistShebang =
if (text.startsWith("#!")) text.replaceFirst("#!", "//") else text
val input = Input.VirtualFile(path.toURI.toString(), skipFistShebang)
if (path.isAmmoniteScript || path.isMill) {
if (path.isAmmoniteScript) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this actually wrong? Do mill files have multiple stages like ammonite (don't remember why this was added actually) This actually caused multi-stage tests for ammonite fail, they might be wrong though.

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

Successfully merging this pull request may close these issues.

3 participants