Skip to content

Refactor some other pieces of code in CLion plugin #358

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 1 commit into from
Jul 29, 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
Expand Up @@ -2,7 +2,7 @@ package org.utbot.cpp.clion.plugin.actions.generate

import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import org.utbot.cpp.clion.plugin.client.requests.AssertionRequest
import org.utbot.cpp.clion.plugin.client.requests.test.AssertionRequest
import org.utbot.cpp.clion.plugin.grpc.getAssertionGrpcRequest
import org.utbot.cpp.clion.plugin.utils.activeProject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.utbot.cpp.clion.plugin.actions.generate

import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import org.utbot.cpp.clion.plugin.client.requests.ClassRequest
import org.utbot.cpp.clion.plugin.client.requests.test.ClassRequest
import org.utbot.cpp.clion.plugin.grpc.getClassGrpcRequest
import org.utbot.cpp.clion.plugin.utils.activeProject
import org.utbot.cpp.clion.plugin.utils.isCPPFileName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.utbot.cpp.clion.plugin.actions.generate

import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import org.utbot.cpp.clion.plugin.client.requests.FileRequest
import org.utbot.cpp.clion.plugin.client.requests.test.FileRequest
import org.utbot.cpp.clion.plugin.grpc.getFileGrpcRequest
import org.utbot.cpp.clion.plugin.utils.activeProject
import org.utbot.cpp.clion.plugin.utils.isCPPorCFileName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.utbot.cpp.clion.plugin.actions.generate

import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import org.utbot.cpp.clion.plugin.client.requests.FolderRequest
import org.utbot.cpp.clion.plugin.client.requests.test.FolderRequest
import org.utbot.cpp.clion.plugin.grpc.getFolderGrpcRequest
import org.utbot.cpp.clion.plugin.utils.activeProject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.utbot.cpp.clion.plugin.actions.generate

import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import org.utbot.cpp.clion.plugin.client.requests.FunctionRequest
import org.utbot.cpp.clion.plugin.client.requests.test.FunctionRequest
import org.utbot.cpp.clion.plugin.grpc.getFunctionGrpcRequest
import org.utbot.cpp.clion.plugin.utils.activeProject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.utbot.cpp.clion.plugin.actions.generate

import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import org.utbot.cpp.clion.plugin.client.requests.LineRequest
import org.utbot.cpp.clion.plugin.client.requests.test.LineRequest
import org.utbot.cpp.clion.plugin.grpc.getLineGrpcRequest
import org.utbot.cpp.clion.plugin.utils.activeProject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import javax.swing.ListSelectionModel
import javax.swing.event.DocumentEvent
import org.utbot.cpp.clion.plugin.grpc.getFunctionGrpcRequest
import org.utbot.cpp.clion.plugin.grpc.getPredicateGrpcRequest
import org.utbot.cpp.clion.plugin.client.requests.FunctionReturnTypeRequest
import org.utbot.cpp.clion.plugin.client.requests.PredicateRequest
import org.utbot.cpp.clion.plugin.client.requests.test.FunctionReturnTypeRequest
import org.utbot.cpp.clion.plugin.client.requests.test.PredicateRequest
import org.utbot.cpp.clion.plugin.utils.activeProject
import org.utbot.cpp.clion.plugin.utils.currentClient
import org.utbot.cpp.clion.plugin.utils.notifyError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.utbot.cpp.clion.plugin.actions.generate

import com.intellij.openapi.actionSystem.AnActionEvent
import org.utbot.cpp.clion.plugin.grpc.getProjectGrpcRequest
import org.utbot.cpp.clion.plugin.client.requests.ProjectRequest
import org.utbot.cpp.clion.plugin.client.requests.test.ProjectRequest
import org.utbot.cpp.clion.plugin.utils.activeProject
import org.utbot.cpp.clion.plugin.utils.currentClient

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.utbot.cpp.clion.plugin.actions.generate

