docstr: 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 =
docstr_tok: ["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","="]
code: def _get_context_completions(self):
      """
      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 =
      """
  
      grammar = self._evaluator.grammar
  
      try:
          self.stack = stack = helpers.get_stack_at_position(
              grammar,
              self._code_lines,
              self._module_node,
              self._position,
          )
      except helpers.OnErrorLeaf as e:
          self.stack = stack = None
          if e.error_leaf.value == ".":
              # After ErrorLeaf's that are dots, we will not do any
              # completions since this probably just confuses the user.
              return []
          # If we don't have a context, just use global completion.
  
          return self._global_completions()
  
      allowed_transitions = list(
          stack._allowed_transition_names_and_token_types()
      )
  
      if "if" in allowed_transitions:
          leaf = self._module_node.get_leaf_for_position(
              self._position, include_prefixes=True
          )
          previous_leaf = leaf.get_previous_leaf()
  
          indent = self._position[1]
          if not (leaf.start_pos <= self._position <= leaf.end_pos):
              indent = leaf.start_pos[1]
  
          if previous_leaf is not None:
              stmt = previous_leaf
              while True:
                  stmt = search_ancestor(
                      stmt,
                      "if_stmt",
                      "for_stmt",
                      "while_stmt",
                      "try_stmt",
                      "error_node",
                  )
                  if stmt is None:
                      break
  
                  type_ = stmt.type
                  if type_ == "error_node":
                      first = stmt.children[0]
                      if isinstance(first, Leaf):
                          type_ = first.value + "_stmt"
                  # Compare indents
                  if stmt.start_pos[1] == indent:
                      if type_ == "if_stmt":
                          allowed_transitions += ["elif", "else"]
                      elif type_ == "try_stmt":
                          allowed_transitions += [
                              "except",
                              "finally",
                              "else",
                          ]
                      elif type_ == "for_stmt":
                          allowed_transitions.append("else")
  
      completion_names = list(
          self._get_keyword_completion_names(allowed_transitions)
      )
  
      if any(
          t in allowed_transitions
          for t in (PythonTokenTypes.NAME, PythonTokenTypes.INDENT)
      ):
          # This means that we actually have to do type inference.
  
          nonterminals = [
              stack_node.nonterminal for stack_node in stack
          ]
  
          nodes = [
              node for stack_node in stack for node in stack_node.nodes
          ]
  
          if nodes and nodes[-1] in ("as", "def", "class"):
              # No completions for ``with x as foo`` and ``import x as foo``.
              # Also true for defining names as a class or function.
              return list(
                  self._get_class_context_completions(is_function=True)
              )
          elif "import_stmt" in nonterminals:
              level, names = self._parse_dotted_names(
                  nodes, "import_from" in nonterminals
              )
  
              only_modules = not (
                  "import_from" in nonterminals and "import" in nodes
              )
              completion_names += self._get_importer_names(
                  names,
                  level,
                  only_modules=only_modules,
              )
          elif (
              nonterminals[-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 nonterminals:
              call_signatures = self._call_signatures_method()
              completion_names += get_call_signature_param_names(
                  call_signatures
              )
  
      return completion_names
  
imports: from parso.python.token import PythonTokenTypes
  from parso.python import tree
  from parso.tree import search_ancestor, Leaf
  from jedi._compatibility import Parameter
  from jedi import debug
  from jedi import settings
  from jedi.api import classes
  from jedi.api import helpers
  from jedi.evaluate import imports
  from jedi.api import keywords
  from jedi.evaluate.helpers import evaluate_call_of_leaf
  from jedi.evaluate.filters import get_global_filters
  from jedi.parser_utils import get_statement_of_position
label_desc: Use image node_id 3 for calling the Completion obj's underlying member method code with example usage: obj._get_context_completions() and returns: completion_names, self, list, list