'Analyzes the context that a completion is made in and decides what to
return.
Technically this works by generating a parser stack and analysing the
current stack for possible grammar nodes.
Possible enhancements:
- global/nonlocal search global
- yield from / raise from <- could be only exceptions/generators
- In args: */**: no completion
- In params (also lambda): no completion before ='

def _get_context_completions(self):

    grammar = self._evaluator.grammar
    try:
        self.stack = helpers.get_stack_at_position(grammar, self._code_lines, self._module_node, self._position)
    except helpers.OnErrorLeaf as e:
        self.stack = None
        if (e.error_leaf.value == '.'):
            return []
        return self._global_completions()
    (allowed_keywords, allowed_tokens) = helpers.get_possible_completion_types(grammar, self.stack)
    completion_names = list(self._get_keyword_completion_names(allowed_keywords))
    if ((token.NAME in allowed_tokens) or (token.INDENT in allowed_tokens)):
        symbol_names = list(self.stack.get_node_names(grammar))
        nodes = list(self.stack.get_nodes())
        if ('import_stmt' in symbol_names):
            level = 0
            only_modules = True
            (level, names) = self._parse_dotted_names(nodes)
            if ('import_from' in symbol_names):
                if ('import' in nodes):
                    only_modules = False
            else:
                assert ('import_name' in symbol_names)
            completion_names += self._get_importer_names(names, level, only_modules)
        elif (nodes and (nodes[(-1)] in ('as', 'def', 'class'))):
            return list(self._get_class_context_completions(is_function=True))
        elif ((symbol_names[(-1)] in ('trailer', 'dotted_name')) and (nodes[(-1)] == '.')):
            dot = self._module_node.get_leaf_for_position(self._position)
            completion_names += self._trailer_completions(dot.get_previous_leaf())
        else:
            completion_names += self._global_completions()
            completion_names += self._get_class_context_completions(is_function=False)
        if ('trailer' in symbol_names):
            call_signatures = self._call_signatures_method()
            completion_names += get_call_signature_param_names(call_signatures)
    return completion_names
