From 6d5291611e87e23c4bcd2224603ca30626c85391 Mon Sep 17 00:00:00 2001 From: Shalom Ben Zvi Kazaz Date: Thu, 14 Nov 2024 17:59:58 +0200 Subject: [PATCH] fix code lens scope for error hotspot --- .../plugin/document/CodeLensProvider.java | 4 ++-- .../plugin/notifications/NotificationUtil.java | 8 ++++++++ .../intellij/plugin/codelens/CodeLensService.kt | 16 +++++++++++----- .../digma/intellij/plugin/model/lens/CodeLens.kt | 2 +- .../plugin/model/rest/codelens/Decorator.kt | 16 +++++++++++++++- .../main/kotlin/rider/model/CodeObjectsModel.kt | 1 + .../plugin/rider/protocol/CodeLensHost.kt | 1 + 7 files changed, 39 insertions(+), 9 deletions(-) diff --git a/ide-common/src/main/java/org/digma/intellij/plugin/document/CodeLensProvider.java b/ide-common/src/main/java/org/digma/intellij/plugin/document/CodeLensProvider.java index a513aee40..b1ef76d72 100644 --- a/ide-common/src/main/java/org/digma/intellij/plugin/document/CodeLensProvider.java +++ b/ide-common/src/main/java/org/digma/intellij/plugin/document/CodeLensProvider.java @@ -205,7 +205,7 @@ private synchronized Set buildCodeLens(@NotNull DocumentInfoContainer String title = priorityEmoji + decorator.getTitle(); //title is used as id of CodeLens - CodeLens codeLens = new CodeLens(decorator.getTitle(), codeObjectId, decorator.getCodeObjectId(), title, importance); + CodeLens codeLens = new CodeLens(decorator.getTitle(), codeObjectId, decorator.getScopeCodeObjectId(), title, importance); codeLens.setLensDescription(decorator.getDescription()); codeLens.setLensMoreText("Go to " + title); @@ -219,7 +219,7 @@ private synchronized Set buildCodeLens(@NotNull DocumentInfoContainer private static CodeLens buildCodeLensOfActive(String methodId, Decorator liveDecorator) { var title = Unicodes.getLIVE_CIRCLE(); - CodeLens codeLens = new CodeLens(liveDecorator.getTitle(), methodId, liveDecorator.getCodeObjectId(), title, 1); + CodeLens codeLens = new CodeLens(liveDecorator.getTitle(), methodId, liveDecorator.getScopeCodeObjectId(), title, 1); codeLens.setLensDescription(liveDecorator.getDescription()); return codeLens; diff --git a/ide-common/src/main/java/org/digma/intellij/plugin/notifications/NotificationUtil.java b/ide-common/src/main/java/org/digma/intellij/plugin/notifications/NotificationUtil.java index 7a4945378..822afafd9 100644 --- a/ide-common/src/main/java/org/digma/intellij/plugin/notifications/NotificationUtil.java +++ b/ide-common/src/main/java/org/digma/intellij/plugin/notifications/NotificationUtil.java @@ -33,6 +33,14 @@ public static void notifyFadingError(Project project, String content) { .notify(project); } + public static void notifyFadingInfo(Project project, String content) { + + NotificationGroupManager.getInstance() + .getNotificationGroup(DIGMA_FADING_BALLOON_NOTIFICATION_GROUP) + .createNotification(content, NotificationType.INFORMATION) + .notify(project); + } + public static void notifyChangingEnvironment(Project project, String oldEnv,String newEnv) { var content = "Digma: Changing environment " + oldEnv + " to " + newEnv; diff --git a/ide-common/src/main/kotlin/org/digma/intellij/plugin/codelens/CodeLensService.kt b/ide-common/src/main/kotlin/org/digma/intellij/plugin/codelens/CodeLensService.kt index 6321e0304..8669c3366 100644 --- a/ide-common/src/main/kotlin/org/digma/intellij/plugin/codelens/CodeLensService.kt +++ b/ide-common/src/main/kotlin/org/digma/intellij/plugin/codelens/CodeLensService.kt @@ -23,6 +23,7 @@ import org.digma.intellij.plugin.document.CodeLensUtils.psiFileToKey import org.digma.intellij.plugin.errorreporting.ErrorReporter import org.digma.intellij.plugin.log.Log import org.digma.intellij.plugin.model.lens.CodeLens +import org.digma.intellij.plugin.notifications.NotificationUtil import org.digma.intellij.plugin.posthog.ActivityMonitor import org.digma.intellij.plugin.psi.LanguageService import org.digma.intellij.plugin.scope.ScopeContext @@ -222,12 +223,17 @@ class CodeLensService(private val project: Project) : Disposable { selectedEditor?.caretModel?.moveToOffset(it.textOffset) } } - Backgroundable.ensurePooledThreadWithoutReadAccess { - val contextPayload = objectToJsonNode(ChangeScopeMessagePayload(lens)) - val scopeContext = ScopeContext("IDE/CODE_LENS_CLICKED", contextPayload) - ScopeManager.getInstance(project).changeScope(SpanScope(lens.scopeCodeObjectId), scopeContext, null) - } + val scopeCodeObjectId = lens.scopeCodeObjectId + if (scopeCodeObjectId == null){ + NotificationUtil.notifyFadingInfo(project,"No asset found for method: ${lens.codeMethod}") + }else{ + Backgroundable.ensurePooledThreadWithoutReadAccess { + val contextPayload = objectToJsonNode(ChangeScopeMessagePayload(lens)) + val scopeContext = ScopeContext("IDE/CODE_LENS_CLICKED", contextPayload) + ScopeManager.getInstance(project).changeScope(SpanScope(scopeCodeObjectId), scopeContext, null) + } + } } catch (e: Exception) { Log.warnWithException(logger, project, e, "error in ClickHandler {}", e) ErrorReporter.getInstance().reportError(project, "${this::class.simpleName}.ClickHandler.invoke", e) diff --git a/model/src/main/kotlin/org/digma/intellij/plugin/model/lens/CodeLens.kt b/model/src/main/kotlin/org/digma/intellij/plugin/model/lens/CodeLens.kt index 1dd9fd55d..11e90ef1f 100644 --- a/model/src/main/kotlin/org/digma/intellij/plugin/model/lens/CodeLens.kt +++ b/model/src/main/kotlin/org/digma/intellij/plugin/model/lens/CodeLens.kt @@ -6,7 +6,7 @@ import java.util.Objects data class CodeLens( val id: String, val codeMethod: String, //method this code lens should appear on - val scopeCodeObjectId: String, + val scopeCodeObjectId: String?, val lensTitle: String, val importance: Int, ) { diff --git a/model/src/main/kotlin/org/digma/intellij/plugin/model/rest/codelens/Decorator.kt b/model/src/main/kotlin/org/digma/intellij/plugin/model/rest/codelens/Decorator.kt index ef6f70ae6..08bd23764 100644 --- a/model/src/main/kotlin/org/digma/intellij/plugin/model/rest/codelens/Decorator.kt +++ b/model/src/main/kotlin/org/digma/intellij/plugin/model/rest/codelens/Decorator.kt @@ -1,6 +1,7 @@ package org.digma.intellij.plugin.model.rest.codelens import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonIgnoreProperties import org.digma.intellij.plugin.model.rest.insights.InsightImportance import java.beans.ConstructorProperties @@ -12,11 +13,24 @@ data class Decorator "title", "description", "codeObjectId", + "spanCodeObjectId", "importance" ) constructor( val title: String, val description: String, val codeObjectId: String, + val spanCodeObjectId: String?, val importance: InsightImportance -) +) { + @JsonIgnore + fun getScopeCodeObjectId(): String? { + return if (codeObjectId.startsWith("span:")) { + codeObjectId + } else if (spanCodeObjectId != null && spanCodeObjectId.startsWith("span:")) { + spanCodeObjectId + } else { + null + } + } +} diff --git a/rider/protocol/src/main/kotlin/rider/model/CodeObjectsModel.kt b/rider/protocol/src/main/kotlin/rider/model/CodeObjectsModel.kt index 223eaabbf..adb88a412 100644 --- a/rider/protocol/src/main/kotlin/rider/model/CodeObjectsModel.kt +++ b/rider/protocol/src/main/kotlin/rider/model/CodeObjectsModel.kt @@ -52,6 +52,7 @@ object CodeObjectsModel : Ext(SolutionModel.Solution) { val RiderCodeLensInfo = structdef { field("id", PredefinedType.string) field("codeObjectId", PredefinedType.string) + field("scopeCodeObjectId", PredefinedType.string.nullable) field("lensTitle", PredefinedType.string.nullable) field("lensDescription", PredefinedType.string.nullable) field("moreText", PredefinedType.string.nullable) diff --git a/rider/src/main/kotlin/org/digma/intellij/plugin/rider/protocol/CodeLensHost.kt b/rider/src/main/kotlin/org/digma/intellij/plugin/rider/protocol/CodeLensHost.kt index f9851697d..decc29a5b 100644 --- a/rider/src/main/kotlin/org/digma/intellij/plugin/rider/protocol/CodeLensHost.kt +++ b/rider/src/main/kotlin/org/digma/intellij/plugin/rider/protocol/CodeLensHost.kt @@ -148,6 +148,7 @@ class CodeLensHost(project: Project) : LifetimedProjectComponent(project) { private fun CodeLens.toRiderCodeLensInfo(psiUri: String) = RiderCodeLensInfo( id = id, codeObjectId = codeMethod, + scopeCodeObjectId = scopeCodeObjectId, lensTitle = lensTitle, lensDescription = lensDescription, moreText = lensMoreText,