Skip to content

Commit 7b62c39

Browse files
authored
MillBuildRootModule: Don't include generated wrapper files in sources (#4851)
The generated files under the `wrapped` directory wrap and duplicate the original files. Although they're sources to the compiler, they're not sources for the user and/or editor. Also, when compiling the wrapped files, we already translate compiler error messages back to the original files, hence the user/editor should not need to deal with these intermediate files. Before this change, the IDE sometimes shows the generated `build.mill` instead of the original `build.mill` when jumping to definitions or using other code navigation options. If the user edited these files, changes were lost later. This PR removes the wrapped files from `generatedSources`, so they no longer appear in the IDE. Those files are still fed via `allScalaSourceFiles` to the compiler. Tested manually with Metals 1.5.2+97-5a09352f-SNAPSHOT/vscode and IntelliJ 2025.1. Pull request: #4851
1 parent 7578c20 commit 7b62c39

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

integration/ide/bsp-server/resources/snapshots/build-targets-sources.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@
7575
"kind": 2,
7676
"generated": false
7777
},
78-
{
79-
"uri": "file:///workspace/out/mill-build/generatedScriptSources.dest/wrapped",
80-
"kind": 2,
81-
"generated": true
82-
},
8378
{
8479
"uri": "file:///workspace/out/mill-build/generatedScriptSources.dest/support",
8580
"kind": 2,

integration/ide/gen-idea/resources/extended/idea/mill_modules/mill-build.iml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<exclude-output/>
55
<content url="file://$MODULE_DIR$/../..">
66
<sourceFolder url="file://$MODULE_DIR$/../../out/mill-build/generatedScriptSources.dest/support" isTestSource="false" generated="true"/>
7-
<sourceFolder url="file://$MODULE_DIR$/../../out/mill-build/generatedScriptSources.dest/wrapped" isTestSource="false" generated="true"/>
87
<sourceFolder url="file://$MODULE_DIR$/../../build.mill" isTestSource="false"/>
98
<sourceFolder url="file://$MODULE_DIR$/../../mill-build/src" isTestSource="false"/>
109
<sourceFolder url="file://$MODULE_DIR$/../../mill-build/resources" type="java-resource"/>
@@ -118,4 +117,4 @@
118117
<orderEntry type="library" scope="RUNTIME" name="xz-1.9.jar" level="project"/>
119118
<orderEntry type="library" name="zstd-jni-1.5.7-2.jar" level="project"/>
120119
</component>
121-
</module>
120+
</module>

integration/ide/gen-idea/resources/extended/idea/mill_modules/mill-build.mill-build.iml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
<content url="file://$MODULE_DIR$/../../out/mill-build/mill-build/generatedScriptSources.dest/support">
66
<sourceFolder url="file://$MODULE_DIR$/../../out/mill-build/mill-build/generatedScriptSources.dest/support" isTestSource="false" generated="true"/>
77
</content>
8-
<content url="file://$MODULE_DIR$/../../out/mill-build/mill-build/generatedScriptSources.dest/wrapped">
9-
<sourceFolder url="file://$MODULE_DIR$/../../out/mill-build/mill-build/generatedScriptSources.dest/wrapped" isTestSource="false" generated="true"/>
10-
</content>
118
<content url="file://$MODULE_DIR$/../../mill-build">
129
<sourceFolder url="file://$MODULE_DIR$/../../mill-build/build.mill" isTestSource="false"/>
1310
<sourceFolder url="file://$MODULE_DIR$/../../mill-build/mill-build/src" isTestSource="false"/>

integration/ide/gen-idea/resources/hello-idea/idea/mill_modules/mill-build.iml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<exclude-output/>
55
<content url="file://$MODULE_DIR$/../..">
66
<sourceFolder url="file://$MODULE_DIR$/../../out/mill-build/generatedScriptSources.dest/support" isTestSource="false" generated="true"/>
7-
<sourceFolder url="file://$MODULE_DIR$/../../out/mill-build/generatedScriptSources.dest/wrapped" isTestSource="false" generated="true"/>
87
<sourceFolder url="file://$MODULE_DIR$/../../build.mill" isTestSource="false"/>
98
<sourceFolder url="file://$MODULE_DIR$/../../mill-build/src" isTestSource="false"/>
109
<sourceFolder url="file://$MODULE_DIR$/../../mill-build/resources" type="java-resource"/>

runner/meta/src/mill/meta/MillBuildRootModule.scala

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,15 @@ trait MillBuildRootModule()(implicit
9696
override def platformSuffix: T[String] = s"_mill${BuildInfo.millBinPlatform}"
9797

9898
override def generatedSources: T[Seq[PathRef]] = Task {
99-
generatedScriptSources()._1 ++ generatedScriptSources()._2
99+
generatedScriptSources()._2
100100
}
101101

102+
/**
103+
* Additional script files, we generate, since not all Mill source
104+
* files (e.g. `.sc` and `.mill`) can be fed to the compiler as-is.
105+
* The wrapped files aren't supposed to appear under [[generatedSources]] and [[allSources]],
106+
* since they are derived from [[sources]] and would confuse any further tooling like IDEs.
107+
*/
102108
def generatedScriptSources: T[MillBuildRootModule.GeneratedScriptSourcesResult] = Task {
103109
val wrapped = Task.dest / "wrapped"
104110
val support = Task.dest / "support"
@@ -211,15 +217,28 @@ trait MillBuildRootModule()(implicit
211217
codesig.transitiveCallGraphHashes
212218
}
213219

220+
/**
221+
* All mill build source files.
222+
* These files are the inputs but not necessarily the same files we feed to the compiler,
223+
* since we need to process `.mill` files and generate additional Scala files from it.
224+
*/
214225
override def sources: T[Seq[PathRef]] = Task {
215226
scriptSources() ++ super.sources()
216227
}
217228

218229
override def allSourceFiles: T[Seq[PathRef]] = Task {
230+
val allMillSources =
231+
// the real input-sources
232+
allSources() ++
233+
// also sources, but derived from `scriptSources`
234+
generatedScriptSources()._1
235+
219236
val candidates =
220-
Lib.findSourceFiles(allSources(), Seq("scala", "java") ++ buildFileExtensions.asScala)
237+
Lib.findSourceFiles(allMillSources, Seq("scala", "java") ++ buildFileExtensions.asScala.toSeq)
238+
221239
// We need to unlist those files, which we replaced by generating wrapper scripts
222240
val filesToExclude = Lib.findSourceFiles(scriptSources(), buildFileExtensions.asScala.toSeq)
241+
223242
candidates.filterNot(filesToExclude.contains).map(PathRef(_))
224243
}
225244

0 commit comments

Comments
 (0)