Search in sources :

Example 1 with RFunction

use of org.rstudio.studio.client.workbench.views.source.editors.text.RFunction 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)

Aggregations

JsArrayString (com.google.gwt.core.client.JsArrayString)1 AceEditor (org.rstudio.studio.client.workbench.views.source.editors.text.AceEditor)1 RFunction (org.rstudio.studio.client.workbench.views.source.editors.text.RFunction)1 CodeModel (org.rstudio.studio.client.workbench.views.source.editors.text.ace.CodeModel)1 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)1