Skip to content

Commit d0e8c6c

Browse files
committed
fix: support multiple marks with same instrument/subscription id
1 parent e0641f2 commit d0e8c6c

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

marker/src/main/kotlin/spp/jetbrains/marker/SourceMarker.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,14 @@ class SourceMarker(private val project: Project) {
189189
return getSourceMarks().filterIsInstance<GuideMark>()
190190
}
191191

192-
fun findByInstrumentId(instrumentId: String): SourceMark? {
193-
return getSourceMarks().firstOrNull {
192+
fun findByInstrumentId(instrumentId: String): List<SourceMark> {
193+
return getSourceMarks().filter {
194194
it.getUserData(SourceMarkerKeys.INSTRUMENT_ID) == instrumentId
195195
}
196196
}
197197

198-
fun findBySubscriptionId(subscriptionId: String): SourceMark? {
199-
return getSourceMarks().firstOrNull {
198+
fun findBySubscriptionId(subscriptionId: String): List<SourceMark> {
199+
return getSourceMarks().filter {
200200
it.getUserData(SourceMarkerKeys.VIEW_SUBSCRIPTION_ID) == subscriptionId
201201
}
202202
}

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

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -186,44 +186,40 @@ class LiveInstrumentEventListener(
186186
activeInstruments.remove(event.instrument)
187187
InstrumentEventWindowService.getInstance(project).addInstrumentEvent(event)
188188

189-
val inlayMark = SourceMarker.getInstance(project).findByInstrumentId(event.instrument.id!!)
190-
if (inlayMark != null) {
191-
if (inlayMark is GutterMark) {
189+
SourceMarker.getInstance(project).findByInstrumentId(event.instrument.id!!).forEach {
190+
if (it is GutterMark) {
192191
if (event.instrument.meta["created_by"] != UserData.selfInfo(project)?.developer?.id) {
193192
//just remove foreign instrument icons
194-
inlayMark.dispose()
193+
it.dispose()
195194
} else if (event.instrument !is LiveBreakpoint) {
196195
//just remove non-breakpoint icons
197-
inlayMark.dispose()
196+
it.dispose()
198197
} else {
199198
if (event.cause == null) {
200-
inlayMark.configuration.icon = PluginIcons.Breakpoint.complete
199+
it.configuration.icon = PluginIcons.Breakpoint.complete
201200
} else {
202-
inlayMark.configuration.icon = PluginIcons.Breakpoint.error
201+
it.configuration.icon = PluginIcons.Breakpoint.error
203202
}
204-
inlayMark.sourceFileMarker.refresh()
203+
it.sourceFileMarker.refresh()
205204
}
206205
}
207206

208-
val eventListeners = inlayMark.getUserData(SourceMarkerKeys.INSTRUMENT_EVENT_LISTENERS)
209-
if (eventListeners?.isNotEmpty() == true) {
210-
eventListeners.forEach { it.onInstrumentRemovedEvent(event) }
211-
}
207+
it.getUserData(SourceMarkerKeys.INSTRUMENT_EVENT_LISTENERS)
208+
?.forEach { it.onInstrumentRemovedEvent(event) }
212209
}
213210
}
214211
}
215212

216-
override fun onInstrumentHitEvent(event: LiveInstrumentHit) {
217-
ApplicationManager.getApplication().invokeLater {
218-
InstrumentEventWindowService.getInstance(project).addInstrumentEvent(event)
213+
override fun onInstrumentHitEvent(event: LiveInstrumentHit) = ApplicationManager.getApplication().invokeLater {
214+
InstrumentEventWindowService.getInstance(project).addInstrumentEvent(event)
219215

220-
if (event is LiveBreakpointHit) {
221-
SourceMarker.getInstance(project).findByInstrumentId(event.instrument.id!!)
222-
?.getUserData(SourceMarkerKeys.INSTRUMENT_EVENT_LISTENERS)
223-
?.forEach { it.onBreakpointHitEvent(event) }
224-
} else if (event is LiveLogHit) {
225-
SourceMarker.getInstance(project).findByInstrumentId(event.instrument.id!!)
226-
?.getUserData(SourceMarkerKeys.INSTRUMENT_EVENT_LISTENERS)?.forEach { it.onLogHitEvent(event) }
216+
if (event is LiveBreakpointHit) {
217+
SourceMarker.getInstance(project).findByInstrumentId(event.instrument.id!!).forEach {
218+
it.getUserData(SourceMarkerKeys.INSTRUMENT_EVENT_LISTENERS)?.forEach { it.onBreakpointHitEvent(event) }
219+
}
220+
} else if (event is LiveLogHit) {
221+
SourceMarker.getInstance(project).findByInstrumentId(event.instrument.id!!).forEach {
222+
it.getUserData(SourceMarkerKeys.INSTRUMENT_EVENT_LISTENERS)?.forEach { it.onLogHitEvent(event) }
227223
}
228224
}
229225
}

plugin/src/main/kotlin/spp/jetbrains/sourcemarker/view/LiveViewEventListener.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ class LiveViewEventListener(
5151
if (log.isTraceEnabled) log.trace("Received live event: $event")
5252

5353
//todo: remove in favor of sending events to individual subscribers
54-
SourceMarker.getInstance(project).findBySubscriptionId(event.subscriptionId)
55-
?.getUserData(SourceMarkerKeys.VIEW_EVENT_LISTENERS)?.forEach { it.accept(event) }
54+
SourceMarker.getInstance(project).findBySubscriptionId(event.subscriptionId).forEach {
55+
it.getUserData(SourceMarkerKeys.VIEW_EVENT_LISTENERS)?.forEach { it.accept(event) }
56+
}
5657

5758
vertx.eventBus().publish(toLiveViewSubscription(event.subscriptionId), it.body())
5859
}

0 commit comments

Comments
 (0)