Skip to content

Commit 45db4f5

Browse files
committed
Refactor UI related logic
1 parent 60ae0c7 commit 45db4f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+866
-878
lines changed

clion-plugin/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ all configuration options.
4343
1. Open plugin settings in settings - Tools - UTBot Settings
4444
2. Click `detect paths`. It will try to get source paths, build dir paths from CLion
4545
CMake model.
46-
3. Specify absolute path to build folder, it should be different from build folder that CLion uses,
46+
3. Specify absolute path to build directory, it should be different from build directory that CLion uses,
4747
because there can be conflicts between UTBotCpp and CLion. For example, if CLion uses `project_path/cmake-build-debug`,
4848
then you can specify `project_path/utbot_build`.
4949
4. For target path specify `/utbot/auto/target/path`

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package org.utbot.cpp.clion.plugin
22

33
import com.intellij.ide.util.RunOnceUtil
4-
import com.intellij.openapi.components.service
54
import com.intellij.openapi.project.Project
65
import com.intellij.openapi.startup.StartupActivity
76
import org.utbot.cpp.clion.plugin.client.Client
8-
import org.utbot.cpp.clion.plugin.settings.UTBotPluginSpecificSettings
97
import org.utbot.cpp.clion.plugin.settings.pluginSettings
108
import org.utbot.cpp.clion.plugin.settings.settings
119
import org.utbot.cpp.clion.plugin.ui.wizard.UTBotWizard
@@ -14,13 +12,14 @@ import org.utbot.cpp.clion.plugin.utils.invokeOnEdt
1412

