Пример #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 []

        import cpsm_py
        candidates = context['candidates']
        ispath = (os.path.exists(context['candidates'][0]['word']))
        for pattern in split_input(context['input']):
            cpsm_result = cpsm_py.ctrlp_match((d['word'] for d in candidates),
                                              pattern,
                                              limit=1000,
                                              ispath=ispath)[0]
            candidates = [x for x in candidates if x['word'] in cpsm_result]
        return candidates
Пример #2
0
    def gather_candidates(self, context):
        if context['event'] == 'interactive':
            # Update input
            self.on_close(context)

            if not context['input']:
                return []

            context['__patterns'] = [
                '.*'.join(util.split_input(context['input']))
            ]

        if context['__proc']:
            return self._async_gather_candidates(context,
                                                 context['async_timeout'])

        if not context['__patterns']:
            return []

        args = [
            'bundle', 'exec', 'i18n_flow', 'search', '--format=oneline',
            '--nocolor'
        ]
        args += context['__patterns']

        self.print_message(context, args)

        context['__config_base_path'] = self._base_path()

        context['__proc'] = process.Process(args, context, context['path'])
        return self._async_gather_candidates(context, 0.5)
Пример #3
0
    def gather_candidates(self, context):
        if context['event'] == 'interactive':
            # Update input
            self.on_close(context)

            if not context['input']:
                return []

            context['__patterns'] = [
                '.*'.join(util.split_input(context['input']))]

        if context['__proc']:
            return self._async_gather_candidates(
                context, context['async_timeout'])

        if not context['__patterns']:
            return []

        args = ['bundle', 'exec', 'i18n_flow', 'search', '--format=oneline', '--nocolor']
        args += context['__patterns']

        self.print_message(context, args)

        context['__config_base_path'] = self._base_path()

        context['__proc'] = process.Process(args, context, context['path'])
        return self._async_gather_candidates(context, 0.5)
Пример #4
0
    def gather_candidates(self, context: UserContext) -> Candidates:
        if context['event'] == 'interactive':
            # Update input
            self.on_close(context)

            if (not context['input'] or len(context['input']) <
                    self.vars['min_interactive_pattern']):
                return []

            context['__patterns'] = [
                '.*'.join(util.split_input(context['input']))
            ]

        if context['__proc']:
            return self._async_gather_candidates(context,
                                                 context['async_timeout'])

        if not context['__patterns'] or not self.vars['command']:
            return []

        args = self._init_grep_args(context)
        self.print_message(context, args)

        context['__proc'] = process.Process(args, context, context['path'])
        return self._async_gather_candidates(context, 0.5)
Пример #5
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
            if globruntime(context['runtimepath'], 'bin/cpsm_py.so'):
                # Add path
                sys.path.append(os.path.dirname(
                    globruntime(context['runtimepath'], 'bin/cpsm_py.so')[0]))
                self.__initialized = True
            else:
                error(self.vim, 'matcher_cpsm: bin/cpsm_py.so' +
                      ' is not found in your runtimepath.')
                error(self.vim, 'matcher_cpsm: You must install/build' +
                      ' Python3 support enabled cpsm.')
                self.__disabled = True
                return []

        import cpsm_py
        candidates = context['candidates']
        max = context['max_candidate_width']
        ispath = (os.path.exists(context['candidates'][0]['word']))
        for pattern in split_input(context['input']):
            cpsm_result = cpsm_py.ctrlp_match(
                (d['word'][:max] for d in candidates),
                pattern, limit=1000, ispath=ispath)[0]
            candidates = [x for x in candidates if x['word'] in cpsm_result]
        return candidates
Пример #6
0
    def filter(self, context: UserContext) -> Candidates:
        if len(context['input']) < 1:
            return context['candidates']  # type: ignore
        for c in context['candidates']:
            c['filter__rank'] = 0

        for pattern in split_input(context['input']):
            for c in context['candidates']:
                c['filter__rank'] += get_score(c['word'], pattern)
        return sorted(context['candidates'], key=lambda x: x['filter__rank'])
Пример #7
0
    def filter(self, context):
        if len(context['input']) < 1:
            return context['candidates']
        for c in context['candidates']:
            c['filter__rank'] = 0

        for pattern in split_input(context['input']):
            for c in context['candidates']:
                c['filter__rank'] += get_score(c['word'], pattern)
        return sorted(context['candidates'],
                      key=lambda x: x['filter__rank'])
