-
Notifications
You must be signed in to change notification settings - Fork 399
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
Mill support: enable importing projects which contain build.mill(.scala) but not wrapper script #674
Open
sideeffffect
wants to merge
4
commits into
JetBrains:idea243.x
Choose a base branch
from
sideeffffect:patch-1
base: idea243.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+12
−7
Open
Mill support: enable importing projects which contain build.mill(.scala) but not wrapper script #674
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line with the condition is too long and could be better formatted (every
||
condition on a new line)Given that just on a single line the same patter is repeated 3 times:
BspUtil.findFileByName(directory, fileName).isDefined
it's worth extracting into a method.I looked into the implementation of
findFileByName
and it callslistFiles
every time.So it's worth having another method, something like
def directoryContainsFile(directory: Path, fileNames: Seq[String]): Boolean
that would do one iteration over the directory files.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIU
BspUtil.findFileByName(directory, "build.sc").isDefined
checks for the "old mill"?But we already have
isLegacyBspCompatible
method, so this line isn't needed, is it?AFAIU
isLegacyBspCompatible
also avoids some false positives when a directory hasbuild.sc
file which doesn't represent a mill build file by checking for a magic lineimport $ivy.com.lihaoyi::mill-contrib-bsp:$MILL_VERSION
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That line isn't required for BSP to work as intended for many Mill versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead, just looking for Mill imports or uses might be a better heuristic.
Finding a
.mill-version
(or.config/mill-version
) file next tobuild.sc
is also strong indicator that you found a Mill project.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, got it.
My main point is that the new code:
BspUtil.findFileByName(directory, "build.sc").isDefined
makes the
isLegacyBspCompatible
method call redundant.Inside that method there is
BspUtil.findFileByName(workspace, "build.sc").exists(<has some magic line>)
.So
isLegacyBspCompatible || BspUtil.findFileByName(directory, "build.sc").isDefined
is in practice the same as
BspUtil.findFileByName(directory, "build.sc").isDefined
.I would remove the new bit and enhance the
isLegacyBspCompatible
method according to your vision in the comment above.If the name is not the most appropriate, in your opinion, then feel free to propose a better one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(BTW, thanks for contributing!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no point in making it even more sophisticated. Once there is a file
build.mill
(orbuild.mill.scala
), we can be fairly certain that we're dealing with a Mill project. No need to search for.mill-version
or anything like that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, the
.mill-version
lookup was only suggested in case you need to disambiguate the purpose of a detectedbuild.sc
, since it is common for various tools: Mill, but also Scala-CLI, Ammonite, workbooks.