[BSP] remove duplicated sources in sbt build target

Also remove the base directory (`./project/`) from the list of source directories
This commit is contained in:
Adrien Piquerez 2021-10-29 15:09:51 +02:00
parent e64c71dd58
commit 75d3bf2b5f
2 changed files with 15 additions and 21 deletions

View File

@ -116,21 +116,18 @@ object BuildServerProtocol {
val base = loadedBuildUnit.localBase val base = loadedBuildUnit.localBase
val sbtFiles = configurationSources(base) val sbtFiles = configurationSources(base)
val pluginData = loadedBuildUnit.unit.plugins.pluginData val pluginData = loadedBuildUnit.unit.plugins.pluginData
val all = Vector.newBuilder[SourceItem] val dirs = pluginData.unmanagedSourceDirectories
def add(fs: Seq[File], sourceItemKind: Int, generated: Boolean): Unit = { val sourceFiles = getStandaloneSourceFiles(pluginData.unmanagedSources, dirs)
fs.foreach(f => all += (SourceItem(f.toURI, sourceItemKind, generated = generated))) val managedDirs = pluginData.managedSourceDirectories
} val managedSourceFiles =
all += (SourceItem( getStandaloneSourceFiles(pluginData.managedSources, managedDirs)
loadedBuildUnit.unit.plugins.base.toURI, val items =
SourceItemKind.Directory, dirs.map(toSourceItem(SourceItemKind.Directory, generated = false)) ++
generated = false sourceFiles.map(toSourceItem(SourceItemKind.File, generated = false)) ++
)) managedDirs.map(toSourceItem(SourceItemKind.Directory, generated = true)) ++
add(pluginData.unmanagedSourceDirectories, SourceItemKind.Directory, generated = false) managedSourceFiles.map(toSourceItem(SourceItemKind.File, generated = true)) ++
add(pluginData.unmanagedSources, SourceItemKind.File, generated = false) sbtFiles.map(toSourceItem(SourceItemKind.File, generated = false))
add(pluginData.managedSourceDirectories, SourceItemKind.Directory, generated = true) Value(SourcesItem(id, items.toVector))
add(pluginData.managedSources, SourceItemKind.File, generated = true)
add(sbtFiles, SourceItemKind.File, generated = false)
Value(SourcesItem(id, all.result()))
} }
val successfulItems = anyOrThrow(items ++ buildItems) val successfulItems = anyOrThrow(items ++ buildItems)
val result = SourcesResult(successfulItems.toVector) val result = SourcesResult(successfulItems.toVector)
@ -280,10 +277,6 @@ object BuildServerProtocol {
val sourceFiles = getStandaloneSourceFiles(unmanagedSources.value, dirs) val sourceFiles = getStandaloneSourceFiles(unmanagedSources.value, dirs)
val managedDirs = managedSourceDirectories.value val managedDirs = managedSourceDirectories.value
val managedSourceFiles = getStandaloneSourceFiles(managedSources.value, managedDirs) val managedSourceFiles = getStandaloneSourceFiles(managedSources.value, managedDirs)
def toSourceItem(itemKind: Int, generated: Boolean)(file: File): SourceItem =
SourceItem(file.toURI, itemKind, generated)
val items = dirs.map(toSourceItem(SourceItemKind.Directory, generated = false)) ++ val items = dirs.map(toSourceItem(SourceItemKind.Directory, generated = false)) ++
sourceFiles.map(toSourceItem(SourceItemKind.File, generated = false)) ++ sourceFiles.map(toSourceItem(SourceItemKind.File, generated = false)) ++
managedDirs.map(toSourceItem(SourceItemKind.Directory, generated = true)) ++ managedDirs.map(toSourceItem(SourceItemKind.Directory, generated = true)) ++
@ -469,6 +462,9 @@ object BuildServerProtocol {
} }
} }
private def toSourceItem(itemKind: Int, generated: Boolean)(file: File): SourceItem =
SourceItem(file.toURI, itemKind, generated)
private def checkMetalsCompatibility( private def checkMetalsCompatibility(
semanticdbEnabled: Boolean, semanticdbEnabled: Boolean,
semanticdbVersion: String, semanticdbVersion: String,

View File

@ -79,14 +79,12 @@ object BuildServerTest extends AbstractServerTest {
val sources = s.items.head.sources.map(_.uri).sorted val sources = s.items.head.sources.map(_.uri).sorted
val expectedSources = Vector( val expectedSources = Vector(
"build.sbt", "build.sbt",
"project/",
"project/A.scala", "project/A.scala",
"project/src/main/java", "project/src/main/java",
"project/src/main/scala-2", "project/src/main/scala-2",
"project/src/main/scala-2.12", "project/src/main/scala-2.12",
"project/src/main/scala-sbt-1.0", "project/src/main/scala-sbt-1.0",
"project/src/main/scala/", "project/src/main/scala/",
"project/src/main/scala/B.scala",
"project/target/scala-2.12/sbt-1.0/src_managed/main" "project/target/scala-2.12/sbt-1.0/src_managed/main"
).map(rel => new File(svr.baseDirectory.getAbsoluteFile, rel).toURI).sorted ).map(rel => new File(svr.baseDirectory.getAbsoluteFile, rel).toURI).sorted
assert(sources == expectedSources) assert(sources == expectedSources)