use of org.erlide.engine.services.codeassist.Location in project erlide_eclipse by erlang.
the class ErlCompletionProposal method setUpLinkedMode.
/**
* Sets up a simple linked mode at {@link #getCursorPosition()} and an exit
* policy that will exit the mode when <code>closingCharacter</code> is
* typed and an exit position at <code>getCursorPosition() + 1</code>.
*
* @param document
* the document
* @param closingCharacter
* the exit character
* @param offsetsAndLengths
* list of offsets and lengths for linked groups
*/
protected void setUpLinkedMode(final IDocument document, final char closingCharacter, final List<Location> offsetsAndLengths) {
if (sourceViewer != null && !offsetsAndLengths.isEmpty()) {
try {
final LinkedModeModel model = new LinkedModeModel();
int last = 0;
int i = 0;
for (final Location offsetAndLength : offsetsAndLengths) {
final LinkedPositionGroup group = new LinkedPositionGroup();
group.addPosition(new LinkedPosition(document, offsetAndLength.getOffset(), offsetAndLength.getLength(), ++i));
model.addGroup(group);
final int l = offsetAndLength.getOffset() + offsetAndLength.getLength();
if (l > last) {
last = l;
}
}
model.forceInstall();
final LinkedModeUI ui = new EditorLinkedModeUI(model, sourceViewer);
// ui.setSimpleMode(true);
ui.setExitPolicy(new ExitPolicy(closingCharacter, document));
ui.setExitPosition(sourceViewer, last + 1, 0, LinkedPositionGroup.NO_STOP);
ui.setCyclingMode(LinkedModeUI.CYCLE_ALWAYS);
ui.enter();
} catch (final BadLocationException x) {
ErlLogger.error(x);
}
}
}
use of org.erlide.engine.services.codeassist.Location in project erlide_eclipse by erlang.
the class ErlangCompletionService method addFunctionCompletion.
void addFunctionCompletion(final int offset, final String prefix, final ErlangFunction function, final Collection<IErlComment> comments, final boolean arityOnly, final List<String> parameterNames, final List<CompletionData> result) {
if (function.name.regionMatches(0, prefix, 0, prefix.length())) {
final int offs = function.name.length() - prefix.length();
final List<Location> offsetsAndLengths = new ArrayList<>();
if (!arityOnly) {
addOffsetsAndLengths(parameterNames, offset + offs + 1, offsetsAndLengths);
}
final String funWithArity = function.getNameWithArity();
String funWithParameters = arityOnly ? funWithArity : getNameWithParameters(function.name, parameterNames);
funWithParameters = funWithParameters.substring(prefix.length());
final String htmlComment = comments == null ? "" : DocumentationFormatter.getDocumentationString(comments, null);
addFunctionCompletion(offset, result, funWithArity, htmlComment, funWithParameters, offsetsAndLengths);
}
}
use of org.erlide.engine.services.codeassist.Location in project erlide_eclipse by erlang.
the class ErlangCompletionService method addFunctionProposalsWithDoc.
void addFunctionProposalsWithDoc(final int offset, final String aprefix, final List<CompletionData> result, final OtpErlangObject res, final IErlImport erlImport, final boolean arityOnly) {
if (res instanceof OtpErlangList) {
final OtpErlangList resl = (OtpErlangList) res;
for (final OtpErlangObject i : resl) {
// {FunWithArity, FunWithParameters, [{Offset, Length}], Doc}
final OtpErlangTuple f = (OtpErlangTuple) i;
final String funWithArity = ((OtpErlangString) f.elementAt(0)).stringValue();
if (!ErlangCompletionService.filterImported(erlImport, funWithArity)) {
continue;
}
String funWithParameters = arityOnly ? funWithArity : ((OtpErlangString) f.elementAt(1)).stringValue();
final OtpErlangList parOffsets = (OtpErlangList) f.elementAt(2);
String docStr = null;
if (f.arity() > 3) {
final OtpErlangObject elt = f.elementAt(3);
if (elt instanceof OtpErlangString) {
docStr = Util.stringValue(elt);
}
}
funWithParameters = funWithParameters.substring(aprefix.length());
final List<Location> offsetsAndLengths = new ArrayList<>();
if (!arityOnly) {
addOffsetsAndLengths(parOffsets, offset, offsetsAndLengths);
}
addFunctionCompletion(offset, result, funWithArity, docStr, funWithParameters, offsetsAndLengths);
}
}
}
use of org.erlide.engine.services.codeassist.Location in project erlide_eclipse by erlang.
the class ErlangCompletionService method addOffsetsAndLengths.
private void addOffsetsAndLengths(final List<String> parameterNames, final int replacementOffset0, final List<Location> result) {
int replacementOffset = replacementOffset0;
for (final String par : parameterNames) {
result.add(new Location(replacementOffset, par.length()));
replacementOffset += par.length() + 2;
}
}
use of org.erlide.engine.services.codeassist.Location in project erlide_eclipse by erlang.
the class ErlangCompletionService method addOffsetsAndLengths.
void addOffsetsAndLengths(final OtpErlangList parOffsets, final int replacementOffset, final List<Location> result) {
for (final OtpErlangObject i : parOffsets) {
final OtpErlangTuple t = (OtpErlangTuple) i;
final OtpErlangLong offset = (OtpErlangLong) t.elementAt(0);
final OtpErlangLong length = (OtpErlangLong) t.elementAt(1);
try {
result.add(new Location(offset.intValue() + replacementOffset, length.intValue()));
} catch (final OtpErlangRangeException e) {
}
}
}
Aggregations