def METHOD_NAME(self, text, state):
    """
    This complete stuff is pretty weird, a generator would make
    a lot more sense, but probably due to backwards compatibility
    this is still the way how it works.
    The only important part is stuff in the ``state == 0`` flow,
    everything else has been copied from the ``rlcompleter`` std.
    library module.
    """
    if state == 0:
        sys.path.insert(0, os.getcwd())
        # Calling python doesn't have a path, so add to sys.path.
        try:
            logging.debug("Start REPL completion: " + repr(text))
            interpreter = Interpreter(text, [namespace_module.__dict__])
            lines = split_lines(text)
            position = (len(lines), len(lines[-1]))
            name = get_on_completion_name(
                interpreter._module_node,
                lines,
                position
            )
            before = text[:len(text) - len(name)]
            completions = interpreter.completions()
            logging.debug("REPL completions: %s", completions)
        except:
            logging.error("REPL Completion error:\n" + traceback.format_exc())
            raise
        finally:
            sys.path.pop(0)
        self.matches = [before + c.name_with_symbols for c in completions]
    try:
        return self.matches[state]
    except IndexError:
        return None