[debugger] fix breakpoint merging, IJPL-155742

null highlight range is a common case and line should be considered then

^IJPL-155742 fixed

GitOrigin-RevId: 83ac2527515131f28664fddc76dddaf5ba2e2b13
This commit is contained in:
Vladimir Parfinenko
2024-06-05 10:07:57 +02:00
committed by intellij-monorepo-bot
parent 5523dffc58
commit 23af003173
2 changed files with 20 additions and 18 deletions

View File

@@ -340,14 +340,10 @@ public final class XLineBreakpointImpl<P extends XBreakpointProperties> extends
return false;
}
int getOffset() {
return myHighlighter != null && myHighlighter.isValid() ? myHighlighter.getStartOffset() : -1;
}
public void updatePosition() {
if (myHighlighter != null && myHighlighter.isValid()) {
mySourcePosition = null; // reset the source position even if the line number has not changed, as the offset may be cached inside
setLine(myHighlighter.getDocument().getLineNumber(getOffset()), false);
setLine(myHighlighter.getDocument().getLineNumber(myHighlighter.getStartOffset()), false);
}
}

View File

@@ -48,9 +48,7 @@ import com.intellij.xdebugger.XDebuggerUtil
import com.intellij.xdebugger.breakpoints.XBreakpoint
import com.intellij.xdebugger.breakpoints.XLineBreakpoint
import com.intellij.xdebugger.impl.breakpoints.InlineBreakpointInlayManager.Companion.getInstance
import it.unimi.dsi.fastutil.ints.IntOpenHashSet
import java.awt.event.MouseEvent
import java.util.function.Consumer
class XLineBreakpointManager(private val myProject: Project) {
private val myBreakpoints = MultiMap.createConcurrent<String, XLineBreakpointImpl<*>>()
@@ -88,19 +86,27 @@ class XLineBreakpointManager(private val myProject: Project) {
return
}
breakpoints.forEach { it.updatePosition() }
// Check if two or more breakpoints occurred at the same position and remove duplicates.
val (valid, invalid) = breakpoints.partition { it.isValid }
removeBreakpoints(invalid)
val areInlineBreakpoints = XDebuggerUtil.areInlineBreakpointsEnabled(FileDocumentManager.getInstance().getFile(document))
val positions = IntOpenHashSet()
val toRemove = mutableListOf<XLineBreakpoint<*>>()
for (breakpoint in breakpoints) {
breakpoint.updatePosition()
val position = if (areInlineBreakpoints) breakpoint.offset else breakpoint.line
if (!breakpoint.isValid || !positions.add(position)) {
toRemove.add(breakpoint)
val duplicates = valid
.groupBy { b ->
if (areInlineBreakpoints) {
// We cannot show multiple breakpoints of the same type at the same position.
// Note that highlightRange might be null, so we still have to add line as an identity element.
Triple(b.type, b.line, b.highlightRange?.startOffset)
} else {
// We cannot show multiple breakpoints of any type at the same line.
b.line
}
}
}
removeBreakpoints(toRemove)
.values
.filter { it.size > 1 }
.flatMap { it.drop(1) }
removeBreakpoints(duplicates)
}
private fun removeBreakpoints(toRemove: Collection<XLineBreakpoint<*>>?) {