use of org.erlide.engine.services.codeassist.CompletionData in project erlide_eclipse by erlang.
the class ErlangCompletionService method getAutoImportedFunctions.
List<CompletionData> getAutoImportedFunctions(final IOtpRpc backend, final int offset, final String prefix) {
final OtpErlangObject res = ErlangEngine.getInstance().getOtpDocService().getProposalsWithDoc(backend, "<auto_imported>", prefix);
final List<CompletionData> result = new ArrayList<>();
addFunctionProposalsWithDoc(offset, prefix, result, res, null, false);
return result;
}
use of org.erlide.engine.services.codeassist.CompletionData in project erlide_eclipse by erlang.
the class AbstractErlContentAssistProcessor method computeCompletionProposals.
@Override
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer, final int offset) {
final String id = Integer.toHexString(viewer.hashCode()) + "@" + offset;
try {
ErlideEventTracer.getInstance().traceOperationStart("completion", id);
try {
final IDocument doc = viewer.getDocument();
final String before = getBefore(viewer, doc, offset);
String elementBefore;
final IErlElement el = getElementAt(offset);
if (el instanceof ISourceReference) {
final ISourceRange r = ((ISourceReference) el).getSourceRange();
final int o = r.getOffset();
elementBefore = doc.get(o, offset - o);
} else {
elementBefore = null;
}
if (restarted && offset > 0) {
final char last = doc.get(offset - 1, 1).charAt(0);
if (last == ',' || last == '.' || last == ';' || last == ')' || last == '(') {
return null;
}
}
if (Objects.equal(oldDoc, doc) && oldBefore != null && before.startsWith(oldBefore) && oldSuggestions == 0) {
return getNoCompletion(offset);
}
oldDoc = doc;
oldBefore = before;
final CompletionService completionService = ErlangEngine.getInstance().getCompletionService();
List<ICompletionProposal> result = Lists.newArrayList();
if (project != null) {
final IOtpRpc backend = BackendCore.getBuildBackend(project);
final List<CompletionData> resultData = completionService.computeCompletions(backend, project, module, elementBefore, offset, before, isInString());
result = Lists.transform(resultData, new Function<CompletionData, ICompletionProposal>() {
@Override
public ICompletionProposal apply(final CompletionData data) {
return toProposal(data);
}
});
}
final ErlTemplateCompletionProcessor t = new ErlTemplateCompletionProcessor(doc, offset - before.length(), before.length());
result.addAll(Arrays.asList(t.computeCompletionProposals(viewer, offset)));
oldSuggestions = result.size();
if (result.isEmpty()) {
ErlLogger.debug("no results");
return getNoCompletion(offset);
}
// ErlLogger.debug("%d results", result.size());
return result.toArray(new ICompletionProposal[result.size()]);
} catch (final Exception e) {
ErlLogger.warn(e);
return null;
}
} finally {
ErlideEventTracer.getInstance().traceOperationEnd("completion", id);
}
}
Aggregations