Пример #1
0
    def filter(self, context):
        if not context['candidates'] or not context['input'] or self._disabled:
            return context['candidates']

        if not self._initialized:
            # cpsm installation check
            ext = '.pyd' if context['is_windows'] else '.so'
            if globruntime(context['runtimepath'], 'bin/cpsm_py' + ext):
                # Add path
                sys.path.append(
                    os.path.dirname(
                        globruntime(context['runtimepath'],
                                    'bin/cpsm_py' + ext)[0]))
                self._initialized = True
            else:
                error(
                    self.vim, 'matcher_cpsm: bin/cpsm_py' + ext +
                    ' is not found in your runtimepath.')
                error(
                    self.vim, 'matcher_cpsm: You must install/build' +
                    ' Python3 support enabled cpsm.')
                self._disabled = True
                return []

        complete_str = context['complete_str']
        if context['ignorecase']:
            complete_str = complete_str.lower()

        cpsm_result = self._get_cpsm_result(context['candidates'],
                                            complete_str)
        return [
            x for x in context['candidates']
            if x['word'] in sorted(cpsm_result, key=cpsm_result.index)
        ]
Пример #2
0
    def load_sources(self, context):
        # Load sources from runtimepath
        for path in globruntime(context['runtimepath'],
                                'rplugin/python3/deoplete/sources/base.py'
                                ) + globruntime(
                                    context['runtimepath'],
                                    'rplugin/python3/deoplete/sources/*.py'):
            name = os.path.basename(path)[: -3]
            module = importlib.machinery.SourceFileLoader(
                'deoplete.sources.' + name, path).load_module()
            self.debug(path)
            if not hasattr(module, 'Source') or name in self.__sources:
                continue

            source = module.Source(self.__vim)
            source.name = name
            source.min_pattern_length = getattr(
                source, 'min_pattern_length',
                context['vars']['deoplete#auto_complete_start_length'])
            source.max_abbr_width = getattr(
                source, 'max_abbr_width',
                context['vars']['deoplete#max_abbr_width'])
            source.max_menu_width = getattr(
                source, 'max_menu_width',
                context['vars']['deoplete#max_menu_width'])

            self.__sources[name] = source
            self.debug('Loaded Source: %s (%s)', name, module.__file__)

        self.set_source_attributes(context)
        self.__custom = context['custom']
Пример #3
0
    def filter(self, context):
        if not context['candidates'] or not context[
                'input'] or self._disabled:
            return context['candidates']

        if not self._initialized:
            # cpsm installation check
            ext = '.pyd' if context['is_windows'] else '.so'
            if globruntime(context['runtimepath'], 'bin/cpsm_py' + ext):
                # Add path
                sys.path.append(os.path.dirname(
                    globruntime(context['runtimepath'],
                                'bin/cpsm_py' + ext)[0]))
                self._initialized = True
            else:
                error(self.vim, 'matcher_cpsm: bin/cpsm_py' + ext +
                      ' is not found in your runtimepath.')
                error(self.vim, 'matcher_cpsm: You must install/build' +
                      ' Python3 support enabled cpsm.')
                self._disabled = True
                return []

        cpsm_result = self._get_cpsm_result(
            context['candidates'], context['complete_str'])
        return [x for x in context['candidates']
                if x['word'] in sorted(cpsm_result, key=cpsm_result.index)]
Пример #4
0
    def load_sources(self, context):
        # Load sources from runtimepath
        for path in globruntime(
                context['runtimepath'],
                'rplugin/python3/deoplete/sources/base.py') + globruntime(
                    context['runtimepath'],
                    'rplugin/python3/deoplete/sources/*.py'):
            name = os.path.basename(path)[:-3]
            module = importlib.machinery.SourceFileLoader(
                'deoplete.sources.' + name, path).load_module()
            self.debug(path)
            if not hasattr(module, 'Source') or name in self.__sources:
                continue

            source = module.Source(self.__vim)

            # Set the source attributes.
            source.filetypes = get_custom(context['custom'], source.name,
                                          'filetypes', source.filetypes)
            source.disabled_syntaxes = get_custom(context['custom'],
                                                  source.name,
                                                  'disabled_syntaxes',
                                                  source.disabled_syntaxes)
            source.input_pattern = get_custom(context['custom'], source.name,
                                              'input_pattern',
                                              source.input_pattern)
            source.min_pattern_length = get_custom(
                context['custom'], source.name, 'min_pattern_length',
                getattr(
                    source, 'min_pattern_length',
                    context['vars']['deoplete#auto_complete_start_length']))
            source.max_pattern_length = get_custom(context['custom'],
                                                   source.name,
                                                   'max_pattern_length',
                                                   source.max_pattern_length)
            source.max_abbr_width = get_custom(
                context['custom'], source.name, 'max_abbr_width',
                getattr(source, 'max_abbr_width',
                        context['vars']['deoplete#max_abbr_width']))
            source.max_menu_width = get_custom(
                context['custom'], source.name, 'max_menu_width',
                getattr(source, 'max_menu_width',
                        context['vars']['deoplete#max_menu_width']))
            source.matchers = get_custom(context['custom'], source.name,
                                         'matchers', source.matchers)
            source.sorters = get_custom(context['custom'], source.name,
                                        'sorters', source.sorters)
            source.converters = get_custom(context['custom'], source.name,
                                           'converters', source.converters)
            source.mark = get_custom(context['custom'], source.name, 'mark',
                                     source.mark)
            source.debug_enabled = get_custom(context['custom'], source.name,
                                              'debug_enabled',
                                              source.debug_enabled)

            self.__sources[source.name] = source
            self.debug('Loaded Source: %s (%s)', name, module.__file__)
