コード例 #1
0
    def get_completions(self, info):
        '''Get Python completions'''
        # https://github.com/davidhalter/jedi/blob/master/jedi/utils.py
        if jedi is None:
            return []

        text = info['code']
        position = (info['line_num'], info['column'])
        interpreter = Interpreter(text, [self.env])

        if jedi.__version__ >= LooseVersion('0.12.0'):
            lines = split_lines(text)
            name = get_on_completion_name(interpreter._module_node, lines,
                                          position)
            before = text[:len(text) - len(name)]
        elif jedi.__version__ >= LooseVersion('0.10.0'):
            lines = split_lines(text)
            name = get_on_completion_name(interpreter._get_module_node(),
                                          lines, position)
            before = text[:len(text) - len(name)]
        else:
            path = UserContext(text, position).get_path_until_cursor()
            path, dot, like = completion_parts(path)
            before = text[:len(text) - len(like)]

        completions = interpreter.completions()
        completions = [before + c.name_with_symbols for c in completions]

        self.kernel.log.error(completions)

        return [c[info['start']:] for c in completions]
コード例 #2
0
    def get_completions(self, info):
        '''Get Python completions'''
        # https://github.com/davidhalter/jedi/blob/master/jedi/utils.py
        if jedi is None:
            return []

        text = info['code']
        position = (info['line_num'], info['column'])
        interpreter = Interpreter(text, [self.env])

        lines = split_lines(text)
        name = get_on_completion_name(
            interpreter._module_node,
            lines,
            position
        )
        before = text[:len(text) - len(name)]

        try:
            completions = interpreter.complete()
        except AttributeError:
            completions = interpreter.completions()

        completions = [before + c.name_with_symbols for c in completions]

        self.kernel.log.error(completions)

        return [c[info['start']:] for c in completions]
コード例 #3
0
    def get_completions(self, info):
        """Gets Python completions based on the current cursor position
        within the %%init_spark cell.

        Based on
        https://github.com/Calysto/metakernel/blob/master/metakernel/magics/python_magic.py

        Parameters
        ----------
        info : dict
            Information about the current caret position
        """
        if jedi is None:
            return []

        text = info['code']
        position = (info['line_num'], info['column'])
        interpreter = jedi.Interpreter(text, [self.env])

        lines = common.splitlines(text)
        name = get_on_completion_name(interpreter._get_module_node(), lines,
                                      position)

        before = text[:len(text) - len(name)]
        completions = interpreter.completions()
        completions = [before + c.name_with_symbols for c in completions]
        return [c[info['start']:] for c in completions]
コード例 #4
0
        def complete(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 = common.splitlines(text)
                    position = (len(lines), len(lines[-1]))
                    name = get_on_completion_name(interpreter._get_module(), lines, position)
                    before = text[:len(text) - len(name)]
                    completions = interpreter.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
コード例 #5
0
        def complete(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:
                    interpreter = Interpreter(text,
                                              [namespace_module.__dict__])

                    lines = common.splitlines(text)
                    position = (len(lines), len(lines[-1]))
                    name = get_on_completion_name(lines, position)
                    before = text[:len(text) - len(name)]
                    completions = interpreter.completions()
                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
コード例 #6
0
    def __init__(self, evaluator, module, code_lines, position, call_signatures_method):
        self._evaluator = evaluator
        self._module = evaluator.wrap(module)
        self._code_lines = code_lines

        # The first step of completions is to get the name
        self._like_name = helpers.get_on_completion_name(module, code_lines, position)
        # The actual cursor position is not what we need to calculate
        # everything. We want the start of the name we're on.
        self._position = position[0], position[1] - len(self._like_name)
        self._call_signatures_method = call_signatures_method
コード例 #7
0
ファイル: completion.py プロジェクト: tianser/vim
    def __init__(self, evaluator, module, code_lines, position, call_signatures_method):
        self._evaluator = evaluator
        self._module = evaluator.wrap(module)
        self._code_lines = code_lines

        # The first step of completions is to get the name
        self._like_name = helpers.get_on_completion_name(code_lines, position)
        # The actual cursor position is not what we need to calculate
        # everything. We want the start of the name we're on.
        self._position = position[0], position[1] - len(self._like_name)
        self._call_signatures_method = call_signatures_method
コード例 #8
0
    def __init__(self, evaluator, module, code_lines, position, call_signatures_callback):
        self._evaluator = evaluator
        self._module_context = module
        self._module_node = module.tree_node
        self._code_lines = code_lines

        # The first step of completions is to get the name
        self._like_name = helpers.get_on_completion_name(self._module_node, code_lines, position)
        # The actual cursor position is not what we need to calculate
        # everything. We want the start of the name we're on.
        self._original_position = position
        self._position = position[0], position[1] - len(self._like_name)
        self._call_signatures_callback = call_signatures_callback
コード例 #9
0
ファイル: python_magic.py プロジェクト: Calysto/metakernel
    def get_completions(self, info):
        '''Get Python completions'''
        # https://github.com/davidhalter/jedi/blob/master/jedi/utils.py
        if jedi is None:
            return []

        text = info['code']
        position = (info['line_num'], info['column'])
        interpreter = Interpreter(text, [self.env])

        if jedi.__version__ >= LooseVersion('0.12.0'):
            lines = split_lines(text)
            name = get_on_completion_name(
                interpreter._module_node,
                lines,
                position
            )
            before = text[:len(text) - len(name)]
        elif jedi.__version__ >= LooseVersion('0.10.0'):
            lines = split_lines(text)
            name = get_on_completion_name(
                interpreter._get_module_node(),
                lines,
                position
            )
            before = text[:len(text) - len(name)]
        else:
            path = UserContext(text, position).get_path_until_cursor()
            path, dot, like = completion_parts(path)
            before = text[:len(text) - len(like)]

        completions = interpreter.completions()
        completions = [before + c.name_with_symbols for c in completions]

        self.kernel.log.error(completions)

        return [c[info['start']:] for c in completions]
コード例 #10
0
ファイル: completion.py プロジェクト: OUMAREGA/PythonFlask
    def __init__(self, inference_state, module_context, code_lines, position,
                 signatures_callback, fuzzy=False):
        self._inference_state = inference_state
        self._module_context = module_context
        self._module_node = module_context.tree_node
        self._code_lines = code_lines

        # The first step of completions is to get the name
        self._like_name = helpers.get_on_completion_name(self._module_node, code_lines, position)
        # The actual cursor position is not what we need to calculate
        # everything. We want the start of the name we're on.
        self._original_position = position
        self._signatures_callback = signatures_callback

        self._fuzzy = fuzzy
コード例 #11
0
    def __init__(self, evaluator, module, code_lines, position, call_signatures_method):
        self._evaluator = evaluator
        self._module_context = module
        self._module_node = module.tree_node
        self._code_lines = code_lines

        # The first step of completions is to get the name
        self._like_name = helpers.get_on_completion_name(self._module_node, code_lines, position)
        # The actual cursor position is not what we need to calculate
        # everything. We want the start of the name we're on.

        # Some hacks to increase speed of Jedi
        current_line = self._code_lines[position[0] - 1]
        if '.' not in current_line and '(' not in current_line:
            init_speed_hacks(True)
        else:
            init_speed_hacks(False)

        self._position = position[0], position[1] - len(self._like_name)
        self._call_signatures_method = call_signatures_method