Skip to content

Commit 6dc83af

Browse files
committed
fix: avoid unnecessary remove request if instrument already finished
ref: sourceplusplus/sourceplusplus#470
1 parent ceaf640 commit 6dc83af

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

plugin/src/main/kotlin/spp/jetbrains/sourcemarker/command/status/ui/BreakpointStatusBar.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import spp.jetbrains.plugin.LiveStatusBarManager;
4343
import spp.jetbrains.sourcemarker.command.status.ui.config.LiveBreakpointConfigurationPanel;
4444
import spp.jetbrains.sourcemarker.command.util.ExpressionUtils;
45+
import spp.jetbrains.sourcemarker.instrument.InstrumentEventWindowService;
4546
import spp.jetbrains.state.LiveStateBar;
4647
import spp.protocol.instrument.LiveBreakpoint;
4748
import spp.protocol.instrument.LiveInstrument;
@@ -59,6 +60,7 @@
5960
import java.util.Collections;
6061
import java.util.HashMap;
6162
import java.util.List;
63+
import java.util.Objects;
6264
import java.util.concurrent.atomic.AtomicLong;
6365

6466
import static spp.jetbrains.PluginBundle.message;
@@ -332,13 +334,12 @@ public void dispose() {
332334
if (groupedMarks != null) groupedMarks.forEach(SourceMark::dispose);
333335

334336
if (liveBreakpoint != null) {
335-
UserData.liveInstrumentService(inlayMark.getProject()).removeLiveInstrument(liveBreakpoint.getId()).onComplete(it -> {
336-
if (it.succeeded()) {
337-
LiveStatusBarManager.getInstance(inlayMark.getProject()).removeActiveLiveInstrument(liveBreakpoint);
338-
} else {
339-
it.cause().printStackTrace();
340-
}
341-
});
337+
String instrumentId = Objects.requireNonNull(liveBreakpoint.getId());
338+
if (!InstrumentEventWindowService.getInstance(inlayMark.getProject()).isFinished(instrumentId)) {
339+
UserData.liveInstrumentService(inlayMark.getProject()).removeLiveInstrument(instrumentId)
340+
.onSuccess(it -> LiveStatusBarManager.getInstance(inlayMark.getProject()).removeActiveLiveInstrument(liveBreakpoint))
341+
.onFailure(Throwable::printStackTrace);
342+
}
342343
}
343344
}
344345

plugin/src/main/kotlin/spp/jetbrains/sourcemarker/command/status/ui/LogStatusBar.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import spp.jetbrains.sourcemarker.command.status.ui.config.LiveLogConfigurationPanel;
3939
import spp.jetbrains.sourcemarker.command.util.AutocompleteField;
4040
import spp.jetbrains.sourcemarker.command.util.AutocompleteFieldRow;
41+
import spp.jetbrains.sourcemarker.instrument.InstrumentEventWindowService;
4142
import spp.jetbrains.sourcemarker.instrument.log.VariableParser;
4243
import spp.jetbrains.state.LiveStateBar;
4344
import spp.protocol.artifact.log.Log;
@@ -67,6 +68,7 @@
6768
import java.util.Collections;
6869
import java.util.HashMap;
6970
import java.util.List;
71+
import java.util.Objects;
7072
import java.util.concurrent.atomic.AtomicLong;
7173
import java.util.function.Function;
7274
import java.util.regex.Matcher;
@@ -642,13 +644,12 @@ public void dispose() {
642644

643645
if (liveLog != null) {
644646
LiveStatusBarManager.getInstance(inlayMark.getProject()).removeLogData(inlayMark);
645-
UserData.liveInstrumentService(inlayMark.getProject()).removeLiveInstrument(liveLog.getId()).onComplete(it -> {
646-
if (it.succeeded()) {
647-
LiveStatusBarManager.getInstance(inlayMark.getProject()).removeActiveLiveInstrument(liveLog);
648-
} else {
649-
it.cause().printStackTrace();
650-
}
651-
});
647+
String instrumentId = Objects.requireNonNull(liveLog.getId());
648+
if (!InstrumentEventWindowService.getInstance(inlayMark.getProject()).isFinished(instrumentId)) {
649+
UserData.liveInstrumentService(inlayMark.getProject()).removeLiveInstrument(instrumentId)
650+
.onSuccess(it -> LiveStatusBarManager.getInstance(inlayMark.getProject()).removeActiveLiveInstrument(liveLog))
651+
.onFailure(Throwable::printStackTrace);
652+
}
652653
}
653654
inlayMark.dispose();
654655
}

plugin/src/main/kotlin/spp/jetbrains/sourcemarker/instrument/InstrumentEventWindowService.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class InstrumentEventWindowService(
5353
) : Disposable, ContentManagerListener {
5454

5555
companion object {
56+
@JvmStatic
5657
fun getInstance(project: Project): InstrumentEventWindowService {
5758
return project.getService(InstrumentEventWindowService::class.java)
5859
}
@@ -256,5 +257,9 @@ class InstrumentEventWindowService(
256257
}
257258
}
258259

260+
fun isFinished(id: String): Boolean {
261+
return overviewTab.model.items.find { it.instrumentId == id }?.isFinished ?: false
262+
}
263+
259264
override fun dispose() = Unit
260265
}

plugin/src/main/kotlin/spp/jetbrains/sourcemarker/instrument/InstrumentNavigationHandler.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ class InstrumentNavigationHandler(
5555
if (canRemove) {
5656
actions.add(object : AnAction("Remove Instrument") {
5757
override fun actionPerformed(e: AnActionEvent) {
58+
if (InstrumentEventWindowService.getInstance(gutterMark.project).isFinished(instrumentId)) {
59+
gutterMark.dispose()
60+
return
61+
}
62+
5863
UserData.liveInstrumentService(gutterMark.project)?.removeLiveInstrument(instrumentId)
59-
?.onSuccess {
60-
gutterMark.dispose()
61-
}?.onFailure {
62-
log.error("Failed to remove live instrument", it)
63-
}
64+
?.onSuccess { gutterMark.dispose() }
65+
?.onFailure { log.error("Failed to remove live instrument", it) }
6466
}
6567
})
6668
}

0 commit comments

Comments
 (0)