Пример #8
0
 def filter(self, context):
     if context["input"] == "":
         return context["candidates"]
     candidates = context["candidates"]
     max = context["max_candidate_width"]
     for pattern in split_input(context["input"]):
         try:
             p = re.compile(pattern, flags=re.IGNORECASE if context["ignorecase"] else 0)
         except Exception:
             return []
         candidates = [x for x in candidates if p.search(x["word"][:max])]
     return candidates
Пример #9
0
 def filter(self, context):
     if context['input'] == '':
         return context['candidates']
     candidates = context['candidates']
     for pattern in split_input(context['input']):
         try:
             p = re.compile(
                 pattern,
                 flags=re.IGNORECASE if context['ignorecase'] else 0)
         except Exception:
             return []
         candidates = [x for x in candidates if p.search(x['word'])]
     return candidates
Пример #10
0
 def match_candidates(self, context, matchers):
     for pattern in split_input(context['input']):
         ctx = copy.copy(context)
         if pattern and pattern[0] == '!':
             if pattern == '!':
                 continue
             ctx['input'] = pattern[1:]
             ignore = self.call_matchers(ctx, matchers)
             context['candidates'] = [x for x in context['candidates']
                                      if x not in ignore]
         else:
             ctx['input'] = pattern
             context['candidates'] = self.call_matchers(ctx, matchers)
Пример #11
0
 def match_candidates(self, context, matchers):
     for pattern in split_input(context['input']):
         ctx = copy.copy(context)
         if pattern[0] == '!':
             if pattern == '!':
                 continue
             ctx['input'] = pattern[1:]
             ignore = self.call_matchers(ctx, matchers)
             context['candidates'] = [x for x in context['candidates']
                                      if x not in ignore]
         else:
             ctx['input'] = pattern
             context['candidates'] = self.call_matchers(ctx, matchers)
Пример #12
0
 def _match_candidates(self, context: UserContext,
                       matchers: typing.List[typing.Any]) -> None:
     for pattern in split_input(context['input']):
         ctx = copy.copy(context)
         if pattern and pattern[0] == '!':
             if pattern == '!':
                 continue
             ctx['input'] = pattern[1:]
             ignore = self._call_matchers(ctx, matchers)
             context['candidates'] = [x for x in context['candidates']
                                      if x not in ignore]
         else:
             ctx['input'] = pattern
             context['candidates'] = self._call_matchers(ctx, matchers)
Пример #13
0
 def filter(self, context):
     candidates = context['candidates']
     ignorecase = context['ignorecase']
     if context['input'] == '':
         return candidates
     for pattern in split_input(context['input']):
         if ignorecase:
             pattern = pattern.lower()
             candidates = [
                 x for x in candidates if pattern in x['word'].lower()
             ]
         else:
             candidates = [x for x in candidates if pattern in x['word']]
     return candidates
Пример #14
0
 def filter(self, context):
     if context['input'] == '':
         return context['candidates']
     candidates = context['candidates']
     for pattern in split_input(context['input']):
         if context['ignorecase']:
             pattern = pattern.lower()
         p = re.compile(escape_fuzzy(re.escape(pattern), True))
         if context['ignorecase']:
             candidates = [
                 x for x in candidates if p.search(x['word'].lower())
             ]
         else:
             candidates = [x for x in candidates if p.search(x['word'])]
     return candidates
Пример #15
0
 def filter(self, context):
     if context['input'] == '':
         return context['candidates']
     candidates = context['candidates']
     max = context['max_candidate_width']
     for pattern in split_input(context['input']):
         if context['ignorecase']:
             pattern = pattern.lower()
         p = re.compile(escape_fuzzy(re.escape(pattern), True))
         if context['ignorecase']:
             candidates = [x for x in candidates
                           if p.search(x['word'][:max].lower())]
         else:
             candidates = [x for x in candidates
                           if p.search(x['word'][:max])]
     return candidates
Пример #16
0
    def _init_args(self, context: UserContext) -> typing.List[str]:
        patterns = ['.*'.join(util.split_input(context['input']))]

        args = [util.expand(self.vars['command'][0])]
        args += self.vars['command'][1:]
        args += self.vars['default_opts']
        if self.vars['pattern_opt']:
            for pattern in patterns:
                args += self.vars['pattern_opt'] + [pattern]
            args += self.vars['separator']
        else:
            args += self.vars['separator']
            args += patterns
        args.append(context['__path'])
        args += self.vars['final_opts']
        return args
