Merge pull request #5719 from eatkins/jline3-completions

Set complete flag in completions
This commit is contained in:
eugene yokota 2020-08-04 22:18:51 -04:00 committed by GitHub
commit 48f086059f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -57,11 +57,14 @@ object LineReader {
* `testOnly testOnly\ com.foo.FooSpec` instead of `testOnly com.foo.FooSpec`.
*/
if (c.append.nonEmpty) {
if (!pl.line().endsWith(" ")) {
candidates.add(new Candidate(pl.line().split(" ").last + c.append))
} else {
candidates.add(new Candidate(c.append))
}
val comp =
if (!pl.line().endsWith(" ")) pl.line().split(" ").last + c.append else c.append
// tell jline to append a " " if the completion would be valid with a " " appended
// which can be the case for input tasks and some commands. We need to exclude
// the empty string and ";" which always seem to be present.
val complete = (Parser.completions(parser, comp + " ", 10).get.map(_.display) --
Set(";", "")).nonEmpty
candidates.add(new Candidate(comp, comp, null, null, null, null, complete))
}
}
}

View File

@ -7,7 +7,7 @@
package sbt.internal.util
import java.io.{ InputStream, InterruptedIOException, OutputStream, PrintStream }
import java.io.{ InputStream, InterruptedIOException, IOException, OutputStream, PrintStream }
import java.nio.channels.ClosedChannelException
import java.util.{ Arrays, Locale }
import java.util.concurrent.atomic.{ AtomicBoolean, AtomicReference }
@ -171,7 +171,8 @@ object Terminal {
if (System.getProperty("sbt.jline.verbose", "false") != "true")
jline.internal.Log.setOutput(new PrintStream(_ => {}, false))
def consoleLog(string: String): Unit = {
Terminal.console.printStream.println(s"[info] $string")
try Terminal.console.printStream.println(s"[info] $string")
catch { case _: IOException => }
}
private[sbt] def set(terminal: Terminal) = {
activeTerminal.set(terminal)