Пример #5
0
 def load_sources(self):
     # Load sources from runtimepath
     for path in globruntime(self.vim,
             'rplugin/python3/deoplete/sources/base.py') \
             + globruntime(self.vim,
             'rplugin/python3/deoplete/sources/*.py'):
         name = os.path.basename(path)
         source = importlib.machinery.SourceFileLoader(
             'deoplete.sources.' + name[: -3], path).load_module()
         if hasattr(source, 'Source'):
             self.sources[name[: -3]] = source.Source(self.vim)
Пример #6
0
 def load_filters(self):
     # Load filters from runtimepath
     for path in globruntime(
             self.__vim,
             'rplugin/python3/deoplete/filters/base.py') + globruntime(
                 self.__vim, 'rplugin/python3/deoplete/filters/*.py'):
         name = os.path.basename(path)[:-3]
         filter = importlib.machinery.SourceFileLoader(
             'deoplete.filters.' + name, path).load_module()
         if hasattr(filter, 'Filter') and name not in self.__filters:
             self.__filters[name] = filter.Filter(self.__vim)
Пример #7
0
 def load_filters(self):
     # Load filters from runtimepath
     for path in globruntime(self.vim,
             'rplugin/python3/deoplete/filters/base.py') \
             + globruntime(self.vim,
             'rplugin/python3/deoplete/filters/*.py'):
         name = os.path.basename(path)
         filter = importlib.machinery.SourceFileLoader(
             'deoplete.filters.' + name[: -3], path).load_module()
         if hasattr(filter, 'Filter'):
             self.filters[name[: -3]] = filter.Filter(self.vim)
Пример #8
0
 def load_sources(self):
     # Load sources from runtimepath
     for path in globruntime(
             self.__vim,
             'rplugin/python3/deoplete/sources/base.py') + globruntime(
                 self.__vim, 'rplugin/python3/deoplete/sources/*.py'):
         name = os.path.basename(path)[:-3]
         source = importlib.machinery.SourceFileLoader(
             'deoplete.sources.' + name, path).load_module()
         if hasattr(source, 'Source') and name not in self.__sources:
             self.__sources[name] = source.Source(self.__vim)
Пример #9
0
 def load_filters(self):
     # Load filters from runtimepath
     for path in globruntime(
             self.__vim,
             'rplugin/python3/deoplete/filters/base.py') + globruntime(
                 self.__vim, 'rplugin/python3/deoplete/filters/*.py'):
         name = os.path.basename(path)[:-3]
         module = importlib.machinery.SourceFileLoader(
             'deoplete.filters.' + name, path).load_module()
         if hasattr(module, 'Filter') and name not in self.__filters:
             filter = module.Filter(self.__vim)
             self.__filters[filter.name] = filter
             self.debug('Loaded Filter: %s (%s)', name, module.__file__)
Пример #10
0
 def load_filters(self):
     # Load filters from runtimepath
     for path in globruntime(self.__vim,
                             'rplugin/python3/deoplete/filters/base.py'
                             ) + globruntime(
                                 self.__vim,
                                 'rplugin/python3/deoplete/filters/*.py'):
         name = os.path.basename(path)[: -3]
         filter = importlib.machinery.SourceFileLoader(
             'deoplete.filters.' + name, path).load_module()
         if hasattr(filter, 'Filter') and name not in self.__filters:
             self.__filters[name] = filter.Filter(self.__vim)
             self.debug('Loaded Filter: %s (%s)', name, filter.__file__)