1513
class UTBotStartupActivity : StartupActivity {
1614
override fun runActivity(project: Project) {
17-
15+
//TODO: preload instantiating the client and avoid such magic
1816
project.getClient()
19-
guessPathsOnFirstProjectOpen(project)
20-
showWizardOnFirstProjectOpen(project)
17+
18+
guessPathsOnFirstOpen(project)
19+
showWizardOnFirstOpen(project)
2120
}
2221

23-
private fun showWizardOnFirstProjectOpen(project: Project) {
22+
private fun showWizardOnFirstOpen(project: Project) {
2423
if (pluginSettings.isFirstLaunch && !Client.IS_TEST_MODE) {
2524
pluginSettings.isFirstLaunch = false
2625
invokeOnEdt {
@@ -29,7 +28,7 @@ class UTBotStartupActivity : StartupActivity {
2928
}
3029
}
3130

32-
private fun guessPathsOnFirstProjectOpen(project: Project) {
31+
private fun guessPathsOnFirstOpen(project: Project) {
3332
RunOnceUtil.runOnceForProject(project, "Guess UTBot paths in settings") {
3433
project.settings.predictPaths()
3534
}

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/generate/BaseGenerateTestsAction.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ package org.utbot.cpp.clion.plugin.actions.generate
22

33
import com.intellij.openapi.actionSystem.AnAction
44
import com.intellij.openapi.actionSystem.AnActionEvent
5-
import org.utbot.cpp.clion.plugin.utils.client
5+
import org.utbot.cpp.clion.plugin.utils.getClient
66

77
abstract class BaseGenerateTestsAction : AnAction() {
88

99
override fun update(e: AnActionEvent) {
1010
val isDefined: Boolean = isDefined(e)
1111

1212
e.presentation.isVisible = isDefined
13-
e.presentation.isEnabled = isDefined && e.client.isServerAvailable()
13+
e.presentation.isEnabled = isDefined && e.getClient().isServerAvailable()
1414
}
1515

1616
/**

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/generate/GenerateForPredicateAction.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import org.utbot.cpp.clion.plugin.grpc.getPredicateGrpcRequest
1414
import org.utbot.cpp.clion.plugin.client.requests.FunctionReturnTypeRequest
1515
import org.utbot.cpp.clion.plugin.client.requests.PredicateRequest
1616
import org.utbot.cpp.clion.plugin.utils.activeProject
17-
import org.utbot.cpp.clion.plugin.utils.client
17+
import org.utbot.cpp.clion.plugin.utils.getClient
1818
import org.utbot.cpp.clion.plugin.utils.notifyError
1919
import testsgen.Util.ValidationType
2020
import java.awt.Dimension
@@ -48,7 +48,7 @@ class GenerateForPredicateAction : BaseGenerateTestsAction() {
4848
getPredicateGrpcRequest(e, comparisonOperator, validationType, valueToCompare),
4949
e.activeProject()
5050
).apply {
51-
e.client.executeRequest(this)
51+
e.getClient().executeRequest(this)
5252
}
5353

5454
// ask for comparison operator to use in predicate
@@ -111,7 +111,7 @@ class GenerateForPredicateAction : BaseGenerateTestsAction() {
111111
}
112112
}
113113
}.apply {
114-
e.client.executeRequest(this)
114+
e.getClient().executeRequest(this)
115115
}
116116
}
117117

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/generate/GenerateForProjectAction.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import com.intellij.openapi.actionSystem.AnActionEvent
44
import org.utbot.cpp.clion.plugin.grpc.getProjectGrpcRequest
55
import org.utbot.cpp.clion.plugin.client.requests.ProjectRequest
66
import org.utbot.cpp.clion.plugin.utils.activeProject
7-
import org.utbot.cpp.clion.plugin.utils.client
7+
import org.utbot.cpp.clion.plugin.utils.getClient
88

99
class GenerateForProjectAction : BaseGenerateTestsAction() {
1010
override fun actionPerformed(e: AnActionEvent) {
1111
ProjectRequest(
1212
getProjectGrpcRequest(e),
1313
e.activeProject(),
1414
).apply {
15-
e.client.executeRequest(this)
15+
e.getClient().executeRequest(this)
1616
}
1717
}
1818

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/generate/RunWithCoverageAction.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class RunWithCoverageAction(val element: PsiElement) : BaseGenerateTestsAction()
1414
override fun actionPerformed(e: AnActionEvent) {
1515
logger.debug("Action RunWithCoverageAction was called")
1616

17-
val testArgs = TestNameAndTestSuite.getFromPsiElement(element)
17+
val testArgs = TestNameAndTestSuite.create(element)
1818
val suiteName = testArgs.suite
1919
val testedMethodName = testArgs.name
2020
val filePath = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE).path

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import kotlinx.coroutines.SupervisorJob
1212
import kotlinx.coroutines.cancel
1313
import kotlinx.coroutines.delay
1414
import kotlinx.coroutines.isActive
15+
import kotlinx.coroutines.job
1516
import kotlinx.coroutines.launch
1617
import kotlinx.coroutines.runBlocking
1718
import kotlinx.coroutines.withTimeout
@@ -20,7 +21,6 @@ import org.utbot.cpp.clion.plugin.grpc.getProjectConfigGrpcRequest
2021
import org.utbot.cpp.clion.plugin.listeners.ConnectionStatus
2122
import org.utbot.cpp.clion.plugin.listeners.UTBotEventsListener
2223
import org.utbot.cpp.clion.plugin.settings.projectIndependentSettings
23-
import org.utbot.cpp.clion.plugin.utils.hasChildren
2424
import org.utbot.cpp.clion.plugin.utils.logger
2525
import testsgen.Testgen
2626

@@ -49,15 +49,15 @@ class Client(
4949
exception.printStackTrace()
5050
}
5151

52-
val dispatcher = Dispatchers.IO
52+
private val dispatcher = Dispatchers.IO
5353

5454
// coroutine scope for requests that don't have a lifetime of a plugin, e.g. generation requests
5555
// this division is needed for testing: when in test we send a generate request to server, we need to wait
5656
// until it completes, the indicator that all such requests have completed is that this scope has no children
57-
val requestsCS: CoroutineScope = CoroutineScope(dispatcher + excHandler + SupervisorJob())
57+
private val requestsCS: CoroutineScope = CoroutineScope(dispatcher + excHandler + SupervisorJob())
5858

5959
// coroutine scope for suspending functions that can live entire plugin lifetime, e.g. server logs, gtest logs, heartbeat
60-
val servicesCS: CoroutineScope = CoroutineScope(dispatcher + excHandler + SupervisorJob())
60+
private val servicesCS: CoroutineScope = CoroutineScope(dispatcher + excHandler + SupervisorJob())
6161

6262
init {
6363
logger.info { "Connecting to server on host: ${projectIndependentSettings.serverName} , port: ${projectIndependentSettings.port}" }
@@ -179,14 +179,16 @@ class Client(
179179
fun waitForServerRequestsToFinish(timeout: Long = SERVER_TIMEOUT) {
180180
runBlocking {
181181
withTimeout(timeout) {
182-
while (requestsCS.hasChildren()) {
182+
val hasChildJobs = requestsCS.coroutineContext.job.children.any()
183+
while (hasChildJobs) {
183184
delay(DELAY_TIME)
184185
}
185186
}
186187
}
187188
}
188189

189190
companion object {
191+
//TODO: why don't use process this setting similarly to "isFirstLaunch"? Why is it a property of the client?
190192
var IS_TEST_MODE = false
191193
const val HEARTBEAT_INTERVAL: Long = 500L
192194
const val SERVER_TIMEOUT: Long = 300000L

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import kotlinx.coroutines.flow.catch
77
import kotlinx.coroutines.flow.collect
88
import org.utbot.cpp.clion.plugin.grpc.getDummyGrpcRequest
99
import org.utbot.cpp.clion.plugin.grpc.getLogChannelGrpcRequest
10-
import org.utbot.cpp.clion.plugin.ui.userLog.OutputProvider
10+
import org.utbot.cpp.clion.plugin.ui.services.OutputProvider
1111
import org.utbot.cpp.clion.plugin.ui.userLog.UTBotConsole
1212
import org.utbot.cpp.clion.plugin.utils.invokeOnEdt
1313
import org.utbot.cpp.clion.plugin.utils.logger

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import org.utbot.cpp.clion.plugin.utils.notifyError
1313
import org.utbot.cpp.clion.plugin.utils.notifyInfo
1414
import org.utbot.cpp.clion.plugin.utils.notifyUnknownResponse
1515
import org.utbot.cpp.clion.plugin.utils.notifyWarning
16-
import org.utbot.cpp.clion.plugin.utils.refreshAndFindIOFile
16+
import org.utbot.cpp.clion.plugin.utils.refreshAndFindNioFile
1717
import testsgen.Testgen
1818

1919
abstract class ProjectConfigResponseHandler(
@@ -56,8 +56,9 @@ class CheckProjectConfigurationHandler(
5656
val missingFileName =
5757
if (response.type == Testgen.ProjectConfigStatus.LINK_COMMANDS_JSON_NOT_FOUND) "link_commands.json" else "compile_commands.json"
5858
notifyError(
59-
"Project is not configured properly: $missingFileName is missing in the build folder.",
60-
project, AskServerToGenerateJsonForProjectConfiguration()
59+
"Project is not configured properly: file $missingFileName is missed in the build directory",
60+
project,
61+
AskServerToGenerateJsonForProjectConfiguration(),
6162
)
6263
}
6364
Testgen.ProjectConfigStatus.BUILD_DIR_SAME_AS_PROJECT -> {
@@ -87,7 +88,7 @@ class CreateBuildDirHandler(
8788
}
8889
else -> notifyUnknownResponse(response, project)
8990
}
90-
refreshAndFindIOFile(project.settings.buildDirPath.toString())
91+
refreshAndFindNioFile(project.settings.buildDirPath)
9192
}
9293
}
9394

@@ -106,6 +107,6 @@ class GenerateJsonHandler(
106107
)
107108
else -> notifyUnknownResponse(response, project)
108109
}
109-
refreshAndFindIOFile(project.settings.buildDirPath.toString())
110+
refreshAndFindNioFile(project.settings.buildDirPath)
110111
}
111112
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ abstract class StreamHandlerWithProgress<T>(
2727
override fun onFinish() {
2828
super.onFinish()
2929
invokeOnEdt {
30-
indicator.complete()
30+
indicator.finish()
3131
}
3232
}
3333

0 commit comments

Comments
 (0)