-
-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a
sourceGenerators
task to help out IDE config generation (#4621)
Context : #4530 * Adds a `DeferredGeneratedSourcesModule` that extends `JavaModule`, providing a `def deferredGeneratedSourceTasks` alternative to `generatedSources`. This allows BSP/GenIdea/Bloop to predict source roots without actually running the code generation logic. * Adds a `def out` to the `Ctx` class, allowing to query the location `out` folder within tasks. * Adds unit tests / integration tests where relevant #### Previous description (kept for the record) : @lihaoyi, I want to open this PR to continue the discussion. At the time of writing this, this adds a `generatedSourceRoots` parameter for tasks, as you've described, and uses it to compute the source directories for the bloop configuration, as opposed to actually running the `allSources` task. A similar change would need to be achieved in `GenIdea` and `BSP`. So now, the problem I see is as follows : in order for this to be useful, it needs to be applied to all source generators provided OOTB by the mill codebase, but also third party providers of source-generator (like smithy4s), as the ability to jump to the sources is paramount for the user experience in IDEs. Applying this change is a fair bit of work in this codebase, and a big ask for the larger ecosystem, and although I think SBT's approach of treating all source generators lazily is preferable to mill's current approach of running all source generators eagerly, I don't think I can weigh the benefits of changing the approach against the cost induced by breaking IDE behaviour for existing plugins. With that in mind here's what I think would be a good mitigation : ```scala // Rather than traversing the transitive inputs of `allSources`, we define this setting as a way to register lazy // source generators. We force the contract to return `Unit` to prevent the assumption that a returned `PathRef` would be // added to the sources. def lazySourceGenerators = Seq[T[Unit]] // Runs the lazy source generators, returning path refs computed from their `generatedSourceRoots`. // When the tasks don't have `generatedSourceRoots` set, we assume that the `T.dest` is to be added as source root. final def runLazySourceGenerators : T[Seq[PathRef]] = ??? // Does not run the lazy source generators, but rather computes the source roots they'll generate code in. // Wrapped in T because the evaluator is needed to get the T.dest of the lazy source generators. I presume that is // something we could thread in through the ctx (like `def destOf(task: T[_]) : Path`) final def lazyGeneratedSourceRoots: T[Seq[Path]] = ??? // Keeps the current behaviour intact def allSources = T { sources() ++ generatedSources() ++ runLazySourceGenerators() } ``` The `Bloop`, `GenIdea` and `BSP` then get amended to call `sources()`, `generatedSources()` and `lazyGeneratedSourceRoots()`, but avoids `runLazySourceGenerators`. This approach would allow to alleviate the pain point raised in the discussion above, whilst retaining the current behaviour of the ecosystem. Mill plugin providers could be encouraged to use `runLazySourceGenerators` instead of `generatedSources`, but users would have a recourse to turn eager source generators into lazy ones if they need it to be (provided a `withGeneratedSourceRoots` is provided to them, that is) --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
6f069b0
commit 95f1fe3
Showing
20 changed files
with
407 additions
and
34 deletions.
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.