Пример #11
0
 def load_filters(self, context):
     # Load filters from runtimepath
     for path in globruntime(context['runtimepath'],
                             'rplugin/python3/deoplete/filter/base.py'
                             ) + globruntime(
                                 context['runtimepath'],
                                 'rplugin/python3/deoplete/filter/*.py'):
         filename = os.path.basename(path)[: -3]
         module = importlib.machinery.SourceFileLoader(
             'deoplete.filter.' + filename, path).load_module()
         if hasattr(module, 'Filter') and filename not in self.__filters:
             filter = module.Filter(self.__vim)
             self.__filters[filter.name] = filter
             self.debug('Loaded Filter: %s (%s)',
                        filter.name, module.__file__)
Пример #12
0
    def load_sources(self):
        # Load sources from runtimepath
        for path in globruntime(self.__vim,
                                'rplugin/python3/deoplete/sources/base.py'
                                ) + globruntime(
                                    self.__vim,
                                    'rplugin/python3/deoplete/sources/*.py'):
            name = os.path.basename(path)[: -3]
            module = importlib.machinery.SourceFileLoader(
                'deoplete.sources.' + name, path).load_module()
            if not hasattr(module, 'Source') or name in self.__sources:
                continue

            source = module.Source(self.__vim)

            # Set the source attributes.
            source.filetypes = get_custom(
                self.__vim, source.name).get(
                    'filetypes', source.filetypes)
            source.disabled_syntaxes = get_custom(
                self.__vim, source.name).get(
                    'disabled_syntaxes', source.disabled_syntaxes)
            source.input_pattern = get_custom(
                self.__vim, source.name).get(
                    'input_pattern', source.input_pattern)
            source.min_pattern_length = get_custom(
                self.__vim, source.name).get(
                    'min_pattern_length', source.min_pattern_length)
            source.max_pattern_length = get_custom(
                self.__vim, source.name).get(
                    'max_pattern_length', source.max_pattern_length)
            source.max_abbr_width = get_custom(
                self.__vim, source.name).get(
                    'max_abbr_width', source.max_abbr_width)
            source.max_menu_width = get_custom(
                self.__vim, source.name).get(
                    'max_menu_width', source.max_menu_width)
            source.matchers = get_custom(
                self.__vim, source.name).get('matchers', source.matchers)
            source.sorters = get_custom(self.__vim, source.name).get(
                'sorters', source.sorters)
            source.converters = get_custom(self.__vim, source.name).get(
                'converters', source.converters)
            source.mark = get_custom(self.__vim, source.name).get(
                'mark', source.mark)

            self.__sources[source.name] = source
            self.debug('Loaded Source: %s (%s)', name, module.__file__)
Пример #13
0
    def load_sources(self):
        # Load sources from runtimepath
        for path in globruntime(self.__vim, "rplugin/python3/deoplete/sources/base.py") + globruntime(
            self.__vim, "rplugin/python3/deoplete/sources/*.py"
        ):
            name = os.path.basename(path)[:-3]
            module = importlib.machinery.SourceFileLoader("deoplete.sources." + name, path).load_module()
            if not hasattr(module, "Source") or name in self.__sources:
                continue

            source = module.Source(self.__vim)

            # Set the source attributes.
            source.filetypes = get_custom(self.__vim, source.name).get("filetypes", source.filetypes)
            source.disabled_syntaxes = get_custom(self.__vim, source.name).get(
                "disabled_syntaxes", source.disabled_syntaxes
            )
            source.input_pattern = get_custom(self.__vim, source.name).get("input_pattern", source.input_pattern)
            source.min_pattern_length = get_custom(self.__vim, source.name).get(
                "min_pattern_length", source.min_pattern_length
            )
            source.max_pattern_length = get_custom(self.__vim, source.name).get(
                "max_pattern_length", source.max_pattern_length
            )
            source.matchers = get_custom(self.__vim, source.name).get("matchers", source.matchers)
            source.sorters = get_custom(self.__vim, source.name).get("sorters", source.sorters)
            source.converters = get_custom(self.__vim, source.name).get("converters", source.converters)

            self.__sources[source.name] = source
            self.debug("Loaded Source: %s (%s)", name, module.__file__)
