Search in sources :

Example 1 with Location

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);
        }
    }
}
Also used : LinkedPositionGroup(org.eclipse.jface.text.link.LinkedPositionGroup) LinkedPosition(org.eclipse.jface.text.link.LinkedPosition) EditorLinkedModeUI(org.eclipse.ui.texteditor.link.EditorLinkedModeUI) LinkedModeModel(org.eclipse.jface.text.link.LinkedModeModel) LinkedModeUI(org.eclipse.jface.text.link.LinkedModeUI) EditorLinkedModeUI(org.eclipse.ui.texteditor.link.EditorLinkedModeUI) Point(org.eclipse.swt.graphics.Point) BadLocationException(org.eclipse.jface.text.BadLocationException) Location(org.erlide.engine.services.codeassist.Location)

Example 2 with Location

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);
    }
}
Also used : ArrayList(java.util.ArrayList) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) Location(org.erlide.engine.services.codeassist.Location)

Example 3 with Location

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);
        }
    }
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) ArrayList(java.util.ArrayList) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) Location(org.erlide.engine.services.codeassist.Location)

Example 4 with Location

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;
    }
}
Also used : OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) Location(org.erlide.engine.services.codeassist.Location)

Example 5 with Location

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) {
        }
    }
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) Location(org.erlide.engine.services.codeassist.Location)

Aggregations

Location (org.erlide.engine.services.codeassist.Location)5 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)3 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)2 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)2 ArrayList (java.util.ArrayList)2 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)1 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)1 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 LinkedModeModel (org.eclipse.jface.text.link.LinkedModeModel)1 LinkedModeUI (org.eclipse.jface.text.link.LinkedModeUI)1 LinkedPosition (org.eclipse.jface.text.link.LinkedPosition)1 LinkedPositionGroup (org.eclipse.jface.text.link.LinkedPositionGroup)1 Point (org.eclipse.swt.graphics.Point)1 EditorLinkedModeUI (org.eclipse.ui.texteditor.link.EditorLinkedModeUI)1