Skip to content

Commit 9e1dac1

Browse files
felladrinroboquat
authored andcommitted
Fix 'gp open' command to open files in JetBrains Client instead of the backend IDE
1 parent 30fd0a9 commit 9e1dac1

File tree

2 files changed

+18
-25
lines changed

2 files changed

+18
-25
lines changed

Diff for: components/ide/jetbrains/backend-plugin/launch-dev-server.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ export IJ_HOST_SYSTEM_BASE_DIR=/workspace/.cache/JetBrains
8181
export CWM_HOST_STATUS_OVER_HTTP_TOKEN=gitpod
8282

8383
# Build and move idea-cli, then overwrite environment variables initially defined by `components/ide/jetbrains/image/leeway.Dockerfile`
84-
IDEA_CLI_DEV_PATH=$TEST_BACKEND_DIR/bin/idea-cli-dev
84+
# Note: IDEA_CLI_DEV_PATH path needs to be the same string used in components/ide/jetbrains/cli/cmd/root.go
85+
IDEA_CLI_DEV_PATH=/ide-desktop/bin/idea-cli-dev
8586
(cd ../cli && go build -o $IDEA_CLI_DEV_PATH)
8687
export EDITOR="$IDEA_CLI_DEV_PATH open"
8788
export VISUAL="$EDITOR"

Diff for: components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/GitpodCLIService.kt

+16-24
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package io.gitpod.jetbrains.remote
66

77
import com.intellij.codeWithMe.ClientId
88
import com.intellij.ide.BrowserUtil
9-
import com.intellij.openapi.application.ApplicationManager
109
import com.intellij.openapi.client.ClientSession
1110
import com.intellij.openapi.client.ClientSessionsManager
1211
import com.intellij.openapi.components.service
@@ -24,10 +23,7 @@ import io.netty.channel.ChannelHandlerContext
2423
import io.netty.handler.codec.http.FullHttpRequest
2524
import io.netty.handler.codec.http.QueryStringDecoder
2625
import io.prometheus.client.exporter.common.TextFormat
27-
import kotlinx.coroutines.Dispatchers
28-
import kotlinx.coroutines.GlobalScope
29-
import kotlinx.coroutines.launch
30-
import kotlinx.coroutines.withContext
26+
import kotlinx.coroutines.*
3127
import org.jetbrains.ide.RestService
3228
import org.jetbrains.io.response
3329
import java.io.OutputStreamWriter
@@ -69,11 +65,7 @@ class GitpodCLIService : RestService() {
6965
val file = parseFilePath(fileStr) ?: return "invalid file"
7066
val shouldWait = getBooleanParameter("wait", urlDecoder)
7167
return withClient(request, context) {
72-
GlobalScope.launch {
73-
withContext(Dispatchers.IO) {
74-
cliHelperService.open(file, shouldWait)
75-
}
76-
}
68+
cliHelperService.open(file, shouldWait)
7769
}
7870
}
7971
if (operation == "preview") {
@@ -105,8 +97,8 @@ class GitpodCLIService : RestService() {
10597
}
10698
}
10799

108-
private fun withClient(request: FullHttpRequest, context: ChannelHandlerContext, action: (project: Project?) -> Unit): String? {
109-
ApplicationManager.getApplication().executeOnPooledThread {
100+
private fun withClient(request: FullHttpRequest, context: ChannelHandlerContext, action: suspend (project: Project?) -> Unit): String? {
101+
GlobalScope.launch {
110102
getClientSessionAndProjectAsync().let { (session, project) ->
111103
ClientId.withClientId(session.clientId) {
112104
action(project)
@@ -119,21 +111,21 @@ class GitpodCLIService : RestService() {
119111

120112
private data class ClientSessionAndProject(val session: ClientSession, val project: Project?)
121113

122-
private tailrec fun getClientSessionAndProjectAsync(): ClientSessionAndProject {
114+
private suspend fun getClientSessionAndProjectAsync(): ClientSessionAndProject {
123115
val project = getLastFocusedOrOpenedProject()
124116
var session: ClientSession? = null
125-
if (project != null) {
126-
session = ClientSessionsManager.getProjectSessions(project, false).firstOrNull()
127-
}
128-
if (session == null) {
129-
session = ClientSessionsManager.getAppSessions(false).firstOrNull()
130-
}
131-
return if (session != null) {
132-
ClientSessionAndProject (session, project)
133-
} else {
134-
Thread.sleep(1000L)
135-
getClientSessionAndProjectAsync()
117+
while (session == null) {
118+
if (project != null) {
119+
session = ClientSessionsManager.getProjectSessions(project, false).firstOrNull()
120+
}
121+
if (session == null) {
122+
session = ClientSessionsManager.getAppSessions(false).firstOrNull()
123+
}
124+
if (session == null) {
125+
delay(1000L)
126+
}
136127
}
128+
return ClientSessionAndProject(session, project)
137129
}
138130

139131
private fun parseFilePath(path: String): Path? {

0 commit comments

Comments
 (0)