Skip to content

Commit c7066c9

Browse files
committed
Update ui
2 parents b5fca10 + dfb6a87 commit c7066c9

File tree

25 files changed

+395
-78
lines changed

25 files changed

+395
-78
lines changed

common-build-logic/src/main/kotlin/common/BuildProfile.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ object BuildProfiles {
190190

191191
isEAP = true,
192192
profile = Profile.p242,
193-
platformVersion = "242.19533-EAP-CANDIDATE-SNAPSHOT",
194-
riderVersion = "2024.2-EAP5-SNAPSHOT",
193+
platformVersion = "242.19890-EAP-CANDIDATE-SNAPSHOT",
194+
riderVersion = "2024.2-EAP6-SNAPSHOT",
195195
pycharmVersion = "242-EAP-SNAPSHOT",
196196
riderTargetFramework = "net8.0",
197197
riderResharperVersionConstant = "PROFILE_2023_2",

ide-common/src/main/java/org/digma/intellij/plugin/analytics/Environment.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ public Env findById(@NotNull String envId) {
187187
}
188188

189189
private Optional<Env> find(@Nullable String envIdToFind) {
190+
if (envIdToFind == null) {
191+
return Optional.empty();
192+
}
190193
return environments.stream().filter(env -> env.getId().equals(envIdToFind)).findFirst();
191194
}
192195

@@ -223,7 +226,7 @@ private void notifyEnvironmentsListChange() {
223226
}
224227

225228

226-
private void notifyEnvironmentChanged(Env oldEnv, Env newEnv) {
229+
private void notifyEnvironmentChanged(@Nullable Env oldEnv, @Nullable Env newEnv) {
227230
if (project.isDisposed()) {
228231
return;
229232
}

ide-common/src/main/java/org/digma/intellij/plugin/analytics/EnvironmentChangeHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.digma.intellij.plugin.log.Log;
1111
import org.digma.intellij.plugin.model.rest.environment.Env;
1212
import org.digma.intellij.plugin.psi.*;
13+
import org.jetbrains.annotations.Nullable;
1314

1415
import java.util.List;
1516

@@ -30,7 +31,7 @@ public EnvironmentChangeHandler(Project project) {
3031
//environmentChanged must run in a background thread.
3132
//when fired by the Environment object it is on background
3233
@Override
33-
public void environmentChanged(Env newEnv) {
34+
public void environmentChanged(@Nullable Env newEnv) {
3435

3536
try {
3637

ide-common/src/main/java/org/digma/intellij/plugin/analytics/EnvironmentChanged.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.intellij.util.messages.Topic;
44
import org.digma.intellij.plugin.model.rest.environment.Env;
5+
import org.jetbrains.annotations.Nullable;
56

67
import java.util.List;
78

@@ -10,7 +11,7 @@ public interface EnvironmentChanged {
1011
@com.intellij.util.messages.Topic.ProjectLevel
1112
Topic<EnvironmentChanged> ENVIRONMENT_CHANGED_TOPIC = Topic.create("ENVIRONMENT_CHANGED_TOPIC", EnvironmentChanged.class);
1213

13-
void environmentChanged(Env newEnv);
14+
void environmentChanged(@Nullable Env newEnv);
1415

1516
void environmentsListChanged(List<Env> newEnvironments);
1617

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.digma.intellij.plugin.common.Backgroundable;
77
import org.digma.intellij.plugin.errorreporting.ErrorReporter;
88
import org.digma.intellij.plugin.model.rest.environment.Env;
9+
import org.jetbrains.annotations.Nullable;
910

1011
import java.util.List;
1112

@@ -32,7 +33,7 @@ public void documentInfoChanged(PsiFile psiFile) {
3233
}
3334

3435
@Override
35-
public void environmentChanged(Env newEnv) {
36+
public void environmentChanged(@Nullable Env newEnv) {
3637
Backgroundable.executeOnPooledThread(() -> {
3738
try {
3839
var changedPsiFiles = CodeLensProvider.getInstance(project).refresh();

ide-common/src/main/java/org/digma/intellij/plugin/psi/LanguageService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ default String detectMethodBySpan(@NotNull Project project, String spanCodeObjec
394394
/**
395395
* let language services do something on environmentChanged. for example to update the current method context.
396396
*/
397-
default void environmentChanged(Env newEnv) {
397+
default void environmentChanged(@Nullable Env newEnv) {
398398
//nothing to do , implement for specific languages if necessary
399399
}
400400

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ class FrequencyDetector(cacheExpirationTime: java.time.Duration) {
1818
val occurrences = counter.incrementAndGet()
1919
return occurrences > 1
2020
}
21-
22-
23-
24-
21+
fun isTooFrequentStackTrace(message: String, stacktrace: String): Boolean {
22+
val hash = stacktrace.hashCode()
23+
val counter = myCache.getOrCreate(message, hash.toString())
24+
val occurrences = counter.incrementAndGet()
25+
return occurrences > 1
26+
}
2527
fun isTooFrequentError(message: String, action: String): Boolean {
2628
val counter = myCache.getOrCreate(message, action)
2729
val occurrences = counter.incrementAndGet()

ide-common/src/main/kotlin/org/digma/intellij/plugin/errorreporting/ErrorReporter.kt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,34 @@ open class ErrorReporter {
116116
)
117117
}
118118

119+
private fun isTooFrequent(message: String, stackTrace: String?): Boolean {
120+
if (!stackTrace.isNullOrEmpty()) {
121+
return frequencyDetector.isTooFrequentStackTrace(message, stackTrace)
122+
}
123+
return frequencyDetector.isTooFrequentError(message, "")
124+
}
125+
126+
open fun reportError(message: String, stackTrace: String?, details: Map<String, Any>, project: Project?, useFrequencyDetector: Boolean = true) {
127+
if (message.isNullOrEmpty() && stackTrace.isNullOrEmpty()) {
128+
reportError(
129+
project, "At least one of the following properties must be set: [message] or [stackTrace].", "reportError",
130+
mapOf(
131+
SEVERITY_PROP_NAME to SEVERITY_HIGH_TRY_FIX
132+
)
133+
)
134+
return
135+
}
136+
if (useFrequencyDetector && isTooFrequent(message, stackTrace)) {
137+
return
138+
}
139+
val projectToUse = project ?: findActiveProject()
140+
141+
projectToUse?.let {
142+
if (it.isDisposed) return
143+
ActivityMonitor.getInstance(it).registerError(null, message, details)
144+
}
145+
}
146+
119147
//this method is used to report an error that is not an exception. it should contain some details to say what the error is
120148
open fun reportError(project: Project?, message: String, action: String, details: Map<String, String>) {
121149

@@ -178,7 +206,6 @@ open class ErrorReporter {
178206
}
179207

180208

181-
182209
open fun reportAnalyticsServiceError(
183210
project: Project,
184211
message: String,

ide-common/src/main/kotlin/org/digma/intellij/plugin/posthog/ActivityMonitor.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ class ActivityMonitor(private val project: Project) : Disposable {
128128
}
129129

130130

131-
132-
133131
override fun dispose() {
134132
//nothing to do, used as parent disposable
135133
}
@@ -315,7 +313,7 @@ class ActivityMonitor(private val project: Project) : Disposable {
315313
}
316314

317315

318-
fun registerError(exception: Throwable?, message: String, extraDetails: Map<String, String> = mapOf()) {
316+
fun registerError(exception: Throwable?, message: String, extraDetails: Map<String, Any> = mapOf()) {
319317

320318
try {
321319
val osType = System.getProperty("os.name")
@@ -327,7 +325,7 @@ class ActivityMonitor(private val project: Project) : Disposable {
327325

328326
//Don't call directly, use ErrorReporter.reportError
329327

330-
val details = mutableMapOf(
328+
val details = mutableMapOf<String, Any>(
331329
"error.source" to "plugin",
332330
"action" to "unknown",
333331
"message" to message,
@@ -644,8 +642,6 @@ class ActivityMonitor(private val project: Project) : Disposable {
644642
}
645643

646644

647-
648-
649645
//todo: remove at some point
650646
fun registerFirstTimePluginLoaded() {
651647
postHog?.capture(userId, "plugin first-loaded")
@@ -822,7 +818,6 @@ class ActivityMonitor(private val project: Project) : Disposable {
822818
}
823819

824820

825-
826821
private fun registerSessionDetails() {
827822

828823
SessionMetadataProperties.getInstance().put(CURRENT_INSTALL_STATUS_KEY, InstallStatus.Active)
@@ -925,7 +920,6 @@ class ActivityMonitor(private val project: Project) : Disposable {
925920
}
926921

927922

928-
929923
fun registerJiraFieldCopied(eventName: String, details: Map<String, Any>) {
930924

931925
PersistenceService.getInstance().setJiraFieldCopiedTimestamp()
@@ -991,7 +985,7 @@ class ActivityMonitor(private val project: Project) : Disposable {
991985

992986
fun reportApiPerformanceIssue(details: MutableMap<String, Any>) {
993987
capture(
994-
"api-performance-issue",details
988+
"api-performance-issue", details
995989
)
996990
}
997991

ide-common/src/main/kotlin/org/digma/intellij/plugin/scope/CodeNavigationBuilder.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ private fun buildCodeLocationFromAssetNavigation(
5555
assetNavigation: AssetNavigationResponse,
5656
): CodeLocation {
5757

58-
val codeDetailsList = buildFromCodeLocation(project, assetNavigation.codeLocation)
58+
val codeDetailsList = assetNavigation.codeLocation?.let {
59+
buildFromCodeLocation(project, it)
60+
} ?: listOf()
61+
62+
5963
//if has code locations no need to continue
6064
if (codeDetailsList.isNotEmpty()) {
6165
return CodeLocation(codeDetailsList, listOf())

0 commit comments

Comments
 (0)