@@ -61,6 +61,7 @@ import org.eclipse.lsp4j.jsonrpc.RemoteEndpoint
6161import org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethod
6262import org.eclipse.lsp4j.jsonrpc.messages.ResponseMessage
6363import org.eclipse.lsp4j.launch.LSPLauncher
64+ import org.jetbrains.annotations.VisibleForTesting
6465import org.slf4j.event.Level
6566import software.aws.toolkits.core.utils.debug
6667import software.aws.toolkits.core.utils.getLogger
@@ -134,11 +135,11 @@ internal class LSPProcessListener : ProcessListener {
134135}
135136
136137@Service(Service .Level .PROJECT )
137- class AmazonQLspService (private val project : Project , private val cs : CoroutineScope ) : Disposable {
138+ open class AmazonQLspService (private val project : Project , private val cs : CoroutineScope ) : Disposable {
138139 private val _flowInstance = MutableSharedFlow <AmazonQServerInstance >(replay = 1 , onBufferOverflow = BufferOverflow .DROP_OLDEST )
139140 val instanceFlow = _flowInstance .asSharedFlow().map { it.languageServer }
140141
141- private var instance: Deferred <AmazonQServerInstance >
142+ private var instance: Deferred <AmazonQServerInstanceFacade >
142143 val capabilities
143144 get() = instance.getCompleted().initializeResult.getCompleted().capabilities
144145
@@ -154,7 +155,8 @@ class AmazonQLspService(private val project: Project, private val cs: CoroutineS
154155 // dont allow lsp commands if server is restarting
155156 private val mutex = Mutex (false )
156157
157- private fun start () = cs.async {
158+ @VisibleForTesting
159+ protected open fun start (): Deferred <AmazonQServerInstanceFacade > = cs.async {
158160 // manage lifecycle RAII-like so we can restart at arbitrary time
159161 // and suppress IDE error if server fails to start
160162 var attempts = 0
@@ -331,21 +333,27 @@ class AmazonQLspService(private val project: Project, private val cs: CoroutineS
331333 }
332334}
333335
334- private class AmazonQServerInstance (private val project : Project , private val cs : CoroutineScope ) : Disposable {
335- val encryptionManager = JwtEncryptionManager ()
336-
337- private val launcher: Launcher <AmazonQLanguageServer >
336+ interface AmazonQServerInstanceFacade : Disposable {
337+ val launcher: Launcher <AmazonQLanguageServer >
338+ val launcherFuture: Future <Void >
339+ val initializeResult: Deferred <AwsExtendedInitializeResult >
340+ val encryptionManager: JwtEncryptionManager
338341
339342 val languageServer: AmazonQLanguageServer
340343 get() = launcher.remoteProxy
341344
342345 val rawEndpoint: RemoteEndpoint
343346 get() = launcher.remoteEndpoint
347+ }
348+
349+ private class AmazonQServerInstance (private val project : Project , private val cs : CoroutineScope ) : Disposable, AmazonQServerInstanceFacade {
350+ override val encryptionManager = JwtEncryptionManager ()
351+ override val launcher: Launcher <AmazonQLanguageServer >
344352
345353 @Suppress(" ForbiddenVoid" )
346- val launcherFuture: Future <Void >
354+ override val launcherFuture: Future <Void >
347355 private val launcherHandler: KillableProcessHandler
348- val initializeResult: Deferred <InitializeResult >
356+ override val initializeResult: Deferred <AwsExtendedInitializeResult >
349357
350358 private fun createClientCapabilities (): ClientCapabilities =
351359 ClientCapabilities ().apply {
@@ -546,7 +554,7 @@ private class AmazonQServerInstance(private val project: Project, private val cs
546554 }
547555 languageServer.initialized(InitializedParams ())
548556
549- initializeResult
557+ initializeResult as AwsExtendedInitializeResult
550558 }
551559
552560 // invokeOnCompletion results in weird lock/timeout error
0 commit comments