use of org.rstudio.studio.client.common.debugging.model.Breakpoint in project rstudio by rstudio.
the class BreakpointManager method processFunctionSteps.
private void processFunctionSteps(ArrayList<Breakpoint> breakpoints, JsArray<FunctionSteps> stepList) {
ArrayList<Breakpoint> unSettableBreakpoints = new ArrayList<Breakpoint>();
// each breakpoint with its steps.
for (int i = 0; i < breakpoints.size() && i < stepList.length(); i++) {
FunctionSteps steps = stepList.get(i);
Breakpoint breakpoint = breakpoints.get(i);
if (steps.getSteps().length() > 0) {
// line; if there is, discard this one.
if (breakpoint.getLineNumber() != steps.getLineNumber()) {
for (Breakpoint possibleDupe : breakpoints_) {
if (breakpoint.getPath().equals(possibleDupe.getPath()) && steps.getLineNumber() == possibleDupe.getLineNumber() && breakpoint.getBreakpointId() != possibleDupe.getBreakpointId()) {
breakpoint.setState(Breakpoint.STATE_REMOVING);
unSettableBreakpoints.add(breakpoint);
}
}
}
breakpoint.addFunctionSteps(steps.getName(), steps.getLineNumber(), steps.getSteps());
} else {
unSettableBreakpoints.add(breakpoint);
}
}
discardUnsettableBreakpoints(unSettableBreakpoints);
}
use of org.rstudio.studio.client.common.debugging.model.Breakpoint in project rstudio by rstudio.
the class BreakpointManager method prepareAndSetFunctionBreakpoints.
private void prepareAndSetFunctionBreakpoints(final FileFunction function) {
// look over the list of breakpoints in this function and see if any are
// marked inactive, or if they need their steps refreshed (necessary
// when a function has had steps added or removed in the editor)
final ArrayList<Breakpoint> inactiveBreakpoints = new ArrayList<Breakpoint>();
int[] inactiveLines = new int[] {};
int numLines = 0;
for (Breakpoint breakpoint : breakpoints_) {
if (function.containsBreakpoint(breakpoint) && (breakpoint.getState() != Breakpoint.STATE_ACTIVE || breakpoint.needsUpdatedSteps())) {
inactiveBreakpoints.add(breakpoint);
inactiveLines[numLines++] = breakpoint.getLineNumber();
}
}
// corresponding steps from the function
if (inactiveBreakpoints.size() > 0) {
server_.getFunctionSteps(function.functionName, function.fileName, function.packageName, inactiveLines, new ServerRequestCallback<JsArray<FunctionSteps>>() {
@Override
public void onResponseReceived(JsArray<FunctionSteps> response) {
// ask the server to set the breakpoint
if (response.length() > 0) {
processFunctionSteps(inactiveBreakpoints, response);
setFunctionBreakpoints(function);
} else // no results: discard the breakpoints
{
discardUnsettableBreakpoints(inactiveBreakpoints);
}
}
@Override
public void onError(ServerError error) {
discardUnsettableBreakpoints(inactiveBreakpoints);
}
});
} else {
setFunctionBreakpoints(function);
}
}
use of org.rstudio.studio.client.common.debugging.model.Breakpoint in project rstudio by rstudio.
the class BreakpointManager method onSessionInit.
// Event handlers ----------------------------------------------------------
@Override
public void onSessionInit(SessionInitEvent sie) {
// Establish a persistent object for the breakpoints. Note that this
// object is read by the server on init, so the scope/name pair here
// needs to match the pair on the server.
new JSObjectStateValue("debug-breakpoints", "debugBreakpointsState", ClientState.PROJECT_PERSISTENT, session_.getSessionInfo().getClientState(), false) {
@Override
protected void onInit(JsObject value) {
if (value != null) {
BreakpointState state = value.cast();
// restore all of the breakpoints
JsArray<Breakpoint> breakpoints = state.getPersistedBreakpoints();
for (int idx = 0; idx < breakpoints.length(); idx++) {
Breakpoint breakpoint = breakpoints.get(idx);
// make sure the next breakpoint we create after a restore
// has a value larger than any existing breakpoint
currentBreakpointId_ = Math.max(currentBreakpointId_, breakpoint.getBreakpointId() + 1);
addBreakpoint(breakpoint);
}
// this initialization happens after the source windows are
// up, so fire an event to the editor to show all known
// breakpoints. as new source windows are opened, they will
// call getBreakpointsInFile to populate themselves.
events_.fireEvent(new BreakpointsSavedEvent(breakpoints_, true));
}
}
@Override
protected JsObject getValue() {
BreakpointState state = BreakpointState.create();
for (Breakpoint breakpoint : breakpoints_) {
state.addPersistedBreakpoint(breakpoint);
}
breakpointStateDirty_ = false;
return state.cast();
}
@Override
protected boolean hasChanged() {
return breakpointStateDirty_;
}
};
}
use of org.rstudio.studio.client.common.debugging.model.Breakpoint in project rstudio by rstudio.
the class BreakpointManager method removeBreakpoint.
public void removeBreakpoint(int breakpointId) {
Breakpoint breakpoint = getBreakpoint(breakpointId);
if (breakpoint != null) {
breakpoints_.remove(breakpoint);
if (breakpoint.getState() == Breakpoint.STATE_ACTIVE && breakpoint.getType() == Breakpoint.TYPE_FUNCTION) {
setFunctionBreakpoints(new FileFunction(breakpoint));
}
notifyServer(breakpoint, false, breakpoint.getType() == Breakpoint.TYPE_TOPLEVEL);
}
onBreakpointAddOrRemove();
}
use of org.rstudio.studio.client.common.debugging.model.Breakpoint in project rstudio by rstudio.
the class BreakpointManager method setBreakpoint.
public Breakpoint setBreakpoint(final String path, final String functionName, int lineNumber, final boolean immediately) {
// create the new breakpoint and arguments for the server call
final Breakpoint breakpoint = addBreakpoint(Breakpoint.create(currentBreakpointId_++, path, functionName, lineNumber, immediately ? Breakpoint.STATE_PROCESSING : Breakpoint.STATE_INACTIVE, Breakpoint.TYPE_FUNCTION));
notifyServer(breakpoint, true, false);
// expectations. Process it when the function is no longer executing.
if (activeFunctions_.contains(new FileFunction(breakpoint))) {
breakpoint.setPendingDebugCompletion(true);
markInactiveBreakpoint(breakpoint);
} else {
server_.getFunctionState(functionName, path, lineNumber, new ServerRequestCallback<FunctionState>() {
@Override
public void onResponseReceived(FunctionState state) {
if (state.isPackageFunction()) {
breakpoint.markAsPackageBreakpoint(state.getPackageName());
}
// stop processing now
if (!immediately)
return;
// the breakpoint now
if (state.getSyncState()) {
prepareAndSetFunctionBreakpoints(new FileFunction(breakpoint));
} else // otherwise, save an inactive breakpoint--we'll revisit the
// marker the next time the file is sourced or the package is
// rebuilt
{
markInactiveBreakpoint(breakpoint);
}
}
@Override
public void onError(ServerError error) {
// if we can't figure out whether the function is in sync,
// leave it inactive for now
markInactiveBreakpoint(breakpoint);
}
});
}
breakpointStateDirty_ = true;
return breakpoint;
}
Aggregations