Search in sources :

Example 6 with JsArrayString

use of com.google.gwt.core.client.JsArrayString in project rstudio by rstudio.

the class PaneManager method swapConsolePane.

private void swapConsolePane(PaneConfig paneConfig, int consoleTargetIndex) {
    int consoleCurrentIndex = paneConfig.getConsoleIndex();
    if (consoleCurrentIndex != consoleTargetIndex) {
        JsArrayString panes = JsArrayUtil.copy(paneConfig.getPanes());
        panes.set(consoleCurrentIndex, panes.get(consoleTargetIndex));
        panes.set(consoleTargetIndex, "Console");
        uiPrefs_.paneConfig().setGlobalValue(PaneConfig.create(panes, paneConfig.getTabSet1(), paneConfig.getTabSet2(), paneConfig.getConsoleLeftOnTop(), paneConfig.getConsoleRightOnTop()));
        uiPrefs_.writeUIPrefs();
    }
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 7 with JsArrayString

use of com.google.gwt.core.client.JsArrayString in project rstudio by rstudio.

the class CompletionRequester method addFunctionArgumentCompletions.

private void addFunctionArgumentCompletions(String token, ArrayList<QualifiedName> completions) {
    AceEditor editor = (AceEditor) docDisplay_;
    if (editor != null) {
        Position cursorPosition = editor.getSession().getSelection().getCursor();
        CodeModel codeModel = editor.getSession().getMode().getRCodeModel();
        // Try to see if we can find a function name
        TokenCursor cursor = codeModel.getTokenCursor();
        // NOTE: This can fail if the document is empty
        if (!cursor.moveToPosition(cursorPosition))
            return;
        String tokenLower = token.toLowerCase();
        if (cursor.currentValue() == "(" || cursor.findOpeningBracket("(", false)) {
            if (cursor.moveToPreviousToken()) {
                // Check to see if this really is the name of a function
                JsArray<ScopeFunction> functionsInScope = codeModel.getAllFunctionScopes();
                String tokenName = cursor.currentValue();
                for (int i = 0; i < functionsInScope.length(); i++) {
                    ScopeFunction rFunction = functionsInScope.get(i);
                    String fnName = rFunction.getFunctionName();
                    if (tokenName == fnName) {
                        JsArrayString args = rFunction.getFunctionArgs();
                        for (int j = 0; j < args.length(); j++) {
                            String arg = args.get(j);
                            if (arg.toLowerCase().startsWith(tokenLower))
                                completions.add(new QualifiedName(args.get(j) + " = ", fnName, false, RCompletionType.CONTEXT));
                        }
                    }
                }
            }
        }
    }
}
Also used : TokenCursor(org.rstudio.studio.client.workbench.views.source.editors.text.ace.TokenCursor) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) CodeModel(org.rstudio.studio.client.workbench.views.source.editors.text.ace.CodeModel) AceEditor(org.rstudio.studio.client.workbench.views.source.editors.text.AceEditor) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) ScopeFunction(org.rstudio.studio.client.workbench.views.source.editors.text.ScopeFunction)

Example 8 with JsArrayString

use of com.google.gwt.core.client.JsArrayString in project rstudio by rstudio.

the class CompletionRequester method getCompletions.

public void getCompletions(final String token, final List<String> assocData, final List<Integer> dataType, final List<Integer> numCommas, final String functionCallString, final String chainDataName, final JsArrayString chainAdditionalArgs, final JsArrayString chainExcludeArgs, final boolean chainExcludeArgsFromObject, final String filePath, final String documentId, final boolean implicit, final ServerRequestCallback<CompletionResult> callback) {
    boolean isHelp = dataType.size() > 0 && dataType.get(0) == AutocompletionContext.TYPE_HELP;
    if (usingCache(token, isHelp, callback))
        return;
    doGetCompletions(token, assocData, dataType, numCommas, functionCallString, chainDataName, chainAdditionalArgs, chainExcludeArgs, chainExcludeArgsFromObject, filePath, documentId, new ServerRequestCallback<Completions>() {

        @Override
        public void onError(ServerError error) {
            callback.onError(error);
        }

        @Override
        public void onResponseReceived(Completions response) {
            cachedLinePrefix_ = token;
            String token = response.getToken();
            JsArrayString comp = response.getCompletions();
            JsArrayString pkgs = response.getPackages();
            JsArrayBoolean quote = response.getQuote();
            JsArrayInteger type = response.getType();
            ArrayList<QualifiedName> newComp = new ArrayList<QualifiedName>();
            // Get function completions from the server
            for (int i = 0; i < comp.length(); i++) if (comp.get(i).endsWith(" = "))
                newComp.add(new QualifiedName(comp.get(i), pkgs.get(i), quote.get(i), type.get(i), response.getHelpHandler()));
            // Try getting our own function argument completions
            if (!response.getExcludeOtherCompletions()) {
                addFunctionArgumentCompletions(token, newComp);
                addScopedArgumentCompletions(token, newComp);
            }
            // Get variable completions from the current scope
            if (!response.getExcludeOtherCompletions()) {
                addScopedCompletions(token, newComp, "variable");
                addScopedCompletions(token, newComp, "function");
            }
            // Get other server completions
            for (int i = 0; i < comp.length(); i++) if (!comp.get(i).endsWith(" = "))
                newComp.add(new QualifiedName(comp.get(i), pkgs.get(i), quote.get(i), type.get(i), response.getHelpHandler()));
            // to properly ascertain this.
            if (isTopLevelCompletionRequest())
                addSnippetCompletions(token, newComp);
            // Remove duplicates
            newComp = resolveDuplicates(newComp);
            CompletionResult result = new CompletionResult(response.getToken(), newComp, response.getGuessedFunctionName(), response.getSuggestOnAccept(), response.getOverrideInsertParens());
            if (response.isCacheable()) {
                cachedCompletions_.put("", result);
            }
            callback.onResponseReceived(result);
        }
    });
}
Also used : RnwOptionCompletionResult(org.rstudio.studio.client.workbench.views.source.model.RnwChunkOptions.RnwOptionCompletionResult) ServerError(org.rstudio.studio.client.server.ServerError) JsArrayInteger(com.google.gwt.core.client.JsArrayInteger) ArrayList(java.util.ArrayList) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayBoolean(com.google.gwt.core.client.JsArrayBoolean) Completions(org.rstudio.studio.client.common.codetools.Completions)

