Skip to content

Commit 1b273db

Browse files
authored
add ReconnectAction and add it in status bar popup (#401)
* add ReconnectAction and add it in status bar popup * Extract string to bundle
1 parent 32c0298 commit 1b273db

File tree

6 files changed

+40
-3
lines changed

6 files changed

+40
-3
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.utbot.cpp.clion.plugin.actions
2+
3+
import com.intellij.openapi.actionSystem.AnAction
4+
import com.intellij.openapi.actionSystem.AnActionEvent
5+
import com.intellij.openapi.components.service
6+
import org.utbot.cpp.clion.plugin.UTBot
7+
import org.utbot.cpp.clion.plugin.client.ClientManager
8+
9+
class ReconnectAction: AnAction(UTBot.message("actions.reconnect")) {
10+
override fun actionPerformed(e: AnActionEvent) {
11+
e.project!!.service<ClientManager>().restartClient()
12+
}
13+
14+
override fun update(e: AnActionEvent) {
15+
e.presentation.isEnabledAndVisible = e.project != null
16+
}
17+
}

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/Client.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ import kotlinx.coroutines.launch
1717
import kotlinx.coroutines.runBlocking
1818
import kotlinx.coroutines.withTimeout
1919
import org.jetbrains.annotations.TestOnly
20+
import org.utbot.cpp.clion.plugin.UTBot
2021
import org.utbot.cpp.clion.plugin.client.channels.LogChannel
2122
import org.utbot.cpp.clion.plugin.client.requests.CheckProjectConfigurationRequest
2223
import org.utbot.cpp.clion.plugin.grpc.getProjectConfigGrpcRequest
2324
import org.utbot.cpp.clion.plugin.listeners.ConnectionStatus
2425
import org.utbot.cpp.clion.plugin.listeners.UTBotEventsListener
2526
import org.utbot.cpp.clion.plugin.settings.projectIndependentSettings
2627
import org.utbot.cpp.clion.plugin.utils.logger
28+
import org.utbot.cpp.clion.plugin.utils.notifyWarning
2729
import testsgen.Testgen
2830

2931
/**
@@ -72,6 +74,7 @@ class Client(
7274
if (isDisposed) {
7375
// if client is disposed, then connection settings were changed, and requests issued to this client
7476
// are no longer relevant, so we don't execute them
77+
notifyWarning(UTBot.message("warning.reconnecting"))
7578
return
7679
}
7780
executeRequestImpl(request)

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/ClientManager.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import org.utbot.cpp.clion.plugin.listeners.ConnectionSettingsListener
1212
import org.utbot.cpp.clion.plugin.utils.logger
1313

1414
@Service
15-
class ClientManager(val project: Project): Disposable {
15+
class ClientManager(val project: Project) : Disposable {
1616
private val clientId = generateClientID()
1717
private val loggingChannels = listOf<LogChannel>(GTestLogChannelImpl(project), ServerLogChannelImpl(project))
1818
var client: Client = Client(project, clientId, loggingChannels)
@@ -28,14 +28,18 @@ class ClientManager(val project: Project): Disposable {
2828
override fun connectionSettingsChanged(newPort: Int, newServerName: String) {
2929
if (newPort != client.port || newServerName != client.serverName) {
3030
project.logger.trace { "Connection settings changed. Setting up new client." }
31-
client.dispose()
32-
client = Client(project, clientId, loggingChannels)
31+
restartClient()
3332
}
3433
}
3534
})
3635
}
3736
}
3837

38+
fun restartClient() {
39+
client.dispose()
40+
client = Client(project, clientId, loggingChannels)
41+
}
42+
3943
override fun dispose() = client.dispose()
4044

4145
private fun generateClientID(): String {

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/ui/statusBar/StatusBarConnectionStatus.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import com.intellij.openapi.wm.StatusBarWidgetFactory
1313
import com.intellij.ui.awt.RelativePoint
1414
import com.intellij.util.Consumer
1515
import org.utbot.cpp.clion.plugin.actions.AskServerToGenerateJsonForProjectConfiguration
16+
import org.utbot.cpp.clion.plugin.actions.ReconnectAction
1617
import org.utbot.cpp.clion.plugin.actions.configure.ConfigureProjectAction
1718
import org.utbot.cpp.clion.plugin.actions.configure.ReconfigureProjectAction
1819
import org.utbot.cpp.clion.plugin.actions.ShowWizardAction
@@ -105,6 +106,8 @@ object StatusBarActionsPopup {
105106
actionGroup.addSeparator()
106107
actionGroup.add(ConfigureProjectAction())
107108
actionGroup.addSeparator()
109+
actionGroup.add(ReconnectAction())
110+
actionGroup.addSeparator()
108111
actionGroup.addAction(ReconfigureProjectAction())
109112

110113
return actionGroup

clion-plugin/src/main/resources/META-INF/plugin.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,16 @@
188188
description="Generates tests for file without context of a project">
189189
<synonym text="US"/>
190190
</action>
191+
191192
<action id="org.utbot.cpp.clion.plugin.actions.generate.RunAllTestsWithCoverageAction"
192193
class="org.utbot.cpp.clion.plugin.actions.generate.RunAllTestsWithCoverageAction"
193194
text="UTBot: Run All Tests and Show Coverage"/>
195+
196+
<action id="org.utbot.cpp.clion.plugin.actions.ReconnectAction"
197+
class="org.utbot.cpp.clion.plugin.actions.ReconnectAction" text="Reconnect to Server"
198+
description="Recreates connection to server, useful when you launch the server and plugin don&#39;t connect immedeately">
199+
<override-text place="GoToAction" text="UTBot: Reconnect to Server"/>
200+
</action>
201+
194202
</actions>
195203
</idea-plugin>

clion-plugin/src/main/resources/messages/UTBot.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ settings.project.remotePath=Path to project on remote machine
1414
settings.project.serverName=Server host name
1515
settings.project.port=Server port
1616
settings.project.cmakeOptions=Cmake options
17+
actions.reconnect=Reconnect to Server
1718
requests.assertion.description.progress=Generating for assertion...
1819
requests.file.description.progress=Generating for file...
1920
requests.function.description.progress=Generating for function...
@@ -49,3 +50,4 @@ advanced.timeoutPerFunction.description=Maximum time (in seconds) alloted for ge
4950
advanced.timeoutPerTest.title=Timeout per test:
5051
advanced.timeoutPerTest.description=Maximum time (in seconds) alloted for a single test run. Set to non-positive number to disable it. <a href=https://github.com/UnitTestBot/UTBotCpp/wiki/vscode-extension-settings#timeout-per-test>Learn more</a>
5152
targets.notargets.description=No targets can be found by UTBot in current project
53+
warning.reconnecting=Reconnecting to server! Request won't be executed! Please try again, later.

0 commit comments

Comments
 (0)