Search in sources :

Example 6 with ServerError

use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.

the class HelpStrategy method showDataHelp.

@SuppressWarnings("unused")
private void showDataHelp(final QualifiedName selectedItem, final CompletionPopupDisplay display) {
    ParsedInfo cachedHelp = cache_.get(selectedItem);
    if (cachedHelp != null) {
        doShowDataHelp(cachedHelp, display);
        return;
    }
    server_.getHelp(selectedItem.name, selectedItem.source, selectedItem.type, new ServerRequestCallback<HelpInfo>() {

        @Override
        public void onError(ServerError error) {
            display.clearHelp(false);
        }

        @Override
        public void onResponseReceived(HelpInfo response) {
            if (response != null) {
                ParsedInfo info = response.parse(selectedItem.name);
                cache_.put(selectedItem, info);
                doShowDataHelp(info, display);
            } else {
                display.setHelpVisible(false);
                display.clearHelp(false);
            }
        }
    });
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) HelpInfo(org.rstudio.studio.client.workbench.views.help.model.HelpInfo) ParsedInfo(org.rstudio.studio.client.workbench.views.help.model.HelpInfo.ParsedInfo)

Example 7 with ServerError

use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.

the class HelpStrategy method showParameterHelp.

private void showParameterHelp(final QualifiedName selectedItem, final CompletionPopupDisplay display) {
    final String name = selectedItem.name.replaceAll("\\s*=\\s*$", "");
    ParsedInfo cachedHelp = cache_.get(selectedItem);
    if (cachedHelp != null) {
        doShowParameterHelp(cachedHelp, name, display);
        return;
    }
    if (selectedItem.helpHandler != null) {
        server_.getCustomParameterHelp(selectedItem.helpHandler, selectedItem.source, new ServerRequestCallback<HelpInfo.Custom>() {

            @Override
            public void onError(ServerError error) {
                display.clearHelp(false);
            }

            public void onResponseReceived(HelpInfo.Custom response) {
                if (response != null) {
                    HelpInfo.ParsedInfo info = response.toParsedInfo();
                    cache_.put(selectedItem, info);
                    doShowParameterHelp(info, name, display);
                } else {
                    display.setHelpVisible(false);
                    display.clearHelp(false);
                }
            }
        });
    } else {
        server_.getHelp(selectedItem.source, null, selectedItem.type, new ServerRequestCallback<HelpInfo>() {

            @Override
            public void onError(ServerError error) {
                display.clearHelp(false);
            }

            @Override
            public void onResponseReceived(HelpInfo response) {
                if (response != null) {
                    ParsedInfo info = response.parse(selectedItem.source);
                    cache_.put(selectedItem, info);
                    doShowParameterHelp(info, name, display);
                } else {
                    display.setHelpVisible(false);
                    display.clearHelp(false);
                }
            }
        });
    }
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) HelpInfo(org.rstudio.studio.client.workbench.views.help.model.HelpInfo) ParsedInfo(org.rstudio.studio.client.workbench.views.help.model.HelpInfo.ParsedInfo)

Example 8 with ServerError

use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.

the class RCompletionManager method goToFunctionDefinition.

