use of org.eclipse.lsp4j.debug.SourceBreakpoint in project magik-tools by StevenLooman.
the class BreakpointManager method addBreakpoint.
/**
* Add a new breakpoint to self and debugger.
*
* @param source Source.
* @param sourceBreakpoint Source breakpoint.
* @return New magik breakpoint.
* @throws IOException -
* @throws ExecutionException -
* @throws InterruptedException -
*/
MagikBreakpoint addBreakpoint(final Source source, final SourceBreakpoint sourceBreakpoint) throws IOException, InterruptedException, ExecutionException {
int line = sourceBreakpoint.getLine();
final AstNode methodNode = this.getNode(source, line);
final MethodDefinitionNodeHelper helper = new MethodDefinitionNodeHelper(methodNode);
String method = null;
int methodLine = 0;
if (methodNode == null) {
method = "<not_in_method>";
} else {
method = helper.getPakkageExemplarMethodName();
methodLine = methodNode.getTokenLine();
if (methodLine == line) {
line = 0;
}
}
String condition = sourceBreakpoint.getCondition();
return this.createBreakpoint(source, method, line, condition);
}
use of org.eclipse.lsp4j.debug.SourceBreakpoint in project magik-tools by StevenLooman.
the class BreakpointManager method setBreakpoints.
/**
* Set breakpoints in source.
*
* @param source Source for breakpoints.
* @param newSourceBreakpoints Breakpoints.
* @return Current breakpoints.
* @throws IOException -
* @throws ExecutionException -
* @throws InterruptedException -
*/
public List<MagikBreakpoint> setBreakpoints(final Source source, final SourceBreakpoint[] newSourceBreakpoints) throws IOException, InterruptedException, ExecutionException {
// Get all current breakpoints.
final List<MagikBreakpoint> breakpoints = this.sourceBreakpoints.computeIfAbsent(source, key -> new ArrayList<>());
// Add new breakpoints.
final List<Integer> magikBreakpointLines = breakpoints.stream().map(MagikBreakpoint::getMethodLine).collect(Collectors.toList());
final List<SourceBreakpoint> addedBreakpoints = Arrays.stream(newSourceBreakpoints).filter(breakpoint -> !magikBreakpointLines.contains(breakpoint.getLine())).collect(Collectors.toList());
for (final SourceBreakpoint sourceBreakpoint : addedBreakpoints) {
this.addBreakpoint(source, sourceBreakpoint);
}
// Remove old breakpoints.
final List<Integer> sourceBreakpointLines = Arrays.stream(newSourceBreakpoints).map(SourceBreakpoint::getLine).collect(Collectors.toList());
final List<MagikBreakpoint> removedBreakpoints = breakpoints.stream().filter(magikBreakpoint -> !sourceBreakpointLines.contains(magikBreakpoint.getMethodLine())).collect(Collectors.toList());
for (final MagikBreakpoint magikBreakpoint : removedBreakpoints) {
this.removeBreakpoint(source, magikBreakpoint);
}
// breakpoints gets updated through addBreakpoint/removeBreakpoint.
return breakpoints;
}
use of org.eclipse.lsp4j.debug.SourceBreakpoint in project magik-tools by StevenLooman.
the class MagikDebugAdapter method setBreakpoints.
@Override
public CompletableFuture<SetBreakpointsResponse> setBreakpoints(final SetBreakpointsArguments args) {
LOGGER.trace("setBreakpoints");
return CompletableFuture.supplyAsync(() -> {
final Source source = args.getSource();
// Do some manual fixing if needed.
if (source.getName() == null && source.getPath() != null) {
final Path path = Path.of(source.getPath());
final String name = path.getFileName().toString();
source.setName(name);
}
try {
final SourceBreakpoint[] sourceBreakpoints = args.getBreakpoints();
final List<MagikBreakpoint> magikBreakpoints = this.breakpointManager.setBreakpoints(source, sourceBreakpoints);
// Return response.
final SetBreakpointsResponse response = new SetBreakpointsResponse();
final Breakpoint[] breakpoints = Lsp4jConversion.toLsp4j(source, magikBreakpoints);
response.setBreakpoints(breakpoints);
return response;
} catch (InterruptedException exception) {
java.lang.Thread.currentThread().interrupt();
throw new CompletionException(exception.getMessage(), exception);
} catch (IOException | ExecutionException exception) {
throw new CompletionException(exception.getMessage(), exception);
}
});
}
use of org.eclipse.lsp4j.debug.SourceBreakpoint in project magik-tools by StevenLooman.
the class BreakpointManagerTest method testAddBreakpoint.
@Test
void testAddBreakpoint() throws IOException, InterruptedException, ExecutionException {
final TestSlapProtocol slapProtocol = new TestSlapProtocol();
final BreakpointManager manager = new BreakpointManager(slapProtocol, null);
final SourceBreakpoint sourceBreakpoint = new SourceBreakpoint();
sourceBreakpoint.setLine(17);
final Source source = new Source();
source.setPath(getPath("magik-debug-adapter/src/test/resources/bpt.magik").toString());
final BreakpointManager.MagikBreakpoint breakpoint = manager.addBreakpoint(source, sourceBreakpoint);
assertThat(breakpoint.getMethodName()).isEqualTo("user:bpt.t()");
assertThat(breakpoint.getMethodLine()).isZero();
assertThat(breakpoint.getCondition()).isNull();
assertThat(breakpoint.getBreakpointId()).isNotEqualTo(ISlapProtocol.INVALID_BREAKPOINT_ID);
}
use of org.eclipse.lsp4j.debug.SourceBreakpoint in project magik-tools by StevenLooman.
the class BreakpointManagerTest method testAddBreakpointInvalidLine.
@Test
void testAddBreakpointInvalidLine() throws IOException, InterruptedException, ExecutionException {
final TestSlapProtocol slapProtocol = new TestSlapProtocol() {
@Override
public CompletableFuture<ISlapResponse> setBreakpoint(String method, int line) {
ErrorResponse errorResponse = new ErrorResponse(RequestType.BREAKPOINT_SET, ErrorMessage.INVALID_LINE_NUMBER);
SlapErrorException exception = new SlapErrorException(errorResponse);
CompletableFuture<ISlapResponse> future = new CompletableFuture<>();
future.completeExceptionally(exception);
return future;
}
};
final BreakpointManager manager = new BreakpointManager(slapProtocol, null);
final SourceBreakpoint sourceBreakpoint = new SourceBreakpoint();
sourceBreakpoint.setLine(18);
final Source source = new Source();
source.setPath(getPath("magik-debug-adapter/src/test/resources/bpt.magik").toString());
final BreakpointManager.MagikBreakpoint breakpoint = manager.addBreakpoint(source, sourceBreakpoint);
assertThat(breakpoint.getMethodName()).isEqualTo("user:bpt.t()");
assertThat(breakpoint.getMethodLine()).isEqualTo(18);
assertThat(breakpoint.getCondition()).isNull();
assertThat(breakpoint.getMessage()).isEqualTo("INVALID_LINE_NUMBER");
assertThat(breakpoint.getBreakpointId()).isEqualTo(ISlapProtocol.INVALID_BREAKPOINT_ID);
}
Aggregations