Skip to content

add ReconnectAction and add it in status bar popup #401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.utbot.cpp.clion.plugin.actions

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.components.service
import org.utbot.cpp.clion.plugin.UTBot
import org.utbot.cpp.clion.plugin.client.ClientManager

class ReconnectAction: AnAction(UTBot.message("actions.reconnect")) {
override fun actionPerformed(e: AnActionEvent) {
e.project!!.service<ClientManager>().restartClient()
}

override fun update(e: AnActionEvent) {
e.presentation.isEnabledAndVisible = e.project != null
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to extend this availability by ON/OFF boolean from per-project UTBotCpp plugin option?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't add ON/OFF functionality for plugin yet. So no

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeout
import org.jetbrains.annotations.TestOnly
import org.utbot.cpp.clion.plugin.UTBot
import org.utbot.cpp.clion.plugin.client.channels.LogChannel
import org.utbot.cpp.clion.plugin.client.requests.CheckProjectConfigurationRequest
import org.utbot.cpp.clion.plugin.grpc.getProjectConfigGrpcRequest
import org.utbot.cpp.clion.plugin.listeners.ConnectionStatus
import org.utbot.cpp.clion.plugin.listeners.UTBotEventsListener
import org.utbot.cpp.clion.plugin.settings.projectIndependentSettings
import org.utbot.cpp.clion.plugin.utils.logger
import org.utbot.cpp.clion.plugin.utils.notifyWarning
import testsgen.Testgen

/**
Expand Down Expand Up @@ -72,6 +74,7 @@ class Client(
if (isDisposed) {
// if client is disposed, then connection settings were changed, and requests issued to this client
// are no longer relevant, so we don't execute them
notifyWarning(UTBot.message("warning.reconnecting"))
return
}
executeRequestImpl(request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.utbot.cpp.clion.plugin.listeners.ConnectionSettingsListener
import org.utbot.cpp.clion.plugin.utils.logger

@Service
class ClientManager(val project: Project): Disposable {
class ClientManager(val project: Project) : Disposable {
private val clientId = generateClientID()
private val loggingChannels = listOf<LogChannel>(GTestLogChannelImpl(project), ServerLogChannelImpl(project))
var client: Client = Client(project, clientId, loggingChannels)
Expand All @@ -28,14 +28,18 @@ class ClientManager(val project: Project): Disposable {
override fun connectionSettingsChanged(newPort: Int, newServerName: String) {
if (newPort != client.port || newServerName != client.serverName) {
project.logger.trace { "Connection settings changed. Setting up new client." }
client.dispose()
client = Client(project, clientId, loggingChannels)
restartClient()
}
}
})
}
}

fun restartClient() {
client.dispose()
client = Client(project, clientId, loggingChannels)
}

override fun dispose() = client.dispose()

private fun generateClientID(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.intellij.openapi.wm.StatusBarWidgetFactory
import com.intellij.ui.awt.RelativePoint
import com.intellij.util.Consumer
import org.utbot.cpp.clion.plugin.actions.AskServerToGenerateJsonForProjectConfiguration
import org.utbot.cpp.clion.plugin.actions.ReconnectAction
import org.utbot.cpp.clion.plugin.actions.configure.ConfigureProjectAction
import org.utbot.cpp.clion.plugin.actions.configure.ReconfigureProjectAction
import org.utbot.cpp.clion.plugin.actions.ShowWizardAction
Expand Down Expand Up @@ -105,6 +106,8 @@ object StatusBarActionsPopup {
actionGroup.addSeparator()
actionGroup.add(ConfigureProjectAction())
actionGroup.addSeparator()
actionGroup.add(ReconnectAction())
actionGroup.addSeparator()
actionGroup.addAction(ReconfigureProjectAction())

return actionGroup
Expand Down
8 changes: 8 additions & 0 deletions clion-plugin/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,16 @@
description="Generates tests for file without context of a project">
<synonym text="US"/>
</action>

<action id="org.utbot.cpp.clion.plugin.actions.generate.RunAllTestsWithCoverageAction"
class="org.utbot.cpp.clion.plugin.actions.generate.RunAllTestsWithCoverageAction"
text="UTBot: Run All Tests and Show Coverage"/>

<action id="org.utbot.cpp.clion.plugin.actions.ReconnectAction"
class="org.utbot.cpp.clion.plugin.actions.ReconnectAction" text="Reconnect to Server"
description="Recreates connection to server, useful when you launch the server and plugin don&#39;t connect immedeately">
<override-text place="GoToAction" text="UTBot: Reconnect to Server"/>
</action>

</actions>
</idea-plugin>
2 changes: 2 additions & 0 deletions clion-plugin/src/main/resources/messages/UTBot.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ settings.project.remotePath=Path to project on remote machine
settings.project.serverName=Server host name
settings.project.port=Server port
settings.project.cmakeOptions=Cmake options
actions.reconnect=Reconnect to Server
requests.assertion.description.progress=Generating for assertion...
requests.file.description.progress=Generating for file...
requests.function.description.progress=Generating for function...
Expand Down Expand Up @@ -49,3 +50,4 @@ advanced.timeoutPerFunction.description=Maximum time (in seconds) alloted for ge
advanced.timeoutPerTest.title=Timeout per test:
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>
targets.notargets.description=No targets can be found by UTBot in current project
warning.reconnecting=Reconnecting to server! Request won't be executed! Please try again, later.