public void goToFunctionDefinition() {
    // check for a file-local definition (intra-file navigation -- using
    // the active scope tree)
    AceEditor editor = (AceEditor) docDisplay_;
    if (editor != null) {
        TokenCursor cursor = editor.getSession().getMode().getRCodeModel().getTokenCursor();
        if (cursor.moveToPosition(editor.getCursorPosition(), true)) {
            // token (obstensibly a funciton name)
            if (cursor.isLeftBracket())
                cursor.moveToPreviousToken();
            // navigate (as this isn't the 'full' function name)
            if (cursor.moveToPreviousToken()) {
                if (cursor.isExtractionOperator())
                    return;
                cursor.moveToNextToken();
            }
            // if this is a string, try resolving that string as a file name
            if (cursor.hasType("string")) {
                String tokenValue = cursor.currentValue();
                String path = tokenValue.substring(1, tokenValue.length() - 1);
                FileSystemItem filePath = FileSystemItem.createFile(path);
                // This will show a dialog error if no such file exists; this
                // seems the most appropriate action in such a case.
                fileTypeRegistry_.editFile(filePath);
            }
            String functionName = cursor.currentValue();
            JsArray<ScopeFunction> scopes = editor.getAllFunctionScopes();
            for (int i = 0; i < scopes.length(); i++) {
                ScopeFunction scope = scopes.get(i);
                if (scope.getFunctionName().equals(functionName)) {
                    navigableSourceEditor_.navigateToPosition(SourcePosition.create(scope.getPreamble().getRow(), scope.getPreamble().getColumn()), true);
                    return;
                }
            }
        }
    }
    // intra-file navigation failed -- hit the server and find a definition
    // in the project index
    // determine current line and cursor position
    InputEditorLineWithCursorPosition lineWithPos = InputEditorUtil.getLineWithCursorPosition(input_);
    // delayed progress indicator
    final GlobalProgressDelayer progress = new GlobalProgressDelayer(globalDisplay_, 1000, "Searching for function definition...");
    server_.getObjectDefinition(lineWithPos.getLine(), lineWithPos.getPosition(), new ServerRequestCallback<ObjectDefinition>() {

        @Override
        public void onResponseReceived(ObjectDefinition def) {
            // dismiss progress
            progress.dismiss();
            // if we got a hit
            if (def.getObjectName() != null) {
                // search locally if a function navigator was provided
                if (navigableSourceEditor_ != null) {
                    // try to search for the function locally
                    SourcePosition position = navigableSourceEditor_.findFunctionPositionFromCursor(def.getObjectName());
                    if (position != null) {
                        navigableSourceEditor_.navigateToPosition(position, true);
                        // we're done
                        return;
                    }
                }
                // navigate to the file/loc
                if (def.getObjectType() == FileFunctionDefinition.OBJECT_TYPE) {
                    FileFunctionDefinition fileDef = def.getObjectData().cast();
                    fileTypeRegistry_.editFile(fileDef.getFile(), fileDef.getPosition());
                } else // search path definition
                if (def.getObjectType() == SearchPathFunctionDefinition.OBJECT_TYPE) {
                    SearchPathFunctionDefinition searchDef = def.getObjectData().cast();
                    eventBus_.fireEvent(new CodeBrowserNavigationEvent(searchDef));
                } else // finally, check to see if it's a data frame
                if (def.getObjectType() == DataDefinition.OBJECT_TYPE) {
                    eventBus_.fireEvent(new SendToConsoleEvent("View(" + def.getObjectName() + ")", true, false));
                }
            }
        }

        @Override
        public void onError(ServerError error) {
            progress.dismiss();
            globalDisplay_.showErrorMessage("Error Searching for Function", error.getUserMessage());
        }
    });
}
Also used : SearchPathFunctionDefinition(org.rstudio.studio.client.workbench.codesearch.model.SearchPathFunctionDefinition) InputEditorLineWithCursorPosition(org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorLineWithCursorPosition) ServerError(org.rstudio.studio.client.server.ServerError) GlobalProgressDelayer(org.rstudio.studio.client.common.GlobalProgressDelayer) AceEditor(org.rstudio.studio.client.workbench.views.source.editors.text.AceEditor) ObjectDefinition(org.rstudio.studio.client.workbench.codesearch.model.ObjectDefinition) ScopeFunction(org.rstudio.studio.client.workbench.views.source.editors.text.ScopeFunction) TokenCursor(org.rstudio.studio.client.workbench.views.source.editors.text.ace.TokenCursor) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) CodeBrowserNavigationEvent(org.rstudio.studio.client.workbench.views.source.events.CodeBrowserNavigationEvent) SourcePosition(org.rstudio.studio.client.workbench.views.source.model.SourcePosition) SendToConsoleEvent(org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent) FileFunctionDefinition(org.rstudio.studio.client.workbench.codesearch.model.FileFunctionDefinition)

