Search in sources :

Example 6 with CompletionData

use of org.erlide.engine.services.codeassist.CompletionData in project erlide_eclipse by erlang.

the class ErlangCompletionService method getVariables.

List<CompletionData> getVariables(final IOtpRpc b, final int offset, final String prefix) {
    final List<CompletionData> result = new ArrayList<>();
    final Collection<String> vars = contextAssistService.getVariables(elementBefore, prefix);
    for (final String var : vars) {
        result.add(new CompletionData(null, var, offset - prefix.length(), prefix.length(), var.length()));
    }
    return result;
}
Also used : CompletionData(org.erlide.engine.services.codeassist.CompletionData) FunctionCompletionData(org.erlide.engine.services.codeassist.FunctionCompletionData) ArrayList(java.util.ArrayList) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 7 with CompletionData

use of org.erlide.engine.services.codeassist.CompletionData in project erlide_eclipse by erlang.

the class ErlangCompletionService method getExternalCallCompletions.

List<CompletionData> getExternalCallCompletions(final IOtpRpc b, final String moduleName0, final int offset, final String prefix, final boolean arityOnly) throws CoreException {
    final ModelFindService modelFindService = ErlangEngine.getInstance().getModelFindService();
    final String moduleName = modelFindService.resolveMacroValue(moduleName0, module);
    // we have an external call
    final List<CompletionData> result = new ArrayList<>();
    final IErlElementLocator model = ErlangEngine.getInstance().getModel();
    final IErlModule theModule = modelFindService.findModule(model, project, moduleName, null, IErlElementLocator.Scope.ALL_PROJECTS);
    // FIXME or IErlElementLocator.Scope.REFERENCED_PROJECTS
    if (theModule != null) {
        if (ErlangEngine.getInstance().getModelUtilService().isOtpModule(theModule)) {
            final OtpErlangObject res = ErlangEngine.getInstance().getOtpDocService().getProposalsWithDoc(b, moduleName, prefix);
            addFunctionProposalsWithDoc(offset, prefix, result, res, null, arityOnly);
        } else {
            addFunctionsFromModule(offset, prefix, arityOnly, result, theModule);
        }
    }
    return result;
}
Also used : CompletionData(org.erlide.engine.services.codeassist.CompletionData) FunctionCompletionData(org.erlide.engine.services.codeassist.FunctionCompletionData) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) ArrayList(java.util.ArrayList) IErlModule(org.erlide.engine.model.root.IErlModule) ModelFindService(org.erlide.engine.services.search.ModelFindService) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 8 with CompletionData

use of org.erlide.engine.services.codeassist.CompletionData in project erlide_eclipse by erlang.

the class ErlangCompletionService method getRecordFieldCompletions.

List<CompletionData> getRecordFieldCompletions(final String recordName, final int offset, final String prefix, final int hashMarkPos, final List<String> fieldsSoFar) {
    if (module == null) {
        return ErlangCompletionService.EMPTY_COMPLETIONS;
    }
    IErlPreprocessorDef pd;
    try {
        pd = ErlangEngine.getInstance().getModelFindService().findPreprocessorDef(module, recordName, ErlElementKind.RECORD_DEF);
    } catch (final CoreException e) {
        return ErlangCompletionService.EMPTY_COMPLETIONS;
    }
    if (pd instanceof IErlRecordDef) {
        final List<CompletionData> result = new ArrayList<>();
        try {
            for (final IErlElement i : pd.getChildren()) {
                final IErlRecordField field = (IErlRecordField) i;
                final String fieldName = field.getFieldName();
                if (!fieldsSoFar.contains(fieldName)) {
                    addIfMatches(fieldName, prefix, offset, result);
                }
            }
        } catch (final ErlModelException e) {
        }
        return result;
    }
    return ErlangCompletionService.EMPTY_COMPLETIONS;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) CompletionData(org.erlide.engine.services.codeassist.CompletionData) FunctionCompletionData(org.erlide.engine.services.codeassist.FunctionCompletionData) CoreException(org.eclipse.core.runtime.CoreException) IErlRecordDef(org.erlide.engine.model.erlang.IErlRecordDef) ErlModelException(org.erlide.engine.model.ErlModelException) ArrayList(java.util.ArrayList) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef) IErlRecordField(org.erlide.engine.model.erlang.IErlRecordField)

