Search in sources :

Example 1 with Breakpoint

use of org.rstudio.studio.client.common.debugging.model.Breakpoint in project rstudio by rstudio.

the class RemoteServer method updateBreakpoints.

@Override
public void updateBreakpoints(ArrayList<Breakpoint> breakpoints, boolean set, boolean arm, ServerRequestCallback<Void> requestCallback) {
    JSONArray bps = new JSONArray();
    for (int i = 0; i < breakpoints.size(); i++) {
        bps.set(i, new JSONObject(breakpoints.get(i)));
    }
    JSONArray params = new JSONArray();
    params.set(0, bps);
    params.set(1, JSONBoolean.getInstance(set));
    params.set(2, JSONBoolean.getInstance(arm));
    sendRequest(RPC_SCOPE, UPDATE_BREAKPOINTS, params, requestCallback);
}
Also used : JSONObject(com.google.gwt.json.client.JSONObject) JSONArray(com.google.gwt.json.client.JSONArray) Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint) Point(org.rstudio.studio.client.workbench.views.plots.model.Point)

Example 2 with Breakpoint

use of org.rstudio.studio.client.common.debugging.model.Breakpoint in project rstudio by rstudio.

the class AceEditorWidget method toggleBreakpointAtPosition.

private void toggleBreakpointAtPosition(Position pos) {
    // rows are 0-based, but debug line numbers are 1-based
    int lineNumber = lineFromRow(pos.getRow());
    int breakpointIdx = getBreakpointIdxByLine(lineNumber);
    // if there's already a breakpoint on that line, remove it
    if (breakpointIdx >= 0) {
        Breakpoint breakpoint = breakpoints_.get(breakpointIdx);
        removeBreakpointMarker(breakpoint);
        fireEvent(new BreakpointSetEvent(lineNumber, breakpoint.getBreakpointId(), false));
        breakpoints_.remove(breakpointIdx);
    } else // if there's no breakpoint on that line yet, create a new unset
    // breakpoint there (the breakpoint manager will pick up the new
    // breakpoint and attempt to set it on the server)
    {
        try {
            // non-whitespace, non-comment token
            if (editor_.getSession().getMode().getCodeModel() != null) {
                Position tokenPos = editor_.getSession().getMode().getCodeModel().findNextSignificantToken(pos);
                if (tokenPos != null) {
                    lineNumber = lineFromRow(tokenPos.getRow());
                    if (getBreakpointIdxByLine(lineNumber) >= 0) {
                        return;
                    }
                } else {
                    // set a breakpoint
                    return;
                }
            }
        } catch (Exception e) {
        // If we failed at any point to fast-forward to the next line with
        // a statement, we'll try to set a breakpoint on the line the user
        // originally clicked. 
        }
        fireEvent(new BreakpointSetEvent(lineNumber, BreakpointSetEvent.UNSET_BREAKPOINT_ID, true));
    }
}
Also used : Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint)

Example 3 with Breakpoint

use of org.rstudio.studio.client.common.debugging.model.Breakpoint in project rstudio by rstudio.

the class AceEditorWidget method updateBreakpoints.

private void updateBreakpoints(AceDocumentChangeEventNative changeEvent) {
    // if there are no breakpoints, don't do any work to move them about
    if (breakpoints_.size() == 0) {
        return;
    }
    // see if we need to move any breakpoints around in response to 
    // this change to the document's text
    String action = changeEvent.getAction();
    Range range = changeEvent.getRange();
    Position start = range.getStart();
    Position end = range.getEnd();
    // in a way that could change lines, we can't have moved anything
    if (start.getRow() == end.getRow() || (!action.equals("insertText") && !action.equals("insertLines") && !action.equals("removeText") && !action.equals("removeLines"))) {
        return;
    }
    int shiftedBy = 0;
    int shiftStartRow = 0;
    // compute how many rows to shift
    if (action == "insertText" || action == "insertLines") {
        shiftedBy = end.getRow() - start.getRow();
    } else {
        shiftedBy = start.getRow() - end.getRow();
    }
    // compute where to start shifting
    shiftStartRow = start.getRow() + ((action == "insertText" && start.getColumn() > 0) ? 1 : 0);
    // make a pass through the breakpoints and move them as appropriate:
    // remove all the breakpoints after the row where the change
    // happened, and add them back at their new position if they were
    // not part of a deleted range. 
    ArrayList<Breakpoint> movedBreakpoints = new ArrayList<Breakpoint>();
    for (int idx = 0; idx < breakpoints_.size(); idx++) {
        Breakpoint breakpoint = breakpoints_.get(idx);
        int breakpointRow = rowFromLine(breakpoint.getEditorLineNumber());
        if (breakpointRow >= shiftStartRow) {
            // remove the breakpoint from its old position
            movedBreakpoints.add(breakpoint);
            removeBreakpointMarker(breakpoint);
        }
    }
    for (Breakpoint breakpoint : movedBreakpoints) {
        // calculate the new position of the breakpoint
        int oldBreakpointPosition = rowFromLine(breakpoint.getEditorLineNumber());
        int newBreakpointPosition = oldBreakpointPosition + shiftedBy;
        // breakpoint there
        if (oldBreakpointPosition >= end.getRow() && !(oldBreakpointPosition == end.getRow() && shiftedBy < 0) && getBreakpointIdxByLine(lineFromRow(newBreakpointPosition)) < 0) {
            breakpoint.moveToLineNumber(lineFromRow(newBreakpointPosition));
            placeBreakpointMarker(breakpoint);
            fireEvent(new BreakpointMoveEvent(breakpoint.getBreakpointId()));
        } else {
            breakpoints_.remove(breakpoint);
            fireEvent(new BreakpointSetEvent(breakpoint.getEditorLineNumber(), breakpoint.getBreakpointId(), false));
        }
    }
}
Also used : Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) ArrayList(java.util.ArrayList) Range(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range) AnchoredRange(org.rstudio.studio.client.workbench.views.source.editors.text.ace.AnchoredRange) Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint)