Example 9 with ServerError

use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.

the class ShinyViewerTypePopupMenu method getDynamicPopupMenu.

@Override
public void getDynamicPopupMenu(final ToolbarPopupMenu.DynamicPopupMenuCallback callback) {
    final ToolbarPopupMenu menu = this;
    server_.getShinyViewerType(new ServerRequestCallback<ShinyViewerType>() {

        @Override
        public void onResponseReceived(ShinyViewerType response) {
            int viewerType = response.getViewerType();
            commands_.shinyRunInPane().setChecked(false);
            commands_.shinyRunInViewer().setChecked(false);
            commands_.shinyRunInBrowser().setChecked(false);
            if (ShinyViewerType.SHINY_VIEWER_PANE == viewerType)
                commands_.shinyRunInPane().setChecked(true);
            if (ShinyViewerType.SHINY_VIEWER_WINDOW == viewerType)
                commands_.shinyRunInViewer().setChecked(true);
            if (ShinyViewerType.SHINY_VIEWER_BROWSER == viewerType)
                commands_.shinyRunInBrowser().setChecked(true);
            callback.onPopupMenu(menu);
        }

        @Override
        public void onError(ServerError error) {
            callback.onPopupMenu(menu);
        }
    });
}
Also used : ShinyViewerType(org.rstudio.studio.client.shiny.model.ShinyViewerType) ToolbarPopupMenu(org.rstudio.core.client.widget.ToolbarPopupMenu) ServerError(org.rstudio.studio.client.server.ServerError)

Example 10 with ServerError

use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.

the class Workbench method onVersionControlShowRsaKey.

@Handler
public void onVersionControlShowRsaKey() {
    final ProgressIndicator indicator = new GlobalProgressDelayer(globalDisplay_, 500, "Reading RSA public key...").getIndicator();
    // compute path to public key
    String sshDir = session_.getSessionInfo().getDefaultSSHKeyDir();
    final String keyPath = FileSystemItem.createDir(sshDir).completePath("id_rsa.pub");
    // read it
    server_.gitSshPublicKey(keyPath, new ServerRequestCallback<String>() {

        @Override
        public void onResponseReceived(String publicKeyContents) {
            indicator.onCompleted();
            new ShowPublicKeyDialog("RSA Public Key", publicKeyContents).showModal();
        }

        @Override
        public void onError(ServerError error) {
            String msg = "Error attempting to read key '" + keyPath + "' (" + error.getUserMessage() + ")";
            indicator.onError(msg);
        }
    });
}
Also used : ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ShowPublicKeyDialog(org.rstudio.studio.client.common.vcs.ShowPublicKeyDialog) ServerError(org.rstudio.studio.client.server.ServerError) GlobalProgressDelayer(org.rstudio.studio.client.common.GlobalProgressDelayer) Handler(org.rstudio.core.client.command.Handler) VcsRefreshHandler(org.rstudio.studio.client.workbench.views.vcs.common.events.VcsRefreshHandler)

Aggregations

ServerError (org.rstudio.studio.client.server.ServerError)109 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)26 JsArrayString (com.google.gwt.core.client.JsArrayString)22 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)20 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)18 Void (org.rstudio.studio.client.server.Void)16 ArrayList (java.util.ArrayList)13 JsArray (com.google.gwt.core.client.JsArray)12 Command (com.google.gwt.user.client.Command)11 GlobalProgressDelayer (org.rstudio.studio.client.common.GlobalProgressDelayer)10 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)9 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)9 Operation (org.rstudio.core.client.widget.Operation)8 Handler (org.rstudio.core.client.command.Handler)7 TextEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)7 JSONString (com.google.gwt.json.client.JSONString)6 EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)6 CodeBrowserEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)6 DataEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget)6 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)6