Пример #14
0
    def gather_candidates(self, context):
        globs = globruntime(self.vim.options['runtimepath'],
                            'bin/complete.fish')

        if not self.__executable_fish or not globs or not context['input']:
            return []

        try:
            process = subprocess.run(['fish', globs[0], context['input']],
                                     timeout=0.5,
                                     capture_output=True,
                                     check=True)
            output = process.stdout
        except subprocess.SubprocessError:
            return []

        lines = [
            line.decode(context['encoding']).split("\t")
            for line in output.splitlines()
        ]

        result = []

        for line in lines:
            if len(line) > 1:
                result.append({'word': line[0], 'menu': line[1]})
            else:
                result.append({'word': line[0]})

        return result
Пример #15
0
    def gather_candidates(self, context):
        capture = globruntime(self.vim.options['runtimepath'],
                              'bin/capture.zsh')
        if not self.__executable_zsh or not capture or not context['input']:
            return []

        result = []
        try:
            for pieces in [
                    x.decode(context['encoding']).rpartition(' -- ')
                    for x in subprocess.check_output(
                        ['zsh', capture[0], context['input']],
                        cwd=self.vim.call('getcwd'),
                        timeout=1.2,
                    ).splitlines()
            ]:
                if not pieces[1]:
                    result.append({'word': pieces[-1].strip()})
                if pieces[-1].strip():
                    for piece in pieces[0].split():
                        result.append({
                            'word': piece.strip(),
                            'info': pieces[-1],
                        })
        except subprocess.SubprocessError:
            return []
        return result
Пример #16
0
 def _init_cpsm(self, context):
     ext = '.pyd' if context['is_windows'] else '.so'
     fname = 'bin/cpsm_py' + ext
     found = globruntime(self.vim.options['runtimepath'], fname)
     errmsg = None
     if found:
         sys.path.insert(0, os.path.dirname(found[0]))
         try:
             import cpsm_py
         except ImportError as exc:
             import traceback
             errmsg = 'Could not import cpsm_py: %s\n%s' % (
                 exc, traceback.format_exc())
         else:
             self._cpsm = cpsm_py
         finally:
             sys.path.pop(0)
     else:
         errmsg = (
             '%s was not found in runtimepath. '
             'You must install/build cpsm with Python 3 support.' % (
                 fname))
     if errmsg:
         self._cpsm = False
     return errmsg
Пример #17
0
 def load_sources(self):
     # Load sources from runtimepath
     for path in globruntime(self.vim, "rplugin/python3/deoplete/sources/base.py") + globruntime(
         self.vim, "rplugin/python3/deoplete/sources/*.py"
     ):
         name = os.path.basename(path)[:-3]
         source = importlib.machinery.SourceFileLoader("deoplete.sources." + name, path).load_module()
         if hasattr(source, "Source") and not name in self.sources:
             self.sources[name] = source.Source(self.vim)
Пример #18
0
 def load_filters(self):
     # Load filters from runtimepath
     for path in globruntime(self.vim, "rplugin/python3/deoplete/filters/base.py") + globruntime(
         self.vim, "rplugin/python3/deoplete/filters/*.py"
     ):
         name = os.path.basename(path)[:-3]
         filter = importlib.machinery.SourceFileLoader("deoplete.filters." + name, path).load_module()
         if hasattr(filter, "Filter") and not name in self.filters:
             self.filters[name] = filter.Filter(self.vim)
Пример #19
0
 def load_filters(self):
     # Load filters from runtimepath
     for path in globruntime(self.__vim, "rplugin/python3/deoplete/filters/base.py") + globruntime(
         self.__vim, "rplugin/python3/deoplete/filters/*.py"
     ):
         name = os.path.basename(path)[:-3]
         module = importlib.machinery.SourceFileLoader("deoplete.filters." + name, path).load_module()
         if hasattr(module, "Filter") and name not in self.__filters:
             filter = module.Filter(self.__vim)
             self.__filters[filter.name] = filter
             self.debug("Loaded Filter: %s (%s)", name, module.__file__)
