Skip to content

Commit 18aec45

Browse files
felladrinAndrea Falzettiakosyakov
authored andcommitted
Add actions Copy URL and Copy Web URL on forwarded ports in terminals from JetBrains EAP IDEs
Co-authored-by: Andrea Falzetti <[email protected]> Co-authored-by: Anton Kosyakov <[email protected]>
1 parent cc3f4a1 commit 18aec45

File tree

4 files changed

+92
-30
lines changed

4 files changed

+92
-30
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package io.gitpod.jetbrains.remote.latest
6+
7+
import com.intellij.openapi.actionSystem.ActionPlaces
8+
import com.intellij.openapi.actionSystem.ActionUpdateThread
9+
import com.intellij.openapi.actionSystem.AnAction
10+
import com.intellij.openapi.actionSystem.AnActionEvent
11+
import com.intellij.openapi.components.service
12+
import com.intellij.openapi.ide.CopyPasteManager
13+
import com.jetbrains.rd.platform.codeWithMe.portForwarding.PortForwardingDataKeys
14+
import io.gitpod.jetbrains.remote.GitpodPortsService
15+
import java.awt.datatransfer.StringSelection
16+
17+
@Suppress("ComponentNotRegistered", "UnstableApiUsage")
18+
class GitpodCopyUrlAction : AnAction() {
19+
override fun actionPerformed(e: AnActionEvent) {
20+
e.dataContext.getData(PortForwardingDataKeys.SUGGESTION)?.getSuggestedHostPort()?.let { hostPort ->
21+
service<GitpodPortsService>().getLocalHostUriFromHostPort(hostPort).let { localHostUri ->
22+
CopyPasteManager.getInstance().setContents(StringSelection(localHostUri.toString()))
23+
}
24+
}
25+
}
26+
27+
override fun update(e: AnActionEvent) {
28+
e.presentation.isEnabled = (e.place != ActionPlaces.ACTION_SEARCH)
29+
}
30+
31+
override fun getActionUpdateThread() = ActionUpdateThread.BGT
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package io.gitpod.jetbrains.remote.latest
6+
7+
import com.intellij.openapi.actionSystem.ActionPlaces
8+
import com.intellij.openapi.actionSystem.ActionUpdateThread
9+
import com.intellij.openapi.actionSystem.AnAction
10+
import com.intellij.openapi.actionSystem.AnActionEvent
11+
import com.intellij.openapi.ide.CopyPasteManager
12+
import com.intellij.util.application
13+
import com.jetbrains.rd.platform.codeWithMe.portForwarding.PortForwardingDataKeys
14+
import io.gitpod.jetbrains.remote.GitpodManager
15+
import io.gitpod.supervisor.api.Status.PortsStatusRequest
16+
import io.gitpod.supervisor.api.StatusServiceGrpc
17+
import kotlinx.coroutines.launch
18+
import java.awt.datatransfer.StringSelection
19+
20+
@Suppress("ComponentNotRegistered", "UnstableApiUsage")
21+
class GitpodCopyWebUrlAction : AnAction() {
22+
override fun actionPerformed(e: AnActionEvent) {
23+
e.dataContext.getData(PortForwardingDataKeys.SUGGESTION)?.getSuggestedHostPort()?.let { hostPort ->
24+
application.coroutineScope.launch {
25+
getUrlFromPort(hostPort)?.let {
26+
CopyPasteManager.getInstance().setContents(StringSelection(it))
27+
}
28+
}
29+
}
30+
}
31+
32+
override fun update(e: AnActionEvent) {
33+
e.presentation.isEnabled = (e.place != ActionPlaces.ACTION_SEARCH)
34+
}
35+
36+
override fun getActionUpdateThread() = ActionUpdateThread.BGT
37+
38+
private fun getUrlFromPort(port: Number): String? {
39+
val blockingStub = StatusServiceGrpc.newBlockingStub(GitpodManager.supervisorChannel)
40+
val request = PortsStatusRequest.newBuilder().setObserve(false).build()
41+
val response = blockingStub.portsStatus(request)
42+
while (response.hasNext()) {
43+
val portStatusResponse = response.next()
44+
for (portStatus in portStatusResponse.portsList) {
45+
if (portStatus.localPort == port) return portStatus.exposed.url
46+
}
47+
}
48+
return null
49+
}
50+
}

components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/latest/GitpodPortsActionCopyUrl.kt

Lines changed: 0 additions & 25 deletions
This file was deleted.

components/ide/jetbrains/backend-plugin/src/main/resources-latest/META-INF/extensions.xml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@
1313
<projectService serviceImplementation="io.gitpod.jetbrains.remote.GitpodTerminalService" client="controller" preload="true"/>
1414
<projectService serviceImplementation="io.gitpod.jetbrains.remote.latest.GitpodPortForwardingService" client="controller" preload="true"/>
1515
</extensions>
16-
<!--
1716
<actions>
18-
<action id="io.gitpod.jetbrains.remote.latest.GitpodPortsActionCopyUrl"
19-
class="io.gitpod.jetbrains.remote.latest.GitpodPortsActionCopyUrl"
20-
text="Gitpod: Copy Port URL"
17+
<action id="io.gitpod.jetbrains.remote.latest.GitpodCopyUrlAction"
18+
class="io.gitpod.jetbrains.remote.latest.GitpodCopyUrlAction"
19+
text="Copy URL"
2120
icon="AllIcons.Actions.Copy">
2221
<add-to-group group-id="PortForwardingPortGroup" anchor="last"/>
2322
</action>
23+
<action id="io.gitpod.jetbrains.remote.latest.GitpodCopyWebUrlAction"
24+
class="io.gitpod.jetbrains.remote.latest.GitpodCopyWebUrlAction"
25+
text="Copy Web URL"
26+
icon="AllIcons.Actions.Copy">
27+
<add-to-group group-id="PortForwardingPortGroup" anchor="last"/>
28+
<add-to-group group-id="PortForwardingSuggestionGroup" anchor="last"/>
29+
</action>
2430
</actions>
25-
-->
2631
</idea-plugin>

0 commit comments

Comments
 (0)