Skip to content

Commit fe2e450

Browse files
authored
Merge pull request #2600 from digma-ai/fix-code-lens-for-error-hotspot
fix code lens scope for error hotspot Closes #2541
2 parents 7ae572c + 6d52916 commit fe2e450

File tree

7 files changed

+39
-9
lines changed

7 files changed

+39
-9
lines changed

ide-common/src/main/java/org/digma/intellij/plugin/document/CodeLensProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private synchronized Set<CodeLens> buildCodeLens(@NotNull DocumentInfoContainer
205205
String title = priorityEmoji + decorator.getTitle();
206206

207207
//title is used as id of CodeLens
208-
CodeLens codeLens = new CodeLens(decorator.getTitle(), codeObjectId, decorator.getCodeObjectId(), title, importance);
208+
CodeLens codeLens = new CodeLens(decorator.getTitle(), codeObjectId, decorator.getScopeCodeObjectId(), title, importance);
209209
codeLens.setLensDescription(decorator.getDescription());
210210
codeLens.setLensMoreText("Go to " + title);
211211

@@ -219,7 +219,7 @@ private synchronized Set<CodeLens> buildCodeLens(@NotNull DocumentInfoContainer
219219

220220
private static CodeLens buildCodeLensOfActive(String methodId, Decorator liveDecorator) {
221221
var title = Unicodes.getLIVE_CIRCLE();
222-
CodeLens codeLens = new CodeLens(liveDecorator.getTitle(), methodId, liveDecorator.getCodeObjectId(), title, 1);
222+
CodeLens codeLens = new CodeLens(liveDecorator.getTitle(), methodId, liveDecorator.getScopeCodeObjectId(), title, 1);
223223
codeLens.setLensDescription(liveDecorator.getDescription());
224224

225225
return codeLens;

ide-common/src/main/java/org/digma/intellij/plugin/notifications/NotificationUtil.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ public static void notifyFadingError(Project project, String content) {
3333
.notify(project);
3434
}
3535

36+
public static void notifyFadingInfo(Project project, String content) {
37+
38+
NotificationGroupManager.getInstance()
39+
.getNotificationGroup(DIGMA_FADING_BALLOON_NOTIFICATION_GROUP)
40+
.createNotification(content, NotificationType.INFORMATION)
41+
.notify(project);
42+
}
43+
3644
public static void notifyChangingEnvironment(Project project, String oldEnv,String newEnv) {
3745

3846
var content = "Digma: Changing environment " + oldEnv + " to " + newEnv;

ide-common/src/main/kotlin/org/digma/intellij/plugin/codelens/CodeLensService.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.digma.intellij.plugin.document.CodeLensUtils.psiFileToKey
2323
import org.digma.intellij.plugin.errorreporting.ErrorReporter
2424
import org.digma.intellij.plugin.log.Log
2525
import org.digma.intellij.plugin.model.lens.CodeLens
26+
import org.digma.intellij.plugin.notifications.NotificationUtil
2627
import org.digma.intellij.plugin.posthog.ActivityMonitor
2728
import org.digma.intellij.plugin.psi.LanguageService
2829
import org.digma.intellij.plugin.scope.ScopeContext
@@ -222,12 +223,17 @@ class CodeLensService(private val project: Project) : Disposable {
222223
selectedEditor?.caretModel?.moveToOffset(it.textOffset)
223224
}
224225
}
225-
Backgroundable.ensurePooledThreadWithoutReadAccess {
226-
val contextPayload = objectToJsonNode(ChangeScopeMessagePayload(lens))
227-
val scopeContext = ScopeContext("IDE/CODE_LENS_CLICKED", contextPayload)
228-
ScopeManager.getInstance(project).changeScope(SpanScope(lens.scopeCodeObjectId), scopeContext, null)
229-
}
230226

227+
val scopeCodeObjectId = lens.scopeCodeObjectId
228+
if (scopeCodeObjectId == null){
229+
NotificationUtil.notifyFadingInfo(project,"No asset found for method: ${lens.codeMethod}")
230+
}else{
231+
Backgroundable.ensurePooledThreadWithoutReadAccess {
232+
val contextPayload = objectToJsonNode(ChangeScopeMessagePayload(lens))
233+
val scopeContext = ScopeContext("IDE/CODE_LENS_CLICKED", contextPayload)
234+
ScopeManager.getInstance(project).changeScope(SpanScope(scopeCodeObjectId), scopeContext, null)
235+
}
236+
}
231237
} catch (e: Exception) {
232238
Log.warnWithException(logger, project, e, "error in ClickHandler {}", e)
233239
ErrorReporter.getInstance().reportError(project, "${this::class.simpleName}.ClickHandler.invoke", e)

model/src/main/kotlin/org/digma/intellij/plugin/model/lens/CodeLens.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import java.util.Objects
66
data class CodeLens(
77
val id: String,
88
val codeMethod: String, //method this code lens should appear on
9-
val scopeCodeObjectId: String,
9+
val scopeCodeObjectId: String?,
1010
val lensTitle: String,
1111
val importance: Int,
1212
) {

model/src/main/kotlin/org/digma/intellij/plugin/model/rest/codelens/Decorator.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.digma.intellij.plugin.model.rest.codelens
22

33
import com.fasterxml.jackson.annotation.JsonCreator
4+
import com.fasterxml.jackson.annotation.JsonIgnore
45
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
56
import org.digma.intellij.plugin.model.rest.insights.InsightImportance
67
import java.beans.ConstructorProperties
@@ -12,11 +13,24 @@ data class Decorator
1213
"title",
1314
"description",
1415
"codeObjectId",
16+
"spanCodeObjectId",
1517
"importance"
1618
)
1719
constructor(
1820
val title: String,
1921
val description: String,
2022
val codeObjectId: String,
23+
val spanCodeObjectId: String?,
2124
val importance: InsightImportance
22-
)
25+
) {
26+
@JsonIgnore
27+
fun getScopeCodeObjectId(): String? {
28+
return if (codeObjectId.startsWith("span:")) {
29+
codeObjectId
30+
} else if (spanCodeObjectId != null && spanCodeObjectId.startsWith("span:")) {
31+
spanCodeObjectId
32+
} else {
33+
null
34+
}
35+
}
36+
}

rider/protocol/src/main/kotlin/rider/model/CodeObjectsModel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ object CodeObjectsModel : Ext(SolutionModel.Solution) {
5252
val RiderCodeLensInfo = structdef {
5353
field("id", PredefinedType.string)
5454
field("codeObjectId", PredefinedType.string)
55+
field("scopeCodeObjectId", PredefinedType.string.nullable)
5556
field("lensTitle", PredefinedType.string.nullable)
5657
field("lensDescription", PredefinedType.string.nullable)
5758
field("moreText", PredefinedType.string.nullable)

rider/src/main/kotlin/org/digma/intellij/plugin/rider/protocol/CodeLensHost.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class CodeLensHost(project: Project) : LifetimedProjectComponent(project) {
148148
private fun CodeLens.toRiderCodeLensInfo(psiUri: String) = RiderCodeLensInfo(
149149
id = id,
150150
codeObjectId = codeMethod,
151+
scopeCodeObjectId = scopeCodeObjectId,
151152
lensTitle = lensTitle,
152153
lensDescription = lensDescription,
153154
moreText = lensMoreText,

0 commit comments

Comments
 (0)