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