use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.
the class BreakpointManager method clearAllBreakpoints.
private void clearAllBreakpoints() {
Set<FileFunction> functions = new TreeSet<FileFunction>();
for (Breakpoint breakpoint : breakpoints_) {
breakpoint.setState(Breakpoint.STATE_REMOVING);
if (breakpoint.getType() == Breakpoint.TYPE_FUNCTION)
functions.add(new FileFunction(breakpoint));
}
// set previously
for (FileFunction function : functions) {
server_.setFunctionBreakpoints(function.functionName, function.fileName, function.packageName, new ArrayList<String>(), new ServerRequestCallback<Void>() {
@Override
public void onError(ServerError error) {
// There's a possibility here that the breakpoints were
// not successfully cleared, so we may be in a temporarily
// confusing state, but no error message will be less
// confusing.
}
});
}
server_.removeAllBreakpoints(new VoidServerRequestCallback());
notifyBreakpointsSaved(new ArrayList<Breakpoint>(breakpoints_), false);
breakpoints_.clear();
onBreakpointAddOrRemove();
}
use of org.rstudio.studio.client.server.ServerError 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.server.ServerError 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;
}
use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.
the class ProjectOpener method showOpenProjectDialog.
public void showOpenProjectDialog(FileSystemContext fsContext, ProjectsServerOperations server, String defaultLocation, int defaultType, boolean showNewSession, final ProgressOperationWithInput<OpenProjectParams> onCompleted) {
initialize();
// use the default dialog on desktop mode or single-session mode
FileDialogs dialogs = RStudioGinjector.INSTANCE.getFileDialogs();
if (Desktop.isDesktop() || !RStudioGinjector.INSTANCE.getSession().getSessionInfo().getMultiSession()) {
dialogs.openFile("Open Project", fsContext, FileSystemItem.createDir(defaultLocation), "R Projects (*.Rproj)", true, new ProgressOperationWithInput<FileSystemItem>() {
@Override
public void execute(FileSystemItem input, final ProgressIndicator indicator) {
final CommandWithArg<FileSystemItem> onProjectFileReady = new CommandWithArg<FileSystemItem>() {
@Override
public void execute(FileSystemItem item) {
onCompleted.execute(new OpenProjectParams(item, null, false), indicator);
}
};
// null return values here imply a cancellation
if (input == null)
return;
if (input.isDirectory()) {
final String rprojPath = input.completePath(input.getName() + ".Rproj");
final FileSystemItem rprojFile = FileSystemItem.createFile(rprojPath);
server_.createProjectFile(rprojFile.getPath(), new ServerRequestCallback<Boolean>() {
@Override
public void onResponseReceived(Boolean success) {
onProjectFileReady.execute(rprojFile);
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
onProjectFileReady.execute(rprojFile);
}
});
} else {
onProjectFileReady.execute(input);
}
}
});
} else {
// in multi-session mode, we have a special dialog for opening projects
WebFileDialogs webDialogs = (WebFileDialogs) dialogs;
webDialogs.openProject(fsContext, FileSystemItem.createDir(defaultLocation), defaultType, showNewSession, onCompleted);
}
}
use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.
the class NewPackagePage method validateAsync.
@Override
protected void validateAsync(final NewProjectResult input, final OperationWithInput<Boolean> onValidated) {
// validate package name first
String packageName = txtProjectName_.getText().trim();
if (!isPackageNameValid(packageName)) {
globalDisplay_.showMessage(MessageDialog.WARNING, "Error", "Invalid package name '" + packageName + "'. Package names " + "should start with a letter, and contain only letters and numbers.");
onValidated.execute(false);
return;
}
final FileSystemItem projFile = FileSystemItem.createFile(input.getProjectFile());
final FileSystemItem projDir = projFile.getParentPath();
server_.stat(projDir.getPath(), new ServerRequestCallback<FileSystemItem>() {
@Override
public void onResponseReceived(final FileSystemItem item) {
// no file at this path -- safe for use
if (!item.exists()) {
onValidated.execute(true);
return;
}
// if it was a file, bail
if (!item.isDirectory()) {
globalDisplay_.showMessage(MessageDialog.WARNING, "Error", "A file already exists at path '" + item.getPath() + "'");
onValidated.execute(false);
return;
}
// check if this directory is empty
server_.listFiles(item, false, new ServerRequestCallback<DirectoryListing>() {
@Override
public void onResponseReceived(DirectoryListing listing) {
boolean ok = true;
JsArray<FileSystemItem> children = listing.getFiles();
for (FileSystemItem child : JsUtil.asIterable(children)) {
boolean canIgnore = child.getExtension().equals(".Rproj") || child.getName().startsWith(".");
if (canIgnore)
continue;
ok = false;
break;
}
if (!ok) {
globalDisplay_.showMessage(MessageDialog.WARNING, "Error", "Directory '" + item.getPath() + "' already exists and is not empty.");
}
onValidated.execute(ok);
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
onValidated.execute(true);
}
});
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
onValidated.execute(true);
}
});
}
Aggregations