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

View File

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