Skip to content

Commit b66300d

Browse files
committed
fix: changing breakpoint condition has no immediate effect
1 parent a5d4235 commit b66300d

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

org.eclipse.lsp4e.debug/src/org/eclipse/lsp4e/debug/debugmodel/DSPBreakpointManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ public void breakpointChanged(IBreakpoint breakpoint, @Nullable IMarkerDelta del
160160
private void addBreakpointToMap(IBreakpoint breakpoint) {
161161
Assert.isTrue(supportsBreakpoint(breakpoint) && breakpoint instanceof ILineBreakpoint);
162162
if (breakpoint instanceof ILineBreakpoint lineBreakpoint) {
163+
// Ensure we do not keep stale breakpoint entries for the same
164+
// location (line/column) when attributes such as conditions change.
165+
// This avoids sending multiple breakpoints for the same source
166+
// location to the debug adapter.
167+
deleteBreakpointFromMap(breakpoint);
168+
163169
IMarker marker = lineBreakpoint.getMarker();
164170
IResource resource = marker.getResource();
165171
IPath location = resource.getLocation();

org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/debug/BreakpointMappingTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,51 @@ void breakpoint_conditions_are_sent_to_server() throws Exception {
113113
manager.shutdown();
114114
}
115115
}
116+
117+
@Test
118+
void changing_breakpoint_condition_replaces_existing_entry() throws Exception {
119+
IFile file = TestUtils.createUniqueTestFile(project, "txt", "first line\nsecond line\n");
120+
121+
var bp = new DSPLineBreakpoint(file, 2);
122+
bp.setCondition("x > 0");
123+
created.add(bp);
124+
125+
var server = new CapturingServer();
126+
var manager = new DSPBreakpointManager(DebugPlugin.getDefault().getBreakpointManager(), server, null);
127+
128+
try {
129+
// Simulate initial registration of the breakpoint with the manager
130+
manager.initialize().join();
131+
manager.breakpointAdded(bp);
132+
133+
// Change the condition and simulate the platform reporting the change
134+
server.calls.clear();
135+
bp.setCondition("x > 1");
136+
manager.breakpointChanged(bp, null);
137+
138+
SetBreakpointsArguments matching = null;
139+
synchronized (server.calls) {
140+
assertTrue(!server.calls.isEmpty(),
141+
"No setBreakpoints() calls captured after breakpoint condition change");
142+
String path = file.getLocation().toOSString();
143+
for (SetBreakpointsArguments a : server.calls) {
144+
if (a.getSource() != null && path.equals(a.getSource().getPath())) {
145+
matching = a;
146+
break;
147+
}
148+
}
149+
}
150+
151+
assertNotNull(matching,
152+
"No setBreakpoints() call for our file was captured after breakpoint condition change");
153+
SourceBreakpoint[] sent = matching.getBreakpoints();
154+
assertNotNull(sent);
155+
assertEquals(1, sent.length, "Expected exactly one SourceBreakpoint after condition change");
156+
157+
SourceBreakpoint sb = sent[0];
158+
assertEquals("x > 1", sb.getCondition());
159+
} finally {
160+
manager.shutdown();
161+
}
162+
}
116163
}

0 commit comments

Comments
 (0)