Lazily concatenate failed errors for completion

* 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:
Björn Antonsson 2016-10-13 16:20:18 +02:00
parent 4b6c0196e6
commit 127c164f81
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)
}