Skip to content

Commit

Permalink
fix code lens scope for error hotspot
Browse files Browse the repository at this point in the history
  • Loading branch information
shalom938 committed Nov 14, 2024
1 parent 7ae572c commit 6d52916
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private synchronized Set<CodeLens> 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);

Expand All @@ -219,7 +219,7 @@ private synchronized Set<CodeLens> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6d52916

Please sign in to comment.