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));
}
}
}
Aggregations