import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import org.utbot.cpp.clion.plugin.client.requests.SnippetRequest
import org.utbot.cpp.clion.plugin.client.requests.test.SnippetRequest
import org.utbot.cpp.clion.plugin.grpc.getSnippetGrpcRequest
import org.utbot.cpp.clion.plugin.utils.activeProject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeout
import org.jetbrains.annotations.TestOnly
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
Expand All @@ -31,7 +32,7 @@ import testsgen.Testgen
class Client(
val project: Project,
clientId: String,
private val loggingChannels: List<LoggingChannel>
private val loggingChannels: List<LogChannel>
) : Disposable,
GrpcClient(projectIndependentSettings.port, projectIndependentSettings.serverName, clientId) {
var connectionStatus = ConnectionStatus.INIT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ package org.utbot.cpp.clion.plugin.client
import com.intellij.openapi.Disposable
import com.intellij.openapi.components.Service
import com.intellij.openapi.project.Project
import org.utbot.cpp.clion.plugin.client.channels.GTestLogChannelImpl
import org.utbot.cpp.clion.plugin.client.channels.LogChannel
import org.utbot.cpp.clion.plugin.client.channels.ServerLogChannelImpl
import kotlin.random.Random
import org.utbot.cpp.clion.plugin.listeners.ConnectionSettingsListener
import org.utbot.cpp.clion.plugin.utils.logger

@Service
class ClientManager(val project: Project): Disposable {
private val clientId = generateClientID()
private val loggingChannels = listOf<LoggingChannel>(GTestChannel(project), ServerLogChannel(project))
private val loggingChannels = listOf<LogChannel>(GTestLogChannelImpl(project), ServerLogChannelImpl(project))
var client: Client = Client(project, clientId, loggingChannels)
private set

Expand All @@ -32,9 +35,7 @@ class ClientManager(val project: Project): Disposable {
}
}

override fun dispose() {
client.dispose()
}
override fun dispose() = client.dispose()

private fun generateClientID(): String {
fun createRandomSequence() = (1..RANDOM_SEQUENCE_LENGTH)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.utbot.cpp.clion.plugin.client.channels

import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import kotlinx.coroutines.flow.Flow
import org.utbot.cpp.clion.plugin.grpc.getDummyGrpcRequest
import org.utbot.cpp.clion.plugin.grpc.getLogChannelGrpcRequest
import org.utbot.cpp.clion.plugin.ui.services.OutputProvider
import org.utbot.cpp.clion.plugin.ui.userLog.UTBotConsole
import testsgen.Testgen
import testsgen.TestsGenServiceGrpcKt

class GTestLogChannelImpl(project: Project): LogChannelImpl(project) {
override val name: String = "GTest Log"
override val logLevel: String = "TestLogLevel"

override val console: UTBotConsole = project.service<OutputProvider>().gtestOutputChannel.outputConsole

override suspend fun open(stub: TestsGenServiceGrpcKt.TestsGenServiceCoroutineStub): Flow<Testgen.LogEntry> =
stub.openGTestChannel(getLogChannelGrpcRequest(logLevel))

override suspend fun close(stub: TestsGenServiceGrpcKt.TestsGenServiceCoroutineStub) {
stub.closeGTestChannel(getDummyGrpcRequest())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.utbot.cpp.clion.plugin.client.channels

import com.intellij.openapi.project.Project
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collect
import org.utbot.cpp.clion.plugin.ui.userLog.UTBotConsole
import org.utbot.cpp.clion.plugin.utils.invokeOnEdt
import org.utbot.cpp.clion.plugin.utils.logger
import testsgen.Testgen
import testsgen.TestsGenServiceGrpcKt

interface LogChannel {
suspend fun provide(stub: TestsGenServiceGrpcKt.TestsGenServiceCoroutineStub)
}

abstract class LogChannelImpl(val project: Project): LogChannel {
abstract val name: String
abstract val logLevel: String

abstract val console: UTBotConsole

abstract suspend fun open(stub: TestsGenServiceGrpcKt.TestsGenServiceCoroutineStub): Flow<Testgen.LogEntry>
abstract suspend fun close(stub: TestsGenServiceGrpcKt.TestsGenServiceCoroutineStub)

override fun toString(): String = name

override suspend fun provide(stub: TestsGenServiceGrpcKt.TestsGenServiceCoroutineStub) {
val logger = project.logger
try {
close(stub)
} catch (cause: io.grpc.StatusException) {
logger.error{ "Exception when closing log channel: $name \n$cause" }
}

open(stub)
.catch { cause -> logger.error{ "Exception in log channel: $name \n$cause" } }
.collect { invokeOnEdt { console.info(it.message) } }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.utbot.cpp.clion.plugin.client.channels

import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import kotlinx.coroutines.flow.Flow
import org.utbot.cpp.clion.plugin.grpc.getDummyGrpcRequest
import org.utbot.cpp.clion.plugin.grpc.getLogChannelGrpcRequest
import org.utbot.cpp.clion.plugin.ui.services.OutputProvider
import org.utbot.cpp.clion.plugin.ui.userLog.UTBotConsole
import testsgen.Testgen
import testsgen.TestsGenServiceGrpcKt.TestsGenServiceCoroutineStub

class ServerLogChannelImpl(project: Project): LogChannelImpl(project) {
override val name: String = "Server Log"
override val logLevel: String = "ServerLogLevel"

override val console: UTBotConsole = project.service<OutputProvider>().serverOutputChannel.outputConsole

override suspend fun open(stub: TestsGenServiceCoroutineStub): Flow<Testgen.LogEntry> =
stub.openLogChannel(getLogChannelGrpcRequest(logLevel))

override suspend fun close(stub: TestsGenServiceCoroutineStub) {
stub.closeLogChannel(getDummyGrpcRequest())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,12 @@ class CoverageAndResultsHandler(
)

manager.coverageGathered(suite)
notify(response)
notifyCoverageReceived()
}

private fun notify(reponse: Testgen.CoverageAndResultsResponse) {
sourceFilePath ?: return
notifyInfo(
"Coverage received!", project,
FocusAction(sourceFilePath)
)
private fun notifyCoverageReceived() {
if (sourceFilePath != null) {
notifyInfo("Coverage received!", project, FocusAction(sourceFilePath))
}
}
}
Loading