'Resolve the function call inference for \'elem\' at \'scoperef\'.'

def _hits_from_call(self, elem, scoperef):

    if (elem.tag == 'variable'):
        hits = []
        var_hits = self._hits_from_variable_type_inference(elem, scoperef)
        for (var_elem, var_scoperef) in var_hits:
            if (var_elem != elem):
                try:
                    hits += self._hits_from_call(var_elem, var_scoperef)
                except CodeIntelError:
                    pass
        if (not hits):
            raise CodeIntelError(('could    not    resolve    call    on    %r.' % elem))
        return hits
    if (elem.get('ilk') == 'class'):
        return [(elem, scoperef)]
    if (elem.get('ilk') != 'function'):
        raise CodeIntelError(('_hits_from_call::    unexpected    element    type    %r' % elem))
    if ((elem.get('name') == 'require') and (scoperef[0] is self.built_in_blob) and (not scoperef[1])):
        try:
            requirename = self.trg.extra.get('_params', []).pop(0)
        except IndexError:
            requirename = None
        if (requirename is not None):
            import codeintel2.lang_javascript
            requirename = codeintel2.lang_javascript.Utils.unquoteJsString(requirename)
            self.log('_hits_from_call:    resolving    CommonJS    require(%r)', requirename)
            hits = self._hits_from_commonjs_require(requirename, scoperef)
            if (len(hits) > 0):
                return hits
    resolver = getattr(elem, 'resolve', None)
    try:
        param = self.trg.extra.get('_params', []).pop(0)
    except IndexError:
        param = None
    if (resolver and (param is not None)):
        try:
            self.log('Attempting    to    use    extra    resolver    %r    param    %r', resolver, param)
            hits = resolver(evlr=self, action='call', scoperef=scoperef, param=param)
            if hits:
                return hits
        except:
            self.log('Extra    resolver    %r:    Failed    to    resolve    %s', resolver, scoperef)
    else:
        self.log('_hits_from_call:    no    resolver    on    %r', elem)
    citdl = elem.get('returns')
    if (not citdl):
        raise CodeIntelError(('no    return    type    info    for    %r' % elem))
    self.log("_hits_from_call:    resolve    '%s'    for    %r,    scoperef:    %r", citdl, elem, scoperef)
    scoperef = (scoperef[0], (scoperef[1] + [elem.get('name')]))
    return self._hits_from_citdl(citdl, scoperef)
