Skip to content

Commit c876507

Browse files
committed
add titles to notifications, change texts
1 parent e11a9a5 commit c876507

35 files changed

+240
-106
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.utbot.cpp.clion.plugin.actions
2+
3+
import com.intellij.openapi.actionSystem.AnActionEvent
4+
import com.intellij.openapi.options.ShowSettingsUtil
5+
import com.intellij.openapi.project.DumbAwareAction
6+
import org.utbot.cpp.clion.plugin.UTBot
7+
import org.utbot.cpp.clion.plugin.settings.UTBotConfigurable
8+
9+
class ShowSettingsAction : DumbAwareAction(UTBot.message("show.settings.text"))/*, LightEditCompatible*/ {
10+
override fun actionPerformed(e: AnActionEvent) {
11+
ShowSettingsUtil.getInstance().showSettingsDialog(e.project, UTBotConfigurable::class.java)
12+
}
13+
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,16 @@ package org.utbot.cpp.clion.plugin.actions.generate
33
import com.intellij.openapi.actionSystem.AnActionEvent
44
import com.intellij.openapi.actionSystem.CommonDataKeys
55
import org.utbot.cpp.clion.plugin.client.requests.test.FolderRequest
6-
import org.utbot.cpp.clion.plugin.grpc.IllegalActionEventException
76
import org.utbot.cpp.clion.plugin.grpc.ParamsBuilder
87
import org.utbot.cpp.clion.plugin.utils.activeProject
98
import org.utbot.cpp.clion.plugin.utils.getFilePathUnsafe
109

1110
class GenerateForFolderAction : BaseGenerateTestsAction() {
1211
override fun actionPerformed(e: AnActionEvent) =
13-
try {
1412
FolderRequest(
1513
ParamsBuilder(e.activeProject()).buildFolderRequestParams(e.getFilePathUnsafe()),
1614
e.activeProject()
1715
).executeUsingCurrentClient()
18-
} catch (exception: IllegalActionEventException) {
19-
// should never happen, all keys should be checked in update
20-
exception.notifyUser()
21-
}
2216

2317
override fun isDefined(e: AnActionEvent): Boolean {
2418
val project = e.project

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.intellij.ui.DocumentAdapter
99
import com.intellij.ui.components.fields.ExtendableTextField
1010
import javax.swing.ListSelectionModel
1111
import javax.swing.event.DocumentEvent
12+
import org.utbot.cpp.clion.plugin.UTBot
1213
import org.utbot.cpp.clion.plugin.client.requests.test.FunctionReturnTypeRequest
1314
import org.utbot.cpp.clion.plugin.client.requests.test.PredicateRequest
1415
import org.utbot.cpp.clion.plugin.grpc.ParamsBuilder
@@ -72,13 +73,15 @@ class GenerateForPredicateAction : BaseGenerateTestsAction() {
7273
}
7374
ValidationType.UNSUPPORTED -> {
7475
notifyError(
76+
UTBot.message("notify.title.error"),
7577
"Unsupported return type for \'Generate Tests With Prompted Result\' feature: \n" +
7678
"supported types are integers, booleans, characters, floats and strings"
7779
)
7880
return
7981
}
8082
ValidationType.UNRECOGNIZED -> {
8183
notifyError(
84+
UTBot.message("notify.title.error"),
8285
"Could not recognise return type for 'Generate Tests With Prompted Result' feature: \n" +
8386
"supported types are integers, booleans, characters, floats and strings"
8487
)

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

Lines changed: 75 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.utbot.cpp.clion.plugin.client
33
import com.intellij.openapi.Disposable
44
import com.intellij.openapi.project.Project
55
import io.grpc.Status
6+
import io.grpc.StatusException
67
import kotlinx.coroutines.CoroutineExceptionHandler
78
import kotlinx.coroutines.CoroutineName
89
import kotlinx.coroutines.CoroutineScope
@@ -18,6 +19,8 @@ import kotlinx.coroutines.runBlocking
1819
import kotlinx.coroutines.withTimeout
1920
import org.jetbrains.annotations.TestOnly
2021
import org.utbot.cpp.clion.plugin.UTBot
22+
import org.utbot.cpp.clion.plugin.actions.ReconnectAction
23+
import org.utbot.cpp.clion.plugin.actions.ShowSettingsAction
2124
import org.utbot.cpp.clion.plugin.client.channels.LogChannel
2225
import org.utbot.cpp.clion.plugin.client.requests.CheckProjectConfigurationRequest
2326
import org.utbot.cpp.clion.plugin.grpc.IllegalPathException
@@ -26,6 +29,8 @@ import org.utbot.cpp.clion.plugin.listeners.ConnectionStatus
2629
import org.utbot.cpp.clion.plugin.listeners.UTBotEventsListener
2730
import org.utbot.cpp.clion.plugin.settings.projectIndependentSettings
2831
import org.utbot.cpp.clion.plugin.utils.logger
32+
import org.utbot.cpp.clion.plugin.utils.notifyError
33+
import org.utbot.cpp.clion.plugin.utils.notifyInfo
2934
import org.utbot.cpp.clion.plugin.utils.notifyWarning
3035
import testsgen.Testgen
3136

@@ -75,7 +80,10 @@ class Client(
7580
if (isDisposed) {
7681
// if client is disposed, then connection settings were changed, and requests issued to this client
7782
// are no longer relevant, so we don't execute them
78-
notifyWarning(UTBot.message("warning.reconnecting"))
83+
notifyWarning(
84+
UTBot.message("notify.warning.reconnecting.title"),
85+
UTBot.message("notify.warning.reconnecting")
86+
)
7987
return
8088
}
8189
executeRequestImpl(request)
@@ -86,9 +94,57 @@ class Client(
8694
try {
8795
request.execute(stub, coroutineContext[Job])
8896
} catch (e: io.grpc.StatusException) {
89-
handleGRPCStatusException(e, "Exception when executing server request")
97+
val id = request.id
98+
when (e.status.code) {
99+
Status.UNAVAILABLE.code -> notifyError(
100+
UTBot.message("notify.title.noConnection"),
101+
UTBot.message("notify.noConnection"),
102+
project,
103+
ShowSettingsAction(),
104+
ReconnectAction()
105+
)
106+
Status.UNKNOWN.code -> notifyError(
107+
UTBot.message("notify.title.unknownServerException"),
108+
UTBot.message("notify.unknownServerException"),
109+
project
110+
)
111+
Status.CANCELLED.code -> notifyError(
112+
UTBot.message("notify.title.cancelled"),
113+
UTBot.message("notify.cancelled", id, e.message ?: ""),
114+
project
115+
)
116+
Status.FAILED_PRECONDITION.code -> notifyError(
117+
UTBot.message("notify.title.failedPrecondition"),
118+
UTBot.message("notify.failedPrecondition", id, e.message ?: ""),
119+
project
120+
)
121+
Status.INTERNAL.code -> notifyError(
122+
UTBot.message("notify.title.internalError"),
123+
UTBot.message("notify.internalError", request, e.message ?: ""),
124+
project
125+
)
126+
Status.UNIMPLEMENTED.code -> notifyError(
127+
UTBot.message("notify.title.error"),
128+
UTBot.message("notify.unimplemented", id, e.message ?: ""),
129+
project
130+
)
131+
Status.INVALID_ARGUMENT.code -> notifyError(
132+
UTBot.message("notify.title.invalid.argument"),
133+
UTBot.message("notify.invalid.argument", e.message ?: "", id),
134+
project
135+
)
136+
else -> notifyError(
137+
UTBot.message("notify.title.error"),
138+
e.message ?: "Corresponding exception's message is missing",
139+
project
140+
)
141+
}
90142
} catch (e: IllegalPathException) {
91-
e.notifyUser()
143+
notifyError(
144+
UTBot.message("notify.bad.settings.title"),
145+
UTBot.message("notify.bad.path", e.message ?: ""),
146+
project
147+
)
92148
}
93149
}
94150
}
@@ -118,7 +174,7 @@ class Client(
118174
logger.info { "Sending REGISTER CLIENT request, clientID == $clientId" }
119175
stub.registerClient(Testgen.RegisterClientRequest.newBuilder().setClientId(clientId).build())
120176
} catch (e: io.grpc.StatusException) {
121-
handleGRPCStatusException(e, "Register client request failed with grpc exception!")
177+
logger.error { "${e.status}: ${e.message}" }
122178
}
123179
}
124180
}
@@ -144,6 +200,7 @@ class Client(
144200
connectionStatus = ConnectionStatus.CONNECTED
145201

146202
if (oldStatus != ConnectionStatus.CONNECTED) {
203+
notifyInfo(UTBot.message("notify.connected.title"), UTBot.message("notify.connected", port, serverName))
147204
logger.info { "Successfully connected to server!" }
148205
registerClient()
149206
configureProject()
@@ -168,19 +225,18 @@ class Client(
168225

169226
if (!messageBus.isDisposed) {
170227
val connectionChangedPublisher = messageBus.syncPublisher(UTBotEventsListener.CONNECTION_CHANGED_TOPIC)
171-
if (oldStatus != ConnectionStatus.BROKEN)
228+
if (oldStatus != ConnectionStatus.BROKEN) {
229+
notifyError(
230+
UTBot.message("notify.disconnected.title"),
231+
UTBot.message("notify.disconnected", port, serverName),
232+
project,
233+
ShowSettingsAction()
234+
)
172235
connectionChangedPublisher.onConnectionChange(oldStatus, ConnectionStatus.BROKEN)
236+
}
173237
}
174238

175-
handleGRPCStatusException(e, "Heartbeat failed with grpc io exception")
176-
}
177-
}
178-
179-
private fun handleGRPCStatusException(e: io.grpc.StatusException, message: String) {
180-
logger.error { "$message \n${e.message}" }
181-
when (e.status) {
182-
Status.UNAVAILABLE -> logger.error { "Server is unavailable: possibly it is shut down." }
183-
Status.UNKNOWN -> logger.error { "Server threw an exception." }
239+
logger.error { "${e.status} \n${e.message}" }
184240
}
185241
}
186242

@@ -196,9 +252,11 @@ class Client(
196252

197253
// should be used only in tests
198254
@TestOnly
199-
fun waitForServerRequestsToFinish(timeout: Long = SERVER_TIMEOUT,
200-
delayTime: Long = 1000L,
201-
ifNotFinished: (List<Job>) -> Unit = {}) {
255+
fun waitForServerRequestsToFinish(
256+
timeout: Long = SERVER_TIMEOUT,
257+
delayTime: Long = 1000L,
258+
ifNotFinished: (List<Job>) -> Unit = {}
259+
) {
202260
runBlocking {
203261
withTimeout(timeout) {
204262
while (requestsCS.coroutineContext.job.children.toList().any()) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ interface Request {
1414
* request can't be completed, for example because user canceled it from UI.
1515
*/
1616
suspend fun execute(stub: TestsGenServiceGrpcKt.TestsGenServiceCoroutineStub, cancellationJob: Job?)
17+
abstract val id: String
1718
}

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package org.utbot.cpp.clion.plugin.client.handlers
33
import com.intellij.coverage.CoverageDataManager
44
import com.intellij.coverage.CoverageEngine
55
import com.intellij.coverage.CoverageRunner
6+
import com.intellij.openapi.actionSystem.AnAction
67
import com.intellij.openapi.project.Project
78
import kotlinx.coroutines.Dispatchers
89
import kotlinx.coroutines.Job
910
import kotlinx.coroutines.flow.Flow
1011
import kotlinx.coroutines.withContext
12+
import org.utbot.cpp.clion.plugin.UTBot
1113
import org.utbot.cpp.clion.plugin.actions.FocusAction
1214
import org.utbot.cpp.clion.plugin.coverage.Coverage
1315
import org.utbot.cpp.clion.plugin.coverage.UTBotCoverageEngine
@@ -44,7 +46,11 @@ class CoverageAndResultsHandler(
4446
return
4547
}
4648
if (response.errorMessage.isNotEmpty()) {
47-
notifyError(response.errorMessage, project)
49+
notifyError(
50+
UTBot.message("notify.title.error"),
51+
response.errorMessage,
52+
project
53+
)
4854
}
4955

5056
data class CoverageCollector(
@@ -96,6 +102,13 @@ class CoverageAndResultsHandler(
96102
}
97103

98104
private fun notifyCoverageReceived() {
99-
notifyInfo("Coverage received!", project, sourceFilePath?.let { FocusAction(it) })
105+
val actions = mutableListOf<AnAction>()
106+
sourceFilePath?.let { actions.add(FocusAction(it)) }
107+
notifyInfo(
108+
UTBot.message("notify.coverage.received.title"),
109+
UTBot.message("notify.coverage.received"),
110+
project,
111+
sourceFilePath?.let { FocusAction(it) }
112+
)
100113
}
101114
}

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

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package org.utbot.cpp.clion.plugin.client.handlers
22

33
import com.intellij.openapi.project.Project
4+
import kotlin.io.path.name
45
import kotlinx.coroutines.Job
56
import kotlinx.coroutines.flow.Flow
67
import org.utbot.cpp.clion.plugin.UTBot
78
import org.utbot.cpp.clion.plugin.actions.AskServerToGenerateBuildDir
89
import org.utbot.cpp.clion.plugin.actions.AskServerToGenerateJsonForProjectConfiguration
910
import org.utbot.cpp.clion.plugin.client.Client
1011
import org.utbot.cpp.clion.plugin.client.requests.CheckProjectConfigurationRequest
12+
import org.utbot.cpp.clion.plugin.grpc.ParamsBuilder
1113
import org.utbot.cpp.clion.plugin.settings.settings
1214
import org.utbot.cpp.clion.plugin.utils.logger
1315
import org.utbot.cpp.clion.plugin.utils.notifyError
@@ -44,11 +46,12 @@ class CheckProjectConfigurationHandler(
4446
override fun handle(response: Testgen.ProjectConfigResponse) {
4547
when (response.type) {
4648
Testgen.ProjectConfigStatus.IS_OK -> {
47-
notifyInfo("Project is configured!", project)
49+
notifyInfo(UTBot.message("notify.title.configured"), UTBot.message("notify.configured"), project)
4850
}
4951
Testgen.ProjectConfigStatus.BUILD_DIR_NOT_FOUND -> {
5052
notifyError(
51-
"Project build dir not found! ${response.message}",
53+
UTBot.message("notify.title.missingBuildDir"),
54+
UTBot.message("notify.missingBuildDir"),
5255
project,
5356
AskServerToGenerateBuildDir()
5457
)
@@ -57,15 +60,16 @@ class CheckProjectConfigurationHandler(
5760
val missingFileName =
5861
if (response.type == Testgen.ProjectConfigStatus.LINK_COMMANDS_JSON_NOT_FOUND) "link_commands.json" else "compile_commands.json"
5962
notifyError(
60-
"Project is not configured properly: file $missingFileName is missed in the build directory",
63+
UTBot.message("notify.title.notConfigured"),
64+
UTBot.message("notify.missing.cdb.files", missingFileName),
6165
project,
6266
AskServerToGenerateJsonForProjectConfiguration(),
6367
)
6468
}
6569
Testgen.ProjectConfigStatus.BUILD_DIR_SAME_AS_PROJECT -> {
6670
val message = response.message
6771
logger.warn(message)
68-
notifyWarning("$message ${UTBot.message("uri.wiki")}", project)
72+
notifyError(UTBot.message("notify.title.error"), "$message ${UTBot.message("uri.wiki")}", project)
6973
}
7074
else -> notifyUnknownResponse(response, project)
7175
}
@@ -81,9 +85,14 @@ class CreateBuildDirHandler(
8185
override fun handle(response: Testgen.ProjectConfigResponse) {
8286
when (response.type) {
8387
Testgen.ProjectConfigStatus.IS_OK -> {
84-
notifyInfo("Build directory was created!", project)
88+
notifyInfo(
89+
UTBot.message("notify.build.dir.created.title"),
90+
UTBot.message("notify.build.dir.created", project.settings.buildDirPath.name),
91+
project
92+
)
8593

8694
CheckProjectConfigurationRequest(
95+
ParamsBuilder(project).buildProjectConfigRequestParams(Testgen.ConfigMode.CHECK),
8796
project
8897
).also {
8998
if (!client.isDisposed) {
@@ -92,7 +101,11 @@ class CreateBuildDirHandler(
92101
}
93102
}
94103
Testgen.ProjectConfigStatus.BUILD_DIR_CREATION_FAILED -> {
95-
notifyInfo("Failed to create build directory! ${response.message}", project)
104+
notifyError(
105+
UTBot.message("notify.failed.to.create.build.dir.title"),
106+
"",
107+
project
108+
)
96109
}
97110
else -> notifyUnknownResponse(response, project)
98111
}
@@ -108,10 +121,14 @@ class GenerateJsonHandler(
108121
) : ProjectConfigResponseHandler(project, grpcStream, progressName, cancellationJob) {
109122
override fun handle(response: Testgen.ProjectConfigResponse) {
110123
when (response.type) {
111-
Testgen.ProjectConfigStatus.IS_OK -> notifyInfo("Successfully configured project!", project)
124+
Testgen.ProjectConfigStatus.IS_OK -> notifyInfo(
125+
UTBot.message("notify.title.configured"),
126+
UTBot.message("notify.configured"),
127+
project
128+
)
112129
Testgen.ProjectConfigStatus.RUN_JSON_GENERATION_FAILED -> notifyError(
113-
"UTBot tried to configure project, but failed with the " +
114-
"following message: ${response.message}", project
130+
UTBot.message("notify.title.notConfigured"),
131+
response.message
115132
)
116133
else -> notifyUnknownResponse(response, project)
117134
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,8 @@ abstract class StreamHandler<T>(
3737
abstract fun onData(data: T)
3838

3939
open fun onCompletion(exception: Throwable?) {
40-
if (exception != null) {
41-
logger.warn(exception.message)
42-
if (exception !is CancellationException) {
43-
exception.printStackTrace()
44-
exception.message?.let { notifyError(it, project) }
45-
}
40+
exception?.let {
41+
throw it
4642
}
4743
}
4844

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
@@ -49,11 +49,11 @@ abstract class StreamHandlerWithProgress<T>(
4949
abstract fun T.getProgress(): Util.Progress
5050

5151
override fun onCompletion(exception: Throwable?) {
52-
super.onCompletion(exception)
5352
if (exception != null) {
5453
invokeOnEdt {
5554
indicator.stop()
5655
}
56+
throw exception
5757
}
5858
}
5959
}

0 commit comments

Comments
 (0)