Example 9 with CompletionData

use of org.erlide.engine.services.codeassist.CompletionData in project erlide_eclipse by erlang.

the class ErlangCompletionService method getModules.

protected List<CompletionData> getModules(final IOtpRpc backend, final int offset, final String prefix, final CompletionFlag kind, final boolean inString) throws ErlModelException {
    final List<String> mods = getModules0(backend, offset, prefix, kind);
    final boolean includes = kind == CompletionFlag.INCLUDES || kind == CompletionFlag.INCLUDE_LIBS;
    final List<CompletionData> result = Lists.newArrayList();
    for (final String m : mods) {
        final String suffix = includes ? "" : ":";
        final String cpl = quoted(m + suffix, kind, inString);
        final int prefixLength = prefix.length();
        result.add(new CompletionData(null, cpl, offset - prefixLength, prefixLength, cpl.length()));
    }
    return result;
}
Also used : CompletionData(org.erlide.engine.services.codeassist.CompletionData) FunctionCompletionData(org.erlide.engine.services.codeassist.FunctionCompletionData) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 10 with CompletionData

use of org.erlide.engine.services.codeassist.CompletionData in project erlide_eclipse by erlang.

the class ErlangCompletionService method getMacroOrRecordCompletions.

List<CompletionData> getMacroOrRecordCompletions(final int offset, final String prefix, final ErlElementKind kind) {
    if (module == null) {
        return ErlangCompletionService.EMPTY_COMPLETIONS;
    }
    final List<CompletionData> result = new ArrayList<>();
    try {
        final List<IErlPreprocessorDef> defs = ErlangCompletionService.getAllPreprocessorDefs(module, kind);
        for (final IErlPreprocessorDef pd : defs) {
            final String name = pd.getDefinedName();
            addIfMatches(name, prefix, offset, result);
        }
    } catch (final CoreException e) {
        ErlLogger.error(e);
    }
    if (kind == ErlElementKind.MACRO_DEF) {
        final String[] names = ErlangEngine.getInstance().getModelUtilService().getPredefinedMacroNames();
        for (final String name : names) {
            addIfMatches(name, prefix, offset, result);
        }
    }
    return result;
}
Also used : CompletionData(org.erlide.engine.services.codeassist.CompletionData) FunctionCompletionData(org.erlide.engine.services.codeassist.FunctionCompletionData) CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef)

Aggregations

CompletionData (org.erlide.engine.services.codeassist.CompletionData)12 FunctionCompletionData (org.erlide.engine.services.codeassist.FunctionCompletionData)12 ArrayList (java.util.ArrayList)8 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)6 IErlElement (org.erlide.engine.model.IErlElement)4 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)3 CoreException (org.eclipse.core.runtime.CoreException)2 ErlModelException (org.erlide.engine.model.ErlModelException)2 IErlImport (org.erlide.engine.model.erlang.IErlImport)2 IErlPreprocessorDef (org.erlide.engine.model.erlang.IErlPreprocessorDef)2 IErlProject (org.erlide.engine.model.root.IErlProject)2 Function (com.google.common.base.Function)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IDocument (org.eclipse.jface.text.IDocument)1 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)1 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)1 IErlRecordDef (org.erlide.engine.model.erlang.IErlRecordDef)1 IErlRecordField (org.erlide.engine.model.erlang.IErlRecordField)1 ISourceRange (org.erlide.engine.model.erlang.ISourceRange)1 ISourceReference (org.erlide.engine.model.erlang.ISourceReference)1