Skip to content

Commit 6e78938

Browse files
committed
init
1 parent 687f881 commit 6e78938

File tree

1 file changed

+29
-2
lines changed
  • plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp

1 file changed

+29
-2
lines changed

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ import com.intellij.openapi.components.Service
1515
import com.intellij.openapi.components.service
1616
import com.intellij.openapi.project.Project
1717
import com.intellij.openapi.util.Key
18+
import com.intellij.util.io.await
19+
import kotlinx.coroutines.CoroutineScope
20+
import kotlinx.coroutines.launch
21+
import org.eclipse.lsp4j.ClientCapabilities
22+
import org.eclipse.lsp4j.InitializeParams
23+
import org.eclipse.lsp4j.InitializedParams
1824
import org.eclipse.lsp4j.jsonrpc.Launcher
1925
import org.eclipse.lsp4j.launch.LSPLauncher
2026
import software.aws.toolkits.core.utils.getLogger
@@ -62,7 +68,7 @@ internal class LSPProcessListener : ProcessListener {
6268
}
6369

6470
@Service(Service.Level.PROJECT)
65-
class AmazonQLspService(project: Project) : Disposable {
71+
class AmazonQLspService(project: Project, private val cs: CoroutineScope) : Disposable {
6672
private val launcher: Launcher<AmazonQLanguageServer>
6773

6874
private val languageServer: AmazonQLanguageServer
@@ -74,7 +80,6 @@ class AmazonQLspService(project: Project) : Disposable {
7480
val handler = KillableColoredProcessHandler.Silent(cmd)
7581
val inputWrapper = LSPProcessListener()
7682
handler.addProcessListener(inputWrapper)
77-
7883
handler.startNotify()
7984

8085
launcher = LSPLauncher.Builder<AmazonQLanguageServer>()
@@ -103,6 +108,28 @@ class AmazonQLspService(project: Project) : Disposable {
103108
.create()
104109

105110
launcher.startListening()
111+
112+
cs.launch {
113+
val initializeResult = languageServer.initialize(
114+
InitializeParams().apply {
115+
// does this work on windows
116+
processId = ProcessHandle.current().pid().toInt()
117+
// capabilities
118+
// client info
119+
// trace?
120+
// workspace folders?
121+
// anything else we need?
122+
}
123+
// probably need a timeout
124+
).await()
125+
126+
// then if this succeeds then we can allow the client to send requests
127+
languageServer.initialized(InitializedParams())
128+
if (initializeResult == null) {
129+
LOG.warn("LSP initialization failed")
130+
handler.destroyProcess()
131+
}
132+
}
106133
}
107134

108135
override fun dispose() {

0 commit comments

Comments
 (0)