-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ability to enable/disable plugin per project (#404)
* fix merge conflicts * add more docs * don't hide toolwindows on disabling * hide/show settings ui when enabling/disabling plugin * required fixes * rebase * delete empty files * set plugin disabled on default, show wizard on first enabled * don't request targets in tests until ci is fixed * fix console accessed not from edt using lazy delegate * fix logging for tests using tinylog * fix tests: enable plugin & wait for connection
- Loading branch information
Showing
63 changed files
with
585 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 7 additions & 19 deletions
26
clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/UTBotStartupActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,31 @@ | ||
package org.utbot.cpp.clion.plugin | ||
|
||
import com.intellij.ide.util.RunOnceUtil | ||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.components.service | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.startup.StartupActivity | ||
import org.utbot.cpp.clion.plugin.client.ClientManager | ||
import org.utbot.cpp.clion.plugin.client.ManagedClient | ||
import org.utbot.cpp.clion.plugin.settings.settings | ||
import org.utbot.cpp.clion.plugin.ui.wizard.UTBotWizard | ||
import org.utbot.cpp.clion.plugin.utils.invokeOnEdt | ||
|
||
class UTBotStartupActivity : StartupActivity { | ||
override fun runActivity(project: Project) { | ||
// We initialize Client here, so that initialization will not happen | ||
// when user issues first generation request which would cause a UI freeze. | ||
initializeClient(project) | ||
guessPathsOnFirstOpen(project) | ||
showWizardOnFirstOpen(project) | ||
if (project.settings.storedSettings.isPluginEnabled) { | ||
initializeClient(project) | ||
guessPathsOnFirstOpen(project) | ||
} | ||
} | ||
|
||
// Here we address the service ClientManager for the first time so that it | ||
// will be initialized by the ide and Client will be created. | ||
// Client in turn will create a grpc channel and start heart-beating the server. | ||
private fun initializeClient(project: Project) = project.service<ClientManager>() | ||
|
||
private fun initializeClient(project: Project) = project.service<ManagedClient>() | ||
|
||
private fun showWizardOnFirstOpen(project: Project) { | ||
if (!ApplicationManager.getApplication().isUnitTestMode) { | ||
invokeOnEdt { | ||
RunOnceUtil.runOnceForProject(project, "Show UTBot quick-start wizard to configure project") { | ||
UTBotWizard(project).showAndGet() | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun guessPathsOnFirstOpen(project: Project) { | ||
RunOnceUtil.runOnceForProject(project, "Guess UTBot paths in settings") { | ||
project.settings.predictPaths() | ||
} | ||
} | ||
} | ||
} |
7 changes: 3 additions & 4 deletions
7
...-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/AskServerToGenerateBuildDir.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
package org.utbot.cpp.clion.plugin.actions | ||
|
||
import com.intellij.openapi.actionSystem.AnAction | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import org.utbot.cpp.clion.plugin.UTBot | ||
import org.utbot.cpp.clion.plugin.client.requests.CreateBuildDirRequest | ||
|
||
class AskServerToGenerateBuildDir : AnAction(UTBot.message("projectConfigure.generate.buildDir")) { | ||
class AskServerToGenerateBuildDir : UTBotBaseAction(UTBot.message("projectConfigure.generate.buildDir")) { | ||
|
||
override fun actionPerformed(e: AnActionEvent) = CreateBuildDirRequest(e).executeUsingCurrentClient() | ||
override fun actionPerformed(e: AnActionEvent) = CreateBuildDirRequest(e).execute() | ||
|
||
override fun update(e: AnActionEvent) { | ||
override fun updateIfEnabled(e: AnActionEvent) { | ||
e.presentation.isEnabledAndVisible = e.project != null | ||
} | ||
} |
7 changes: 3 additions & 4 deletions
7
...tlin/org/utbot/cpp/clion/plugin/actions/AskServerToGenerateJsonForProjectConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
package org.utbot.cpp.clion.plugin.actions | ||
|
||
import com.intellij.openapi.actionSystem.AnAction | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import org.utbot.cpp.clion.plugin.UTBot | ||
import org.utbot.cpp.clion.plugin.client.requests.GenerateJsonFilesRequest | ||
|
||
class AskServerToGenerateJsonForProjectConfiguration : AnAction(UTBot.message("projectConfigure.generate.json")) { | ||
class AskServerToGenerateJsonForProjectConfiguration : UTBotBaseAction(UTBot.message("projectConfigure.generate.json")) { | ||
|
||
override fun actionPerformed(e: AnActionEvent) = GenerateJsonFilesRequest(e).executeUsingCurrentClient() | ||
override fun actionPerformed(e: AnActionEvent) = GenerateJsonFilesRequest(e).execute() | ||
|
||
override fun update(e: AnActionEvent) { | ||
override fun updateIfEnabled(e: AnActionEvent) { | ||
e.presentation.isEnabledAndVisible = e.project != null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 4 additions & 5 deletions
9
clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/ReconnectAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
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 | ||
import org.utbot.cpp.clion.plugin.client.ManagedClient | ||
|
||
class ReconnectAction: AnAction(UTBot.message("actions.reconnect")) { | ||
class ReconnectAction : UTBotBaseAction(UTBot.message("actions.reconnect")) { | ||
override fun actionPerformed(e: AnActionEvent) { | ||
e.project!!.service<ClientManager>().restartClient() | ||
e.project!!.service<ManagedClient>().restartClient() | ||
} | ||
|
||
override fun update(e: AnActionEvent) { | ||
override fun updateIfEnabled(e: AnActionEvent) { | ||
e.presentation.isEnabledAndVisible = e.project != null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/ShowWizardAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
package org.utbot.cpp.clion.plugin.actions | ||
|
||
import com.intellij.openapi.actionSystem.AnAction | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import org.utbot.cpp.clion.plugin.UTBot | ||
import org.utbot.cpp.clion.plugin.ui.wizard.UTBotWizard | ||
import org.utbot.cpp.clion.plugin.utils.activeProject | ||
|
||
class ShowWizardAction: AnAction(UTBot.message("wizard.show")) { | ||
class ShowWizardAction: UTBotBaseAction(UTBot.message("wizard.show")) { | ||
|
||
override fun actionPerformed(e: AnActionEvent) { | ||
UTBotWizard(e.activeProject()).showAndGet() | ||
} | ||
|
||
override fun update(e: AnActionEvent) { | ||
override fun updateIfEnabled(e: AnActionEvent) { | ||
e.presentation.isEnabled = e.project != null | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/TogglePluginAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.utbot.cpp.clion.plugin.actions | ||
|
||
import com.intellij.openapi.actionSystem.ActionPlaces | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.actionSystem.ToggleAction | ||
import com.intellij.openapi.project.Project | ||
import org.utbot.cpp.clion.plugin.UTBot | ||
import org.utbot.cpp.clion.plugin.settings.settings | ||
|
||
class TogglePluginAction : ToggleAction() { | ||
override fun isSelected(e: AnActionEvent): Boolean { | ||
val project = e.project ?: return false | ||
updateActionText(e, project) | ||
return project.settings.storedSettings.isPluginEnabled | ||
} | ||
|
||
override fun setSelected(e: AnActionEvent, pluginEnabled: Boolean) { | ||
val project = e.project ?: return | ||
val previousValue = project.settings.storedSettings.isPluginEnabled | ||
project.settings.storedSettings.isPluginEnabled = pluginEnabled | ||
updateActionText(e, project) | ||
if (previousValue != pluginEnabled) | ||
project.settings.fireUTBotEnabledStateChanged() | ||
} | ||
|
||
private fun updateActionText(e: AnActionEvent, project: Project) { | ||
val isPluginEnabled = project.settings.storedSettings.isPluginEnabled | ||
var newText = if (isPluginEnabled) UTBot.message("actions.enable.enabled") | ||
else UTBot.message("actions.enable.disabled") | ||
if (ActionPlaces.isPopupPlace(e.place)) { | ||
newText = if (isPluginEnabled) | ||
UTBot.message("actions.enable.menu.enabled") | ||
else UTBot.message("actions.enable.menu.disabled") | ||
} | ||
e.presentation.text = newText | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/UTBotBaseAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.utbot.cpp.clion.plugin.actions | ||
|
||
import com.intellij.openapi.actionSystem.AnAction | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import javax.swing.Icon | ||
import org.utbot.cpp.clion.plugin.utils.isPluginEnabled | ||
|
||
abstract class UTBotBaseAction( | ||
text: () -> String? = { null }, | ||
description: () -> String? = { null }, | ||
icon: Icon? = null | ||
) : AnAction(text, description, icon) { | ||
constructor(text: String) : this({ text }) | ||
|
||
override fun update(e: AnActionEvent) { | ||
if (isPluginEnabled(e)) { | ||
updateIfEnabled(e) | ||
} else { | ||
e.presentation.isEnabledAndVisible = false | ||
} | ||
} | ||
|
||
abstract fun updateIfEnabled(e: AnActionEvent) | ||
} |
23 changes: 23 additions & 0 deletions
23
clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/UTBotBaseToggleAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.utbot.cpp.clion.plugin.actions | ||
|
||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.actionSystem.ToggleAction | ||
import javax.swing.Icon | ||
import org.utbot.cpp.clion.plugin.utils.isPluginEnabled | ||
|
||
abstract class UTBotBaseToggleAction( | ||
text: () -> String? = { null }, | ||
description: () -> String? = { null }, | ||
icon: Icon? = null | ||
): ToggleAction(text, description, icon) { | ||
override fun update(e: AnActionEvent) { | ||
super.update(e) | ||
if (isPluginEnabled(e)) { | ||
updateIfEnabled(e) | ||
} else { | ||
e.presentation.isEnabledAndVisible = false | ||
} | ||
} | ||
|
||
abstract fun updateIfEnabled(e: AnActionEvent) | ||
} |
8 changes: 4 additions & 4 deletions
8
...in/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/configure/ConfigureProjectAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
package org.utbot.cpp.clion.plugin.actions.configure | ||
|
||
import com.intellij.openapi.actionSystem.AnAction | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import org.utbot.cpp.clion.plugin.UTBot | ||
import org.utbot.cpp.clion.plugin.actions.UTBotBaseAction | ||
import org.utbot.cpp.clion.plugin.client.requests.CheckProjectConfigurationRequest | ||
import org.utbot.cpp.clion.plugin.utils.activeProject | ||
|
||
class ConfigureProjectAction : AnAction(UTBot.message("projectConfigure.configure")) { | ||
class ConfigureProjectAction : UTBotBaseAction(UTBot.message("projectConfigure.configure")) { | ||
|
||
override fun actionPerformed(e: AnActionEvent) = CheckProjectConfigurationRequest(e.activeProject()).executeUsingCurrentClient() | ||
override fun actionPerformed(e: AnActionEvent) = CheckProjectConfigurationRequest(e.activeProject()).execute() | ||
|
||
override fun update(e: AnActionEvent) { | ||
override fun updateIfEnabled(e: AnActionEvent) { | ||
e.presentation.isEnabledAndVisible = e.project != null | ||
} | ||
} |
10 changes: 5 additions & 5 deletions
10
.../src/main/kotlin/org/utbot/cpp/clion/plugin/actions/configure/ReconfigureProjectAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
package org.utbot.cpp.clion.plugin.actions.configure | ||
|
||
import com.intellij.openapi.actionSystem.AnAction | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import org.utbot.cpp.clion.plugin.UTBot | ||
import org.utbot.cpp.clion.plugin.actions.UTBotBaseAction | ||
import org.utbot.cpp.clion.plugin.grpc.getProjectConfigGrpcRequest | ||
import org.utbot.cpp.clion.plugin.client.requests.CheckProjectConfigurationRequest | ||
import org.utbot.cpp.clion.plugin.utils.activeProject | ||
import testsgen.Testgen | ||
|
||
class ReconfigureProjectAction: AnAction(UTBot.message("projectConfigure.reconfigure")) { | ||
class ReconfigureProjectAction: UTBotBaseAction(UTBot.message("projectConfigure.reconfigure")) { | ||
|
||
override fun actionPerformed(e: AnActionEvent) { | ||
val project = e.activeProject() | ||
CheckProjectConfigurationRequest( | ||
getProjectConfigGrpcRequest(project, Testgen.ConfigMode.ALL), | ||
project, | ||
).executeUsingCurrentClient() | ||
).execute() | ||
} | ||
|
||
override fun update(e: AnActionEvent) { | ||
override fun updateIfEnabled(e: AnActionEvent) { | ||
e.presentation.isEnabledAndVisible = e.project != null | ||
} | ||
} | ||
} |
10 changes: 5 additions & 5 deletions
10
...in/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/generate/BaseGenerateTestsAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.