@@ -1066,24 +1066,47 @@ final class BloopBspServices(
1066
1066
): BspResult [bsp.SourcesResult ] = {
1067
1067
val sourcesItems = projects.iterator.map {
1068
1068
case (target, project) =>
1069
- project.allSourceFilesAndDirectories.map { sources =>
1070
- val items = sources.map { s =>
1071
- import bsp .SourceItemKind ._
1072
- val uri = s.underlying.toUri()
1073
- val (bspUri, kind) = if (s.exists) {
1074
- (uri, if (s.isFile) File else Directory )
1075
- } else {
1076
- val fileMatcher = FileSystems .getDefault.getPathMatcher(" glob:*.{scala, java}" )
1077
- if (fileMatcher.matches(s.underlying.getFileName)) (uri, File )
1078
- // If path doesn't exist and its name doesn't look like a file, assume it's a dir
1079
- else (new URI (uri.toString + " /" ), Directory )
1080
- }
1081
- // TODO(jvican): Don't default on false for generated, add this info to JSON fields
1082
- bsp.SourceItem (bsp.Uri (bspUri), kind, false )
1069
+ def sourceItem (s : AbsolutePath , isGenerated : Boolean ): bsp.SourceItem = {
1070
+ import bsp .SourceItemKind ._
1071
+ val uri = s.underlying.toUri()
1072
+ val (bspUri, kind) = if (s.exists) {
1073
+ (uri, if (s.isFile) File else Directory )
1074
+ } else {
1075
+ val fileMatcher = FileSystems .getDefault.getPathMatcher(" glob:*.{scala, java}" )
1076
+ if (fileMatcher.matches(s.underlying.getFileName)) (uri, File )
1077
+ // If path doesn't exist and its name doesn't look like a file, assume it's a dir
1078
+ else (new URI (uri.toString + " /" ), Directory )
1083
1079
}
1084
- val roots = project.sourceRoots.map(_.map(p => bsp.Uri (p.toBspUri)))
1085
- bsp.SourcesItem (target, items, roots)
1080
+ bsp.SourceItem (bsp.Uri (bspUri), kind, isGenerated)
1086
1081
}
1082
+
1083
+ val unmanagedSources = project.allUnmanagedSourceFilesAndDirectories.map { sources =>
1084
+ sources.map(sourceItem(_, isGenerated = false ))
1085
+ }
1086
+
1087
+ val parentGenerators = Dag .dfs(state.build.getDagFor(project))
1088
+ val managedSources = Task
1089
+ .sequence {
1090
+ parentGenerators.reverse.map { project =>
1091
+ val generators = project.sourceGenerators
1092
+ val tasks = generators.map(
1093
+ state.sourceGeneratorCache.update(_, state.logger, state.commonOptions)
1094
+ )
1095
+ Task .gatherUnordered(tasks)
1096
+ }
1097
+ }
1098
+ .map {
1099
+ // Take only the result of the last set of generators, since these are the generated
1100
+ // sources of the project we're interested in.
1101
+ _.lastOption.map(_.flatten.map(sourceItem(_, isGenerated = true ))).getOrElse(Nil )
1102
+ }
1103
+ .executeOn(ioScheduler)
1104
+
1105
+ val roots = project.sourceRoots.map(_.map(p => bsp.Uri (p.toBspUri)))
1106
+ for {
1107
+ unmanaged <- unmanagedSources
1108
+ managed <- managedSources
1109
+ } yield bsp.SourcesItem (target, unmanaged ++ managed, roots)
1087
1110
}.toList
1088
1111
1089
1112
Task .sequence(sourcesItems).map { items =>
0 commit comments