Search in sources :

Example 16 with Breakpoint

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);
}
Also used : Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint) FunctionSteps(org.rstudio.studio.client.common.debugging.model.FunctionSteps) ArrayList(java.util.ArrayList) Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint)

Example 17 with Breakpoint

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);
    }
}
Also used : Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint) FunctionSteps(org.rstudio.studio.client.common.debugging.model.FunctionSteps) JsArray(com.google.gwt.core.client.JsArray) ServerError(org.rstudio.studio.client.server.ServerError) ArrayList(java.util.ArrayList) Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint)

Example 18 with Breakpoint

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_;
        }
    };
}
Also used : JsObject(org.rstudio.core.client.js.JsObject) Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint) BreakpointsSavedEvent(org.rstudio.studio.client.common.debugging.events.BreakpointsSavedEvent) JSObjectStateValue(org.rstudio.studio.client.workbench.model.helper.JSObjectStateValue) BreakpointState(org.rstudio.studio.client.common.debugging.model.BreakpointState) Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint)

Example 19 with Breakpoint

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();
}
Also used : Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint)

Example 20 with Breakpoint

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;
}
Also used : Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint) ServerError(org.rstudio.studio.client.server.ServerError) FunctionState(org.rstudio.studio.client.common.debugging.model.FunctionState)

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