'Resolve the type inference for \'elem\' at \'scoperef\'.'

def _hits_from_variable_type_inference(self, elem, scoperef):

    assert (elem.tag == 'variable')
    hits = []
    citdl = elem.get('citdl')
    if (citdl == 'require()'):
        requirename = elem.get('required_library_name')
        if requirename:
            self.log('_hits_from_variable_type_inference:    resolving    require(%r)', requirename)
            hits += self._hits_from_commonjs_require(requirename, scoperef)
    if (len(elem) != 0):
        return (hits + [(elem, scoperef)])
    if (not citdl):
        raise CodeIntelError(('no    type-inference    info    for    %r' % elem))
    self.log("resolve    '%s'    type    inference    for    %r:", citdl, elem)
    if ((citdl == elem.get('name')) and (citdl not in elem.names)):
        self.log('_hits_from_variable_type_inference::    recursive    citdl        expression    found,    trying    alternatives.')
        try:
            parent_elem = self._elem_from_scoperef(scoperef)
        except KeyError as ex:
            raise CodeIntelError(('could    not    resolve    recursive    citdl    expression    %r' % citdl))
        else:
            alt_hits = []
            for child in parent_elem:
                if ((child.tag != 'variable') and (child.get('name') == citdl)):
                    alt_hits.append((child, scoperef))
                    if (self._alt_elem_from_scoperef is None):
                        self._alt_elem_from_scoperef = {}
                    alt_sref_name = '.'.join((scoperef[1] + [citdl]))
                    self._alt_elem_from_scoperef[alt_sref_name] = child
                    self.log('Alternative    hit    found:    %r,    scoperef:    %r', child, scoperef)
            if alt_hits:
                return alt_hits
            scoperef = self.parent_scoperef_from_scoperef(scoperef)
            if (scoperef is None):
                raise CodeIntelError(('could    not    resolve    recursive    citdl    expression    %r' % citdl))
            self.log('Continue    search    for    %r    from    the    parent    scope.', citdl)
    try:
        hits += self._hits_from_citdl(citdl, scoperef)
    except EvalError:
        if (not hits):
            raise
    return hits
