Exemple #1
0
    def _loop(self):
        from jedi.evaluate.sys_path import _get_venv_sitepackages

        while True:
            data = stream_read(sys.stdin)
            if not isinstance(data, tuple):
                continue

            cache_key, source, line, col, filename, options = data
            orig_path = sys.path[:]
            venv = os.getenv('VIRTUAL_ENV')
            if venv:
                sys.path.insert(0, _get_venv_sitepackages(venv))
            add_path = self.find_extra_sys_path(filename)
            if add_path and add_path not in sys.path:
                # Add the found path to sys.path.  I'm not 100% certain if this
                # is actually helping anything, but it feels like the right
                # thing to do.
                sys.path.insert(0, add_path)
            if filename:
                sys.path.append(os.path.dirname(filename))

            if isinstance(options, dict):
                extra = options.get('extra_path')
                if extra:
                    if not isinstance(extra, list):
                        extra = [extra]
                    sys.path.extend(extra)

                # Add extra paths if working on a Python remote plugin.
                sys.path.extend(utils.rplugin_runtime_paths(options))

            # Decorators on incomplete functions cause an error to be raised by
            # Jedi.  I assume this is because Jedi is attempting to evaluate
            # the return value of the wrapped, but broken, function.
            # Our solution is to simply strip decorators from the source since
            # we are a completion service, not the syntax police.
            out = None

            if cache_key[-1] == 'vars':
                # Attempt scope completion.  If it fails, it should fall
                # through to script completion.
                out = self.scoped_completions(source, filename, cache_key[-2])

            if not out:
                out = self.script_completion(source, line, col, filename)

            if not out and cache_key[-1] in ('package', 'local'):
                # The backup plan
                try:
                    out = self.module_completions(cache_key[0], sys.path)
                except Exception:
                    pass

            stream_write(sys.stdout, out)
            sys.path[:] = orig_path
Exemple #2
0
    def _loop(self):
        from jedi.evaluate.sys_path import _get_venv_sitepackages

        while True:
            data = stream_read(sys.stdin)
            if not isinstance(data, tuple):
                continue

            cache_key, source, line, col, filename = data
            orig_path = sys.path[:]
            venv = os.getenv('VIRTUAL_ENV')
            if venv:
                sys.path.insert(0, _get_venv_sitepackages(venv))
            add_path = self.find_extra_sys_path(filename)
            if add_path and add_path not in sys.path:
                # Add the found path to sys.path.  I'm not 100% certain if this
                # is actually helping anything, but it feels like the right
                # thing to do.
                sys.path.insert(0, add_path)
            if filename:
                sys.path.append(os.path.dirname(filename))

            # Decorators on incomplete functions cause an error to be raised by
            # Jedi.  I assume this is because Jedi is attempting to evaluate
            # the return value of the wrapped, but broken, function.
            # Our solution is to simply strip decorators from the source since
            # we are a completion service, not the syntax police.
            out = None

            if cache_key[-1] == 'vars':
                # Attempt scope completion.  If it fails, it should fall
                # through to script completion.
                out = self.scoped_completions(source, filename, cache_key[-2])

            if not out:
                out = self.script_completion(source, line, col, filename)

            if not out and cache_key[-1] in ('package', 'local'):
                # The backup plan
                try:
                    out = self.module_completions(cache_key[0], sys.path)
                except Exception:
                    pass

            stream_write(sys.stdout, out)
            sys.path[:] = orig_path
    def _loop(self):
        from jedi.evaluate.sys_path import _get_venv_sitepackages

        while True:
            data = stream_read(sys.stdin)
            if not isinstance(data, tuple):
                continue

            cache_key, source, line, col, filename, options = data
            orig_path = sys.path[:]
            venv = os.getenv('VIRTUAL_ENV')
            if venv:
                sys.path.insert(0, _get_venv_sitepackages(venv))
            add_path = self.find_extra_sys_path(filename)
            if add_path and add_path not in sys.path:
                # Add the found path to sys.path.  I'm not 100% certain if this
                # is actually helping anything, but it feels like the right
                # thing to do.
                sys.path.insert(0, add_path)
            if filename:
                sys.path.append(os.path.dirname(filename))

            if isinstance(options, dict):
                extra = options.get('extra_path')
                if extra:
                    if not isinstance(extra, list):
                        extra = [extra]
                    sys.path.extend(extra)

                # Add extra paths if working on a Python remote plugin.
                sys.path.extend(utils.rplugin_runtime_paths(options))

            # Decorators on incomplete functions cause an error to be raised by
            # Jedi.  I assume this is because Jedi is attempting to evaluate
            # the return value of the wrapped, but broken, function.
            # Our solution is to simply strip decorators from the source since
            # we are a completion service, not the syntax police.
            out = self.script_completion(source, line, col, filename)

            if not out and cache_key[-1] == 'vars':
                # Attempt scope completion.  If it fails, it should fall
                # through to script completion.
                log.debug('Fallback to scoped completions')
                out = self.scoped_completions(source, filename, cache_key[-2])

            if not out and isinstance(options,
                                      dict) and 'synthetic' in options:
                synthetic = options.get('synthetic')
                log.debug('Using synthetic completion: %r', synthetic)
                out = self.script_completion(synthetic['src'],
                                             synthetic['line'],
                                             synthetic['col'], filename)

            if not out and cache_key[-1] in ('package', 'local'):
                # The backup plan
                log.debug('Fallback to module completions')
                try:
                    out = self.module_completions(cache_key[0], sys.path)
                except Exception:
                    pass

            stream_write(sys.stdout, out)
            sys.path[:] = orig_path