Example 4 with Breakpoint

use of org.rstudio.studio.client.common.debugging.model.Breakpoint in project rstudio by rstudio.

the class TextEditingTarget method updateBreakpointWarningBar.

private void updateBreakpointWarningBar() {
    // check to see if there are any inactive breakpoints in this file
    boolean hasInactiveBreakpoints = false;
    boolean hasDebugPendingBreakpoints = false;
    boolean hasPackagePendingBreakpoints = false;
    String pendingPackageName = "";
    ArrayList<Breakpoint> breakpoints = breakpointManager_.getBreakpointsInFile(getPath());
    for (Breakpoint breakpoint : breakpoints) {
        if (breakpoint.getState() == Breakpoint.STATE_INACTIVE) {
            if (breakpoint.isPendingDebugCompletion()) {
                hasDebugPendingBreakpoints = true;
            } else if (breakpoint.isPackageBreakpoint()) {
                hasPackagePendingBreakpoints = true;
                pendingPackageName = breakpoint.getPackageName();
            } else {
                hasInactiveBreakpoints = true;
            }
            break;
        }
    }
    boolean showWarning = hasDebugPendingBreakpoints || hasInactiveBreakpoints || hasPackagePendingBreakpoints;
    if (showWarning && !isBreakpointWarningVisible_) {
        String message = "";
        if (hasDebugPendingBreakpoints) {
            message = "Breakpoints will be activated when the file or " + "function is finished executing.";
        } else if (isPackageFile()) {
            message = "Breakpoints will be activated when the package is " + "built and reloaded.";
        } else if (hasPackagePendingBreakpoints) {
            message = "Breakpoints will be activated when an updated version " + "of the " + pendingPackageName + " package is loaded";
        } else {
            message = "Breakpoints will be activated when this file is " + "sourced.";
        }
        view_.showWarningBar(message);
        isBreakpointWarningVisible_ = true;
    } else if (!showWarning && isBreakpointWarningVisible_) {
        hideBreakpointWarningBar();
    }
}
Also used : Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 5 with Breakpoint

use of org.rstudio.studio.client.common.debugging.model.Breakpoint in project rstudio by rstudio.

the class AceEditorWidget method addOrUpdateBreakpoint.

public void addOrUpdateBreakpoint(Breakpoint breakpoint) {
    int idx = getBreakpointIdxById(breakpoint.getBreakpointId());
    if (idx >= 0) {
        removeBreakpointMarker(breakpoint);
        breakpoint.setEditorState(breakpoint.getState());
        breakpoint.setEditorLineNumber(breakpoint.getLineNumber());
    } else {
        breakpoints_.add(breakpoint);
    }
    placeBreakpointMarker(breakpoint);
}
Also used : Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint)

Aggregations

Breakpoint (org.rstudio.studio.client.common.debugging.model.Breakpoint)22 ArrayList (java.util.ArrayList)9 ServerError (org.rstudio.studio.client.server.ServerError)4 TreeSet (java.util.TreeSet)3 Void (org.rstudio.studio.client.server.Void)3 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)3 JsArrayString (com.google.gwt.core.client.JsArrayString)2 FunctionSteps (org.rstudio.studio.client.common.debugging.model.FunctionSteps)2 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)2 JsArray (com.google.gwt.core.client.JsArray)1 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)1 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 JSONArray (com.google.gwt.json.client.JSONArray)1 JSONObject (com.google.gwt.json.client.JSONObject)1 Timer (com.google.gwt.user.client.Timer)1 JsObject (org.rstudio.core.client.js.JsObject)1 BreakpointsSavedEvent (org.rstudio.studio.client.common.debugging.events.BreakpointsSavedEvent)1 BreakpointState (org.rstudio.studio.client.common.debugging.model.BreakpointState)1 FunctionState (org.rstudio.studio.client.common.debugging.model.FunctionState)1 RoxygenHelper (org.rstudio.studio.client.common.r.roxygen.RoxygenHelper)1