Search in sources :

Example 1 with RScopeObject

use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.RScopeObject in project rstudio by rstudio.

the class CompletionRequester method addScopedCompletions.

private void addScopedCompletions(String token, ArrayList<QualifiedName> completions, String type) {
    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<RScopeObject> scopeVariables = codeModel.getVariablesInScope(cursorPosition);
        String tokenLower = token.toLowerCase();
        for (int i = 0; i < scopeVariables.length(); i++) {
            RScopeObject variable = scopeVariables.get(i);
            if (variable.getType() == type && variable.getToken().toLowerCase().startsWith(tokenLower))
                completions.add(new QualifiedName(variable.getToken(), variable.getType(), 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) RScopeObject(org.rstudio.studio.client.workbench.views.source.editors.text.ace.RScopeObject)

Aggregations

JsArrayString (com.google.gwt.core.client.JsArrayString)1 AceEditor (org.rstudio.studio.client.workbench.views.source.editors.text.AceEditor)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 RScopeObject (org.rstudio.studio.client.workbench.views.source.editors.text.ace.RScopeObject)1