Skip to content

Commit

Permalink
protocol commands
Browse files Browse the repository at this point in the history
  • Loading branch information
shalom938 committed Sep 25, 2024
1 parent 073b22f commit 916a204
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,26 @@ const val DIGMA_COMMAND = "digma"
const val DIGMA_PLUGIN_TARGET = "plugin"


//jetbrains://idea/digma/plugin?action=assets
//jetbrains://idea/digma/plugin?project=spring-petclinic&action=assets
/*
show digma settings
"jetbrains://idea/settings?name=Digma Plugin"
show code object id not encoded
"jetbrains://idea/digma/plugin?action=showAsset&codeObjectId=span:io.opentelemetry.tomcat-10.0$_$HTTP GET /owners/{ownerId}&environmentId=LOCAL#ID#42E6067A-E755-4211-BA0F-B2F84BA8B065"
show code object id encoded
"jetbrains://idea/digma/plugin?action=showAsset&codeObjectId=span%3Aio.opentelemetry.tomcat-10.0%24_%24HTTP%20GET%20%2Fowners%2F%7BownerId%7D&environmentId=LOCAL%23ID%2342E6067A-E755-4211-BA0F-B2F84BA8B065"
*/

class DigmaProtocolCommand : JBProtocolCommand(DIGMA_COMMAND) {
private val logger: Logger = Logger.getInstance(this::class.java)

// override fun perform(target: String?, parameters: Map<String, String>, fragment: String?): Future<String?> {
override suspend fun execute(target: String?, parameters: Map<String, String>, fragment: String?): String? {
try {
return executeImpl(target,parameters,fragment)
}catch (e:Throwable){
ErrorReporter.getInstance().reportError("DigmaProtocolCommand.execute",e)
return executeImpl(target, parameters, fragment)
} catch (e: Throwable) {
ErrorReporter.getInstance().reportError("DigmaProtocolCommand.execute", e)
return "Error $e"
}
}
Expand All @@ -42,7 +50,6 @@ class DigmaProtocolCommand : JBProtocolCommand(DIGMA_COMMAND) {
private suspend fun executeImpl(target: String?, parameters: Map<String, String>, fragment: String?): String? {

if (target != DIGMA_PLUGIN_TARGET) {
// return CompletableFuture.completedFuture("DigmaProtocolCommand Supports Only Plugin Target")
return "DigmaProtocolCommand Supports Only Plugin Target"
}

Expand All @@ -59,7 +66,6 @@ class DigmaProtocolCommand : JBProtocolCommand(DIGMA_COMMAND) {
var project = if (parameters.containsKey(PROJECT_NAME_KEY)) {
when (val openProjectResult = openProject(parameters)) {
is ProtocolOpenProjectResult.Success -> openProjectResult.project
// is ProtocolOpenProjectResult.Error -> return CompletableFuture.completedFuture(openProjectResult.message)
is ProtocolOpenProjectResult.Error -> return openProjectResult.message
}
} else {
Expand All @@ -71,6 +77,7 @@ class DigmaProtocolCommand : JBProtocolCommand(DIGMA_COMMAND) {
RecentProjectListActionProvider.getInstance().getActions().asSequence().filterIsInstance(ReopenProjectAction::class.java)
.firstOrNull()?.projectPath ?: RecentProjectsManager.getInstance().lastProjectCreationLocation
if (recentProjectPath != null) {
@Suppress("UnstableApiUsage")
project = RecentProjectsManagerBase.getInstanceEx().openProject(Path.of(recentProjectPath), OpenProjectTask())
}
}
Expand All @@ -81,7 +88,6 @@ class DigmaProtocolCommand : JBProtocolCommand(DIGMA_COMMAND) {
Log.log(logger::trace, "got project {}", project.name)

val action = getActionFromParameters(parameters)
// ?: return CompletableFuture.completedFuture("DigmaProtocolCommand no action in request")
?: return "DigmaProtocolCommand no action in request"


Expand All @@ -98,16 +104,11 @@ class DigmaProtocolCommand : JBProtocolCommand(DIGMA_COMMAND) {
Log.log(logger::trace, "executing action {}", action)
val result = project.service<DigmaProtocolApi>().performAction(project, parameters, waitForJcef)
Log.log(logger::trace, "after execute action {}", action)
// return CompletableFuture.completedFuture(null)
return result
}

// return CompletableFuture.completedFuture("DigmaProtocolCommand can not find project")
return "DigmaProtocolCommand can not open any project"

}

// override suspend fun execute(target: String?, parameters: Map<String, String>, fragment: String?): String? {
// return super.execute(target, parameters, fragment)
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.intellij.util.messages.Topic
* this is an application event that should fire when we change the api client,
* usually when user changes the api url in settings.
*/
//todo: maybe we don't need it
fun interface ProtocolCommandEvent {


Expand Down

0 comments on commit 916a204

Please sign in to comment.