sbt/server-test/src/test/scala/testpkg/ServerCompletionsTest.scala

47 lines
1.4 KiB
Scala
Raw Normal View History

/*
* sbt
* Copyright 2011 - 2018, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* Licensed under Apache License 2.0 (see LICENSE)
*/
package testpkg
import scala.concurrent.duration._
// starts svr using server-test/completions and perform sbt/completion tests
object ServerCompletionsTest extends AbstractServerTest {
override val testDirectory: String = "completions"
test("return basic completions on request") { _ =>
val completionStr = """{ "query": "" }"""
svr.sendJsonRpc(
s"""{ "jsonrpc": "2.0", "id": 15, "method": "sbt/completion", "params": $completionStr }"""
)
assert(svr.waitForString(10.seconds) { s =>
2020-09-17 14:23:28 +02:00
println(s)
s contains """"result":{"items":["""
})
}
test("return completion for custom tasks") { _ =>
val completionStr = """{ "query": "hell" }"""
svr.sendJsonRpc(
s"""{ "jsonrpc": "2.0", "id": 16, "method": "sbt/completion", "params": $completionStr }"""
)
assert(svr.waitForString(10.seconds) { s =>
Add tab completion support to thin client The sbtc client can provide a ux very similar to using the sbt shell when combined with tab completions. In fact, since some shells have a better tab completion engine than that provided by jilne2, the experience can be even better. To make this work, we add another entry point to the thin client that is capable of generating completions for an input string. It queries sbt for the completions and prints the result to stdout, where they are consumed by the shell and fed into its completion engine. In addition to providing tab completions, if there is no server running or if the user is completing `runMain`, `testOnly` or `testQuick`, the thin client will prompt the user to ask if they would like to start an sbt server or if they would like to compile to generate the main class or test names. Neither powershell nor zsh support forwarding input to the tab completion script. Zsh will print output to stderr so we opportunistically start the server or complete the test class names. Powershell does not print completion output at all, so we do not start a server or fill completions in that case*. For fish and bash, we prompt the user that they can take these actions so that they can avoid the expensive operation if desired. * Powershell users can set the environment variable SBTC_AUTO_COMPLETE if they want to automatically start a server of compile for run and test names. No output will be displayed so there can be a long latency between pressing <tab> and seeing completion results if this variable is set.
2020-06-25 03:31:18 +02:00
s contains """"result":{"items":["hello"]"""
})
}
test("return completions for user classes") { _ =>
val completionStr = """{ "query": "testOnly org." }"""
svr.sendJsonRpc(
s"""{ "jsonrpc": "2.0", "id": 17, "method": "sbt/completion", "params": $completionStr }"""
)
assert(svr.waitForString(10.seconds) { s =>
Add tab completion support to thin client The sbtc client can provide a ux very similar to using the sbt shell when combined with tab completions. In fact, since some shells have a better tab completion engine than that provided by jilne2, the experience can be even better. To make this work, we add another entry point to the thin client that is capable of generating completions for an input string. It queries sbt for the completions and prints the result to stdout, where they are consumed by the shell and fed into its completion engine. In addition to providing tab completions, if there is no server running or if the user is completing `runMain`, `testOnly` or `testQuick`, the thin client will prompt the user to ask if they would like to start an sbt server or if they would like to compile to generate the main class or test names. Neither powershell nor zsh support forwarding input to the tab completion script. Zsh will print output to stderr so we opportunistically start the server or complete the test class names. Powershell does not print completion output at all, so we do not start a server or fill completions in that case*. For fish and bash, we prompt the user that they can take these actions so that they can avoid the expensive operation if desired. * Powershell users can set the environment variable SBTC_AUTO_COMPLETE if they want to automatically start a server of compile for run and test names. No output will be displayed so there can be a long latency between pressing <tab> and seeing completion results if this variable is set.
2020-06-25 03:31:18 +02:00
s contains """"result":{"items":["testOnly org.sbt.ExampleSpec"]"""
})
}
}