Lazily concatenate failed errors for completion [forwardport] (#53)

* Fixes [sbt/sbt#2781]
* When using `<TAB>` completion the failed errors were always
  computed for mathcing projects even if there was no failure,
  leading to excessive computation of Levenshtein distances
  and a large lag (seconds) on builds with many matching
  projects.
This commit is contained in:
Dale Wijnand 2016-10-31 09:23:38 +00:00 committed by GitHub
parent d63a1f2492
commit ea56f331a1
1 changed files with 2 additions and 2 deletions

View File

@ -559,8 +559,8 @@ trait ParserMain {
def seq[T](p: Seq[Parser[T]]): Parser[Seq[T]] = seq0(p, Nil)
def seq0[T](p: Seq[Parser[T]], errors: => Seq[String]): Parser[Seq[T]] =
{
val (newErrors, valid) = separate(p) { case Invalid(f) => Left(f.errors); case ok => Right(ok) }
def combinedErrors = errors ++ newErrors.flatten
val (newErrors, valid) = separate(p) { case Invalid(f) => Left(f.errors _); case ok => Right(ok) }
def combinedErrors = errors ++ newErrors.flatMap(_())
if (valid.isEmpty) invalid(combinedErrors) else new ParserSeq(valid, combinedErrors)
}