Пример #17
0
    def gather_candidates(self, context):
        if context['event'] == 'interactive':
            # Update input
            self.on_close(context)

            if (not context['input'] or len(context['input']) <
                    self.vars['min_interactive_pattern']):
                return []

            context['__patterns'] = [
                '.*'.join(util.split_input(context['input']))
            ]

        if context['__proc']:
            return self._async_gather_candidates(context,
                                                 context['async_timeout'])

        if not context['__patterns'] or not self.vars['command']:
            return []

        args = [util.expand(self.vars['command'][0])]
        args += self.vars['command'][1:]
        args += self.vars['default_opts']
        args += self.vars['recursive_opts']
        args += context['__arguments']
        if self.vars['pattern_opt']:
            for pattern in context['__patterns']:
                args += self.vars['pattern_opt'] + [pattern]
            args += self.vars['separator']
        else:
            args += self.vars['separator']
            args += context['__patterns']
        if context['__paths']:
            args += context['__paths']
        else:
            args += self.vars['final_opts']

        self.print_message(context, args)

        context['__proc'] = process.Process(args, context, context['path'])
        return self._async_gather_candidates(context, 0.5)
Пример #18
0
    def init_grep_args(self, context: UserContext) -> typing.List[str]:
        patterns = ['.*'.join(split_input(context['input']))]

        # Backwards compatibility for `ack`
        if (self.vars['grep_command'] and self.vars['grep_command'][0] == 'ack'
                and self.vars['grep_pattern_opt'] == ['-e']):
            self.vars['grep_pattern_opt'] = ['--match']

        args = [expand(self.vars['grep_command'][0])]
        args += self.vars['grep_command'][1:]
        args += self.vars['grep_default_opts']
        if self.vars['grep_pattern_opt']:
            for pattern in patterns:
                args += self.vars['grep_pattern_opt'] + [pattern]
            args += self.vars['grep_separator']
        else:
            args += self.vars['grep_separator']
            args += patterns
        args.append(context['__path'])
        args += self.vars['grep_final_opts']
        return args
Пример #19
0
    def gather_candidates(self, context):
        if context['event'] == 'interactive':
            # Update input
            self.on_close(context)

            if (not context['input'] or
                    len(context['input']) <
                    self.vars['min_interactive_pattern']):
                return []

            context['__patterns'] = [
                '.*'.join(util.split_input(context['input']))]

        if context['__proc']:
            return self._async_gather_candidates(
                context, context['async_timeout'])

        if not context['__patterns'] or not self.vars['command']:
            return []

        args = [util.expand(self.vars['command'][0])]
        args += self.vars['command'][1:]
        args += self.vars['default_opts']
        args += self.vars['recursive_opts']
        args += context['__arguments']
        if self.vars['pattern_opt']:
            for pattern in context['__patterns']:
                args += self.vars['pattern_opt'] + [pattern]
            args += self.vars['separator']
        else:
            args += self.vars['separator']
            args += context['__patterns']
        if context['__paths']:
            args += context['__paths']
        args += self.vars['final_opts']

        self.print_message(context, args)

        context['__proc'] = process.Process(args, context, context['path'])
        return self._async_gather_candidates(context, 0.5)
Пример #20
0
    def gather_candidates(self, context):
        if context["event"] == "interactive":
            self.on_close(context)
            context["__query"] = context["input"]

        if context["__proc"]:
            return self._async_gather_candidates(context,
                                                 context["async_timeout"])

        if not self.vars["command"]:
            return [{"word": "No hoogle command configured."}]

        args = [util.expand(self.vars["command"][0])]
        args += self.vars["command"][1:]
        args += self.vars["default_opts"]
        args.append("--")
        if context["__query"]:
            args += util.split_input(context["__query"])

        self.print_message(context, args)

        context["__proc"] = process.Process(args, context, context["path"])
        return self._async_gather_candidates(context, 0.5)
 def convert_pattern(self, input_str):
     return '|'.join([re.escape(x) for x in split_input(input_str)])
Пример #22
0
 def convert_pattern(self, input_str):
     return '|'.join([re.escape(x) for x in split_input(input_str)])
Пример #23
0
def test_split_input():
    assert util.split_input('abc def') == ['abc', 'def']
    assert util.split_input('') == ['']
    assert util.split_input('abc\ def') == ['abc def']