List<LookupElement> lookupElements = ContainerUtil.newArrayList();
Module module = ModuleUtilCore.findModuleForPsiElement(containingFile);
Sdk sdk = module == null ? null : ModuleRootManager.getInstance(module).getSdk();
ErlangSdkRelease release = sdk != null ? ErlangSdkType.getRelease(sdk) : null;
if (qAtom != null) {
String moduleName = getName(qAtom);
functions.addAll(getExternalFunctionForCompletion(containingFile.getProject(), moduleName));
if (release == null || release.needBifCompletion(moduleName)) {
addBifs(lookupElements, ErlangBifTable.getBifs(moduleName), withArity);
}
addBifs(lookupElements, ErlangBifTable.getBifs("", ErlangBifTable.MODULE_INFO), withArity);
}
else {
ErlangFile erlangFile = (ErlangFile) containingFile;
functions.addAll(erlangFile.getFunctions());
functions.addAll(getExternalFunctionForCompletion(containingFile.getProject(), "erlang"));
for (ErlangImportFunction importFunction : erlangFile.getImportedFunctions()) {
lookupElements.add(createFunctionLookupElement(importFunction.getQAtom().getText(), getArity(importFunction.getInteger()), withArity, ErlangCompletionContributor.MODULE_FUNCTIONS_PRIORITY));
}
if (!withArity && (release == null || release.needBifCompletion("erlang"))) {
addBifs(lookupElements, ErlangBifTable.getBifs("erlang"));
}
if (!withArity && (release == null || release.needBifCompletion(""))) {
addBifs(lookupElements, ErlangBifTable.getBifs(""));
}
}
functions.addAll(getErlangFunctionsFromIncludes((ErlangFile) containingFile, true, "", 0));