Пример #20
0
    def load_sources(self):
        # Load sources from runtimepath
        for path in globruntime(
                self.__vim,
                'rplugin/python3/deoplete/sources/base.py') + globruntime(
                    self.__vim, 'rplugin/python3/deoplete/sources/*.py'):
            name = os.path.basename(path)[:-3]
            module = importlib.machinery.SourceFileLoader(
                'deoplete.sources.' + name, path).load_module()
            if not hasattr(module, 'Source') or name in self.__sources:
                continue

            source = module.Source(self.__vim)

            # Set the source attributes.
            source.filetypes = get_custom(self.__vim, source.name).get(
                'filetypes', source.filetypes)
            source.disabled_syntaxes = get_custom(self.__vim, source.name).get(
                'disabled_syntaxes', source.disabled_syntaxes)
            source.input_pattern = get_custom(self.__vim, source.name).get(
                'input_pattern', source.input_pattern)
            source.min_pattern_length = get_custom(
                self.__vim, source.name).get('min_pattern_length',
                                             source.min_pattern_length)
            source.max_pattern_length = get_custom(
                self.__vim, source.name).get('max_pattern_length',
                                             source.max_pattern_length)
            source.max_abbr_width = get_custom(self.__vim, source.name).get(
                'max_abbr_width', source.max_abbr_width)
            source.max_menu_width = get_custom(self.__vim, source.name).get(
                'max_menu_width', source.max_menu_width)
            source.matchers = get_custom(self.__vim, source.name).get(
                'matchers', source.matchers)
            source.sorters = get_custom(self.__vim, source.name).get(
                'sorters', source.sorters)
            source.converters = get_custom(self.__vim, source.name).get(
                'converters', source.converters)

            self.__sources[source.name] = source
            self.debug('Loaded Source: %s (%s)', name, module.__file__)
Пример #21
0
    def load_sources(self, context):
        # Load sources from runtimepath
        for path in globruntime(context['runtimepath'],
                                'rplugin/python3/deoplete/source/base.py'
                                ) + globruntime(
                                    context['runtimepath'],
                                    'rplugin/python3/deoplete/source/*.py'
                                ) + globruntime(
                                    context['runtimepath'],
                                    'rplugin/python3/deoplete/sources/*.py'
                                ):
            filename = os.path.basename(path)[: -3]
            module = importlib.machinery.SourceFileLoader(
                'deoplete.source.' + filename, path).load_module()
            self.debug(path)
            if not hasattr(module, 'Source') or filename in self.__sources:
                continue

            source = module.Source(self.__vim)
            source.name = getattr(
                source, 'name', filename)
            source.min_pattern_length = getattr(
                source, 'min_pattern_length',
                context['vars']['deoplete#auto_complete_start_length'])
            source.max_abbr_width = getattr(
                source, 'max_abbr_width',
                context['vars']['deoplete#max_abbr_width'])
            source.max_menu_width = getattr(
                source, 'max_menu_width',
                context['vars']['deoplete#max_menu_width'])

            self.__sources[source.name] = source
            self.debug('Loaded Source: %s (%s)',
                       source.name, module.__file__)

        self.set_source_attributes(context)
        self.__custom = context['custom']
Пример #22
0
    def gather_candidates(self, context):
        capture = globruntime(self.vim.options['runtimepath'],
                              'bin/capture.zsh')
        if not self.__executable_zsh or not capture or not context['input']:
            return []

        result = []
        try:
            for pieces in [x.decode(context['encoding']).split(' -- ')
                           for x in subprocess.check_output(
                               ['zsh', capture[0], context['input']],
                               cwd=self.vim.call('getcwd'),
                               timeout=1.0).splitlines()]:
                if len(pieces) > 1:
                    result.append({ 'word': pieces[0], 'menu': pieces[1] })
                else:
                    result.append({ 'word': pieces[0] })
        except subprocess.SubprocessError:
            return []
        return result
Пример #23
0
 def _init_fruzzy(self, context):
     ext = '.pyd' if context['is_windows'] else '.so'
     fname = 'rplugin/python3/fruzzy_mod' + ext
     found = globruntime(self.vim.options['runtimepath'], fname)
     errmsg = None
     if found:
         sys.path.insert(0, os.path.dirname(found[0]))
         try:
             import fruzzy_mod
         except ImportError as exc:
             import traceback
             errmsg = 'Could not import fruzzy: %s\n%s' % (
                 exc, traceback.format_exc())
         else:
             self.fruzzy = fruzzy_mod.scoreMatchesStr
         finally:
             sys.path.pop(0)
     else:
         errmsg = ('%s was not found in runtimepath. '
                   'You must install/build fruzzy with Python 3 support.' %
                   (fname))
     if errmsg:
         self.fruzzy = False
     return errmsg
Пример #24
0
 def test_globruntime(self):
     eq_(globruntime('/usr', 'bin'), ['/usr/bin'])
Пример #25
0
def test_globruntime():
    assert util.globruntime('/usr', 'bin') == ['/usr/bin']
Пример #26
0
def test_globruntime():
    assert util.globruntime('/usr', 'bin') == ['/usr/bin']
Пример #27
0
 def test_globruntime(self):
     eq_(globruntime('/usr', 'lib'), ['/usr/lib'])
Пример #28
0
 def test_globruntime(self):
     eq_(globruntime('/usr', 'lib'), ['/usr/lib'])