Example 9 with JsArrayString

use of com.google.gwt.core.client.JsArrayString in project rstudio by rstudio.

the class CompletionRequester method addScopedArgumentCompletions.

private void addScopedArgumentCompletions(String token, ArrayList<QualifiedName> completions) {
    AceEditor editor = (AceEditor) docDisplay_;
    // NOTE: this will be null in the console, so protect against that
    if (editor != null) {
        Position cursorPosition = editor.getSession().getSelection().getCursor();
        CodeModel codeModel = editor.getSession().getMode().getRCodeModel();
        JsArray<RFunction> scopedFunctions = codeModel.getFunctionsInScope(cursorPosition);
        if (scopedFunctions.length() == 0)
            return;
        String tokenLower = token.toLowerCase();
        for (int i = 0; i < scopedFunctions.length(); i++) {
            RFunction scopedFunction = scopedFunctions.get(i);
            String functionName = scopedFunction.getFunctionName();
            JsArrayString argNames = scopedFunction.getFunctionArgs();
            for (int j = 0; j < argNames.length(); j++) {
                String argName = argNames.get(j);
                if (argName.toLowerCase().startsWith(tokenLower)) {
                    if (functionName == null || functionName == "") {
                        completions.add(new QualifiedName(argName, "<anonymous function>", false, RCompletionType.CONTEXT));
                    } else {
                        completions.add(new QualifiedName(argName, functionName, false, RCompletionType.CONTEXT));
                    }
                }
            }
        }
    }
}
Also used : Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) CodeModel(org.rstudio.studio.client.workbench.views.source.editors.text.ace.CodeModel) AceEditor(org.rstudio.studio.client.workbench.views.source.editors.text.AceEditor) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) RFunction(org.rstudio.studio.client.workbench.views.source.editors.text.RFunction)

Example 10 with JsArrayString

use of com.google.gwt.core.client.JsArrayString in project rstudio by rstudio.

the class Shell method sessionInit.

private void sessionInit(Session session) {
    SessionInfo sessionInfo = session.getSessionInfo();
    ClientInitState clientState = sessionInfo.getClientState();
    new StringStateValue(GROUP_CONSOLE, STATE_INPUT, ClientState.TEMPORARY, clientState) {

        @Override
        protected void onInit(String value) {
            initialInput_ = value;
        }

        @Override
        protected String getValue() {
            return view_.getInputEditorDisplay().getText();
        }
    };
    JsArrayString history = sessionInfo.getConsoleHistory();
    if (history != null)
        setHistory(history);
    RpcObjectList<ConsoleAction> actions = sessionInfo.getConsoleActions();
    if (actions != null) {
        view_.playbackActions(actions);
    }
    if (sessionInfo.getResumed()) {
    // no special UI for this (resuming session with all console
    // history and other UI state preserved deemed adequate feedback) 
    }
}
Also used : ConsoleAction(org.rstudio.studio.client.workbench.model.ConsoleAction) SessionInfo(org.rstudio.studio.client.workbench.model.SessionInfo) StringStateValue(org.rstudio.studio.client.workbench.model.helper.StringStateValue) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) ClientInitState(org.rstudio.studio.client.workbench.model.ClientInitState)

Aggregations

JsArrayString (com.google.gwt.core.client.JsArrayString)86 ArrayList (java.util.ArrayList)15 JSONString (com.google.gwt.json.client.JSONString)5 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)5 ServerError (org.rstudio.studio.client.server.ServerError)4 JsArrayInteger (com.google.gwt.core.client.JsArrayInteger)3 Command (com.google.gwt.user.client.Command)3 List (java.util.List)3 KeySequence (org.rstudio.core.client.command.KeyboardShortcut.KeySequence)3 JsObject (org.rstudio.core.client.js.JsObject)3 RmdTemplateFormatOption (org.rstudio.studio.client.rmarkdown.model.RmdTemplateFormatOption)3 JsArrayBoolean (com.google.gwt.core.client.JsArrayBoolean)2 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)2 Label (com.google.gwt.user.client.ui.Label)2 OperationException (org.eclipse.che.api.promises.client.OperationException)2 Handler (org.rstudio.core.client.command.Handler)2 EnsureHeightHandler (org.rstudio.core.client.events.EnsureHeightHandler)2 EnsureVisibleHandler (org.rstudio.core.client.events.EnsureVisibleHandler)2 ChangeFontSizeHandler (org.rstudio.studio.client.application.events.ChangeFontSizeHandler)2 RmdFrontMatterOutputOptions (org.rstudio.studio.client.rmarkdown.model.RmdFrontMatterOutputOptions)2