mirror of
https://github.com/ilyakooo0/intellij-haskell.git
synced 2024-09-11 14:56:19 +03:00
Filter out packages which are already seen as depending package and refactor. Fix issue #430
This commit is contained in:
parent
655e10f7b3
commit
37cbc9bc97
@ -93,9 +93,9 @@ private[component] object LibraryPackageInfoComponent {
|
||||
|
||||
private final val PackageNameVersionPattern = """([\w\-]+)-([\d\.]+)(?:\-.*)?""".r
|
||||
|
||||
def toPackageNameversion(depends: String): Option[PackageNameVersion] = {
|
||||
def toPackageNameversion(depends: String): Option[PackageId] = {
|
||||
depends match {
|
||||
case PackageNameVersionPattern(name, version) => Some(PackageNameVersion(name, version))
|
||||
case PackageNameVersionPattern(name, version) => Some(PackageId(name, version))
|
||||
case _ => None
|
||||
}
|
||||
}
|
||||
@ -124,6 +124,6 @@ private[component] object LibraryPackageInfoComponent {
|
||||
}
|
||||
|
||||
|
||||
case class PackageInfo(packageName: String, version: String, id: String, exposedModuleNames: Seq[String], hiddenModuleNames: Seq[String], dependsPackageNames: Seq[PackageNameVersion])
|
||||
case class PackageInfo(packageName: String, version: String, id: String, exposedModuleNames: Seq[String], hiddenModuleNames: Seq[String], dependsOnPackageIds: Seq[PackageId])
|
||||
|
||||
case class PackageNameVersion(name: String, version: String)
|
||||
case class PackageId(name: String, version: String)
|
@ -42,6 +42,7 @@ import intellij.haskell.util.{HaskellFileUtil, HaskellProjectUtil, ScalaUtil}
|
||||
import intellij.haskell.{GlobalInfo, HaskellNotificationGroup}
|
||||
import javax.swing.Icon
|
||||
|
||||
import scala.annotation.tailrec
|
||||
import scala.collection.JavaConverters._
|
||||
import scala.collection.mutable.ListBuffer
|
||||
import scala.concurrent.duration._
|
||||
@ -236,30 +237,32 @@ object HaskellModuleBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
private def getDependsPackageInfos(allPackageInfos: Seq[PackageInfo], modulePackageInfos: Seq[PackageInfo]): Seq[PackageInfo] = {
|
||||
val packageInfoByName = allPackageInfos.map(pi => (pi.packageName, pi)).toMap
|
||||
private def getDependsOnPackageInfos(libraryPackageInfos: Seq[PackageInfo], modulePackageInfos: Seq[PackageInfo]): Seq[PackageInfo] = {
|
||||
val libraryPackageInfoByName = libraryPackageInfos.map(pi => (pi.packageName, pi)).toMap
|
||||
|
||||
def go(packageInfos: Seq[PackageInfo], dependsPackageInfos: ListBuffer[PackageInfo]): Seq[PackageInfo] = {
|
||||
val depends = packageInfos.flatMap { pi =>
|
||||
dependsPackageInfos += pi
|
||||
pi.dependsPackageNames.map(_.name).flatMap(packageInfoByName.get)
|
||||
@tailrec
|
||||
def go(packageInfos: Seq[PackageInfo], dependsOnPackageInfos: ListBuffer[PackageInfo]): Seq[PackageInfo] = {
|
||||
val dependsOn = packageInfos.flatMap { pi =>
|
||||
dependsOnPackageInfos += pi
|
||||
pi.dependsOnPackageIds.map(_.name).flatMap(libraryPackageInfoByName.get).filterNot(dependsOnPackageInfos.contains)
|
||||
}
|
||||
if (depends.isEmpty) {
|
||||
dependsPackageInfos
|
||||
|
||||
if (dependsOn.isEmpty) {
|
||||
dependsOnPackageInfos
|
||||
} else {
|
||||
go(depends.distinct, dependsPackageInfos)
|
||||
go(dependsOn.distinct, dependsOnPackageInfos)
|
||||
}
|
||||
}
|
||||
|
||||
val dependsPackageNames = ListBuffer[PackageInfo]()
|
||||
val dependsOnPackageInfos = ListBuffer[PackageInfo]()
|
||||
|
||||
go(modulePackageInfos, dependsPackageNames).filterNot(_.packageName == "rts")
|
||||
go(modulePackageInfos, dependsOnPackageInfos).filterNot(_.packageName == "rts")
|
||||
}
|
||||
|
||||
private def getModuleLibraryDependencies(moduleDependencies: Seq[HaskellDependency], libraryPackageInfos: Seq[PackageInfo]): Seq[HaskellLibraryDependency] = {
|
||||
val modulePackageInfos = moduleDependencies.filter(_.isInstanceOf[HaskellLibraryDependency]).flatMap(d => libraryPackageInfos.find(_.packageName == d.name))
|
||||
val dependsPackageInfos = getDependsPackageInfos(libraryPackageInfos, modulePackageInfos)
|
||||
dependsPackageInfos.map(pi => HaskellLibraryDependency(pi.packageName, pi.version))
|
||||
val moduleLibraryPackageInfos = moduleDependencies.filter(_.isInstanceOf[HaskellLibraryDependency]).flatMap(d => libraryPackageInfos.find(_.packageName == d.name))
|
||||
val dependsOnPackageInfos = getDependsOnPackageInfos(libraryPackageInfos, moduleLibraryPackageInfos)
|
||||
dependsOnPackageInfos.map(pi => HaskellLibraryDependency(pi.packageName, pi.version))
|
||||
}
|
||||
|
||||
def addLibrarySources(project: Project, update: Boolean): Unit = {
|
||||
|
Loading…
Reference in New Issue
Block a user