コード例 #1
0
    def gather_candidates(self, context):
        if self.__use_previous_result(context):
            return self.__prev_candidates

        try:
            candidates = self.vim.call(
                self.__omnifunc, 0, context['complete_str'])
            if candidates is dict:
                candidates = candidates['words']
            elif candidates is int:
                candidates = []
        except:
            error_vim(self.vim,
                      'Error occurred calling omnifunction: ' +
                      self.__omnifunc)
            candidates = []

        candidates = convert2candidates(candidates)

        for candidate in candidates:
            candidate['dup'] = 1

        self.__prev_linenr = context['position'][1]
        self.__prev_pos = context['complete_position']
        self.__prev_input = context['input']
        self.__prev_candidates = candidates

        return candidates
コード例 #2
0
ファイル: child.py プロジェクト: noahgamboa/vim_runtime
 def _gather_async_results(self, result, source):
     try:
         context = result['context']
         context['is_refresh'] = False
         async_candidates = source.gather_candidates(context)
         result['is_async'] = context['is_async']
         if async_candidates is None:
             return
         context['candidates'] += convert2candidates(async_candidates)
     except Exception as exc:
         self._handle_source_exception(source, exc)
コード例 #3
0
 def _gather_async_results(self, result, source):
     try:
         context = result['context']
         context['is_refresh'] = False
         async_candidates = source.gather_candidates(context)
         result['is_async'] = context['is_async']
         if async_candidates is None:
             return
         context['candidates'] += convert2candidates(async_candidates)
     except Exception as exc:
         self._handle_source_exception(source, exc)
コード例 #4
0
 def _gather_async_results(self, result: Result,
                           source: typing.Any) -> None:
     try:
         context = result['context']
         context['is_refresh'] = False
         context['vars'] = self._vim.vars
         async_candidates = source.gather_candidates(context)
         context['vars'] = None
         result['is_async'] = context['is_async']
         if async_candidates is None:
             return
         context['candidates'] += convert2candidates(async_candidates)
     except Exception as exc:
         self._handle_source_exception(source, exc)
コード例 #5
0
ファイル: omni.py プロジェクト: piersy/deoplete.nvim
    def gather_candidates(self, context):
        try:
            candidates = self.vim.call(self._omnifunc, 0, '')
            if isinstance(candidates, dict):
                candidates = candidates['words']
            elif not isinstance(candidates, list):
                candidates = []
        except Exception:
            candidates = []

        candidates = convert2candidates(candidates)

        for candidate in candidates:
            candidate['dup'] = 1

        return candidates
コード例 #6
0
ファイル: omni.py プロジェクト: dingjingmaster/vimrc
    def gather_candidates(self, context):
        try:
            candidates = self.vim.call(self.__omnifunc, 0, '')
            if candidates is dict:
                candidates = candidates['words']
            elif candidates is int:
                candidates = []
        except Exception as e:
            self.print_error('Error occurred calling omnifunction: ' +
                             self.__omnifunc)
            candidates = []

        candidates = convert2candidates(candidates)

        for candidate in candidates:
            candidate['dup'] = 1

        return candidates
コード例 #7
0
ファイル: omni.py プロジェクト: epeli/vimconfig
    def gather_candidates(self, context):
        try:
            candidates = self.vim.call(self._omnifunc, 0, '')
            if isinstance(candidates, dict):
                candidates = candidates['words']
            elif not isinstance(candidates, list):
                candidates = []
        except Exception as e:
            self.print_error('Error occurred calling omnifunction: ' +
                             self._omnifunc)
            candidates = []

        candidates = convert2candidates(candidates)

        for candidate in candidates:
            candidate['dup'] = 1

        return candidates
コード例 #8
0
ファイル: omni.py プロジェクト: N0hbdy/.dotfiles
    def gather_candidates(self, context):
        try:
            candidates = self.vim.call(self.__omnifunc, 0, '')
            if candidates is dict:
                candidates = candidates['words']
            elif candidates is int:
                candidates = []
        except:
            error_vim(self.vim,
                      'Error occurred calling omnifunction: ' +
                      self.__omnifunc)
            candidates = []

        candidates = convert2candidates(candidates)

        for candidate in candidates:
            candidate['dup'] = 1

        return candidates
コード例 #9
0
ファイル: child.py プロジェクト: niaralab/dotfaster
 def _gather_async_results(self, result, source):
     try:
         context = result['context']
         context['is_refresh'] = False
         async_candidates = source.gather_candidates(context)
         result['is_async'] = context['is_async']
         if async_candidates is None:
             return
         context['candidates'] += convert2candidates(async_candidates)
     except Exception:
         self._source_errors[source.name] += 1
         if source.is_silent:
             return
         if self._source_errors[source.name] > 2:
             error(self._vim, 'Too many errors from "%s". '
                   'This source is disabled until Neovim '
                   'is restarted.' % source.name)
             self._ignore_sources.append(source.name)
         else:
             error_tb(self._vim, 'Errors from: %s' % source.name)
コード例 #10
0
ファイル: child.py プロジェクト: Elv13/Config_Files
 def _gather_async_results(self, result, source):
     try:
         context = result['context']
         context['is_refresh'] = False
         async_candidates = source.gather_candidates(context)
         result['is_async'] = context['is_async']
         if async_candidates is None:
             return
         context['candidates'] += convert2candidates(async_candidates)
     except Exception as exc:
         self._source_errors[source.name] += 1
         if source.is_silent:
             return
         if self._source_errors[source.name] > 2:
             error(self._vim, 'Too many errors from "%s". '
                   'This source is disabled until Neovim '
                   'is restarted.' % source.name)
             self._ignore_sources.append(source.name)
         else:
             error_tb(self._vim, 'Error from %s: %r' % (source.name, exc))
コード例 #11
0
ファイル: omni.py プロジェクト: monnacs/dotfiles
    def gather_candidates(self, context):
        try:
            candidates = self.vim.call(self.__omnifunc, 0,
                                       context['complete_str'])
            if candidates is dict:
                candidates = candidates['words']
            elif candidates is int:
                candidates = []
        except:
            error_vim(
                self.vim,
                'Error occurred calling omnifunction: ' + self.__omnifunc)
            candidates = []

        candidates = convert2candidates(candidates)

        for candidate in candidates:
            candidate['dup'] = 1

        return candidates
コード例 #12
0
ファイル: deoplete.py プロジェクト: s3341458/common_configs
    def gather_results(self, context):
        if not self.use_previous_result(context):
            self._prev_linenr = context['position'][1]
            self._prev_input = context['input']
            self._results = {}

        results = self._results

        for source in [
                x[1] for x in self.itersource(context)
                if x[1].name not in results
        ]:
            try:
                if source.disabled_syntaxes and 'syntax_names' not in context:
                    context['syntax_names'] = get_syn_names(self._vim)
                ctx = copy.deepcopy(context)
                ctx['is_async'] = False

                charpos = source.get_complete_position(ctx)
                if charpos >= 0 and source.is_bytepos:
                    charpos = bytepos2charpos(ctx['encoding'], ctx['input'],
                                              charpos)

                ctx['char_position'] = charpos
                ctx['complete_position'] = charpos2bytepos(
                    ctx['encoding'], ctx['input'], charpos)
                ctx['complete_str'] = ctx['input'][ctx['char_position']:]

                if charpos < 0 or self.is_skip(ctx, source.disabled_syntaxes,
                                               source.min_pattern_length,
                                               source.max_pattern_length,
                                               source.input_pattern):
                    # Skip
                    continue

                ctx['max_abbr_width'] = min(source.max_abbr_width,
                                            ctx['max_abbr_width'])
                ctx['max_menu_width'] = min(source.max_menu_width,
                                            ctx['max_menu_width'])
                if ctx['max_abbr_width'] > 0:
                    ctx['max_abbr_width'] = max(20, ctx['max_abbr_width'])
                if ctx['max_menu_width'] > 0:
                    ctx['max_menu_width'] = max(10, ctx['max_menu_width'])

                # Gathering
                self.profile_start(ctx, source.name)
                ctx['candidates'] = source.gather_candidates(ctx)
                self.profile_end(source.name)

                if not ctx['is_async'] and ('candidates' not in ctx
                                            or not ctx['candidates']):
                    continue

                ctx['candidates'] = convert2candidates(ctx['candidates'])

                results[source.name] = {
                    'name': source.name,
                    'source': source,
                    'context': ctx,
                    'is_async': ctx['is_async'],
                }
            except Exception:
                self._source_errors[source.name] += 1
                if self._source_errors[source.name] > 2:
                    error(
                        self._vim, 'Too many errors from "%s". '
                        'This source is disabled until Neovim '
                        'is restarted.' % source.name)
                    self._ignored_sources.add(source.path)
                    self._sources.pop(source.name)
                    continue
                error_tb(self._vim,
                         'Could not get completions from: %s' % source.name)

        return results.values()
コード例 #13
0
ファイル: deoplete.py プロジェクト: apierz/dotfiles
    def gather_results(self, context):
        results = []

        for source_name, source in self.itersource(context):
            try:
                if source.disabled_syntaxes and 'syntax_names' not in context:
                    context['syntax_names'] = get_syn_names(self._vim)
                ctx = copy.deepcopy(context)
                charpos = source.get_complete_position(ctx)
                if charpos >= 0 and source.is_bytepos:
                    charpos = bytepos2charpos(
                        ctx['encoding'], ctx['input'], charpos)
                ctx['complete_str'] = ctx['input'][charpos:]
                ctx['complete_position'] = charpos2bytepos(
                    ctx['encoding'], ctx['input'], charpos)
                ctx['max_abbr_width'] = min(source.max_abbr_width,
                                            ctx['max_abbr_width'])
                ctx['max_menu_width'] = min(source.max_menu_width,
                                            ctx['max_menu_width'])
                if ctx['max_abbr_width'] > 0:
                    ctx['max_abbr_width'] = max(20, ctx['max_abbr_width'])
                if ctx['max_menu_width'] > 0:
                    ctx['max_menu_width'] = max(10, ctx['max_menu_width'])

                if charpos < 0 or self.is_skip(ctx, source.disabled_syntaxes,
                                               source.min_pattern_length,
                                               source.max_pattern_length,
                                               source.input_pattern):
                    # Skip
                    continue

                # Gathering
                self.profile_start(ctx, source.name)
                ctx['candidates'] = source.gather_candidates(ctx)
                self.profile_end(source.name)

                if 'candidates' not in ctx or not ctx['candidates']:
                    continue

                ctx['candidates'] = convert2candidates(ctx['candidates'])

                # Filtering
                ignorecase = ctx['ignorecase']
                smartcase = ctx['smartcase']
                camelcase = ctx['camelcase']

                # Set ignorecase
                if (smartcase or camelcase) and re.search(
                        r'[A-Z]', ctx['complete_str']):
                    ctx['ignorecase'] = 0

                filters = source.matchers + source.sorters + source.converters
                for f in [self._filters[x] for x
                          in filters if x in self._filters]:
                    try:
                        self.profile_start(ctx, f.name)
                        ctx['candidates'] = f.filter(ctx)
                        self.profile_end(f.name)
                    except Exception:
                        self._filter_errors[f.name] += 1
                        if self._source_errors[f.name] > 2:
                            error(self._vim, 'Too many errors from "%s". '
                                  'This filter is disabled until Neovim '
                                  'is restarted.' % f.name)
                            self._ignored_filters.add(f.path)
                            self._filters.pop(f.name)
                            continue
                        error_tb(self._vim, 'Could not filter using: %s' % f)

                ctx['ignorecase'] = ignorecase

                # On post filter
                if hasattr(source, 'on_post_filter'):
                    ctx['candidates'] = source.on_post_filter(ctx)

                # Set default menu and icase
                mark = source.mark + ' '
                for candidate in ctx['candidates']:
                    candidate['icase'] = 1
                    if (source.mark != '' and
                            candidate.get('menu', '').find(mark) != 0):
                        candidate['menu'] = mark + candidate.get('menu', '')
                    if source.filetypes:
                        candidate['dup'] = 1

                results.append({
                    'name': source_name,
                    'source': source,
                    'context': ctx,
                })
            except Exception:
                self._source_errors[source_name] += 1
                if self._source_errors[source_name] > 2:
                    error(self._vim, 'Too many errors from "%s". '
                          'This source is disabled until Neovim '
                          'is restarted.' % source_name)
                    self._ignored_sources.add(source.path)
                    self._sources.pop(source_name)
                    continue
                error_tb(self._vim,
                         'Could not get completions from: %s' % source_name)
        return results
コード例 #14
0
    def _get_result(self, context, source):
        if source.disabled_syntaxes and 'syntax_names' not in context:
            context['syntax_names'] = get_syn_names(self._vim)

        ctx = copy.deepcopy(context)

        charpos = source.get_complete_position(ctx)
        if charpos >= 0 and source.is_bytepos:
            charpos = bytepos2charpos(ctx['encoding'], ctx['input'], charpos)

        ctx['char_position'] = charpos
        ctx['complete_position'] = charpos2bytepos(ctx['encoding'],
                                                   ctx['input'], charpos)
        ctx['complete_str'] = ctx['input'][ctx['char_position']:]

        if charpos < 0 or self._is_skip(ctx, source):
            if source.name in self._prev_results:
                self._prev_results.pop(source.name)
            # Skip
            return {}

        if (source.name in self._prev_results and self._use_previous_result(
                context, self._prev_results[source.name], source.is_volatile)):
            return self._prev_results[source.name]

        ctx['is_async'] = False
        ctx['is_refresh'] = True
        ctx['max_abbr_width'] = min(source.max_abbr_width,
                                    ctx['max_abbr_width'])
        ctx['max_kind_width'] = min(source.max_kind_width,
                                    ctx['max_kind_width'])
        ctx['max_menu_width'] = min(source.max_menu_width,
                                    ctx['max_menu_width'])
        if ctx['max_abbr_width'] > 0:
            ctx['max_abbr_width'] = max(20, ctx['max_abbr_width'])
        if ctx['max_kind_width'] > 0:
            ctx['max_kind_width'] = max(10, ctx['max_kind_width'])
        if ctx['max_menu_width'] > 0:
            ctx['max_menu_width'] = max(10, ctx['max_menu_width'])

        # Gathering
        self._profile_start(ctx, source.name)
        ctx['candidates'] = source.gather_candidates(ctx)
        self._profile_end(source.name)

        if ctx['candidates'] is None:
            return {}

        ctx['candidates'] = convert2candidates(ctx['candidates'])

        return {
            'name': source.name,
            'source': source,
            'context': ctx,
            'is_async': ctx['is_async'],
            'prev_linenr': ctx['position'][1],
            'prev_input': ctx['input'],
            'input': ctx['input'],
            'complete_position': ctx['complete_position'],
            'candidates': ctx['candidates'],
        }
コード例 #15
0
ファイル: deoplete.py プロジェクト: N0hbdy/.dotfiles
    def gather_results(self, context):
        results = []

        for source in [x[1] for x in self.itersource(context)]:
            try:
                if source.disabled_syntaxes and 'syntax_names' not in context:
                    context['syntax_names'] = get_syn_names(self._vim)
                ctx = copy.deepcopy(context)
                ctx['is_async'] = False

                charpos = source.get_complete_position(ctx)
                if charpos >= 0 and source.is_bytepos:
                    charpos = bytepos2charpos(
                        ctx['encoding'], ctx['input'], charpos)

                ctx['char_position'] = charpos
                ctx['complete_position'] = charpos2bytepos(
                    ctx['encoding'], ctx['input'], charpos)
                ctx['complete_str'] = ctx['input'][ctx['char_position']:]

                if charpos < 0 or self.is_skip(ctx, source):
                    if source.name in self._prev_results:
                        self._prev_results.pop(source.name)
                    # Skip
                    continue

                if (not source.is_volatile and
                        source.name in self._prev_results and
                        self.use_previous_result(
                            context, self._prev_results[source.name])):
                    results.append(self._prev_results[source.name])
                    continue

                ctx['max_abbr_width'] = min(source.max_abbr_width,
                                            ctx['max_abbr_width'])
                ctx['max_menu_width'] = min(source.max_menu_width,
                                            ctx['max_menu_width'])
                if ctx['max_abbr_width'] > 0:
                    ctx['max_abbr_width'] = max(20, ctx['max_abbr_width'])
                if ctx['max_menu_width'] > 0:
                    ctx['max_menu_width'] = max(10, ctx['max_menu_width'])

                # Gathering
                self.profile_start(ctx, source.name)
                ctx['candidates'] = source.gather_candidates(ctx)
                self.profile_end(source.name)

                if ctx['candidates'] is None:
                    continue

                ctx['candidates'] = convert2candidates(ctx['candidates'])

                result = {
                    'name': source.name,
                    'source': source,
                    'context': ctx,
                    'is_async': ctx['is_async'],
                    'prev_linenr': ctx['position'][1],
                    'prev_input': ctx['input'],
                }
                self._prev_results[source.name] = result
                results.append(result)
            except Exception:
                self._source_errors[source.name] += 1
                if self._source_errors[source.name] > 2:
                    error(self._vim, 'Too many errors from "%s". '
                          'This source is disabled until Neovim '
                          'is restarted.' % source.name)
                    self._ignored_sources.add(source.path)
                    self._sources.pop(source.name)
                    continue
                error_tb(self._vim,
                         'Could not get completions from: %s' % source.name)

        return results
コード例 #16
0
ファイル: deoplete.py プロジェクト: N0hbdy/.dotfiles
    def merge_results(self, results, context_input):
        merged_results = []
        all_candidates = []
        for result in [x for x in results
                       if not self.is_skip(x['context'], x['source'])]:
            source = result['source']

            # Gather async results
            if result['is_async']:
                async_candidates = source.gather_candidates(
                    result['context'])
                result['is_async'] = result['context']['is_async']
                if async_candidates is None:
                    continue
                result['context']['candidates'] += convert2candidates(
                    async_candidates)

            if not result['context']['candidates']:
                continue

            context = copy.deepcopy(result['context'])

            context['input'] = context_input
            context['complete_str'] = context['input'][
                context['char_position']:]
            context['is_sorted'] = False

            # Filtering
            ignorecase = context['ignorecase']
            smartcase = context['smartcase']
            camelcase = context['camelcase']

            # Set ignorecase
            if (smartcase or camelcase) and re.search(
                    r'[A-Z]', context['complete_str']):
                context['ignorecase'] = 0

            for f in [self._filters[x] for x
                      in source.matchers + source.sorters + source.converters
                      if x in self._filters]:
                try:
                    self.profile_start(context, f.name)
                    if (isinstance(context['candidates'], dict) and
                            'sorted_candidates' in context['candidates']):
                        context_candidates = []
                        sorted_candidates = context['candidates'][
                            'sorted_candidates']
                        context['is_sorted'] = True
                        for candidates in sorted_candidates:
                            context['candidates'] = candidates
                            context_candidates += f.filter(context)
                        context['candidates'] = context_candidates
                    else:
                        context['candidates'] = f.filter(context)
                    self.profile_end(f.name)
                except Exception:
                    self._filter_errors[f.name] += 1
                    if self._source_errors[f.name] > 2:
                        error(self._vim, 'Too many errors from "%s". '
                              'This filter is disabled until Neovim '
                              'is restarted.' % f.name)
                        self._ignored_filters.add(f.path)
                        self._filters.pop(f.name)
                        continue
                    error_tb(self._vim, 'Could not filter using: %s' % f)

            context['ignorecase'] = ignorecase

            # On post filter
            if hasattr(source, 'on_post_filter'):
                context['candidates'] = source.on_post_filter(context)

            if context['candidates']:
                merged_results.append([context['candidates'], result])

        is_async = len([x for x in results if x['context']['is_async']]) > 0

        if not merged_results:
            return (is_async, -1, [])

        complete_position = min([x[1]['context']['complete_position']
                                 for x in merged_results])

        for [candidates, result] in merged_results:
            context = result['context']
            source = result['source']
            prefix = context['input'][
                complete_position:context['complete_position']]

            mark = source.mark + ' '
            for candidate in candidates:
                # Add prefix
                candidate['word'] = prefix + candidate['word']

                # Set default menu and icase
                candidate['icase'] = 1
                if (source.mark != '' and
                        candidate.get('menu', '').find(mark) != 0):
                    candidate['menu'] = mark + candidate.get('menu', '')
                if source.filetypes:
                    candidate['dup'] = 1

            all_candidates += candidates

        # self.debug(candidates)
        if context['vars']['deoplete#max_list'] > 0:
            all_candidates = all_candidates[
                : context['vars']['deoplete#max_list']]

        return (is_async, complete_position, all_candidates)
コード例 #17
0
ファイル: jlsource.py プロジェクト: wangl-cc/juliatools-nvim
 def gather_candidates(self, context):
     base = context['input'][context['complete_position']:context['position'][2]-1]
     l = self.vim.call('juliacomplete#CompleteServer', 0, base)
     return convert2candidates(l)
コード例 #18
0
ファイル: child.py プロジェクト: niaralab/dotfaster
    def _gather_results(self, context):
        results = []

        for source in [x[1] for x in self._itersource(context)]:
            try:
                if source.disabled_syntaxes and 'syntax_names' not in context:
                    context['syntax_names'] = get_syn_names(self._vim)
                ctx = copy.deepcopy(context)

                charpos = source.get_complete_position(ctx)
                if charpos >= 0 and source.is_bytepos:
                    charpos = bytepos2charpos(
                        ctx['encoding'], ctx['input'], charpos)

                ctx['char_position'] = charpos
                ctx['complete_position'] = charpos2bytepos(
                    ctx['encoding'], ctx['input'], charpos)
                ctx['complete_str'] = ctx['input'][ctx['char_position']:]

                if charpos < 0 or self._is_skip(ctx, source):
                    if source.name in self._prev_results:
                        self._prev_results.pop(source.name)
                    # Skip
                    continue

                if (source.name in self._prev_results and
                        self._use_previous_result(
                            context, self._prev_results[source.name],
                            source.is_volatile)):
                    results.append(self._prev_results[source.name])
                    continue

                ctx['is_async'] = False
                ctx['is_refresh'] = True
                ctx['max_abbr_width'] = min(source.max_abbr_width,
                                            ctx['max_abbr_width'])
                ctx['max_kind_width'] = min(source.max_kind_width,
                                            ctx['max_kind_width'])
                ctx['max_menu_width'] = min(source.max_menu_width,
                                            ctx['max_menu_width'])
                if ctx['max_abbr_width'] > 0:
                    ctx['max_abbr_width'] = max(20, ctx['max_abbr_width'])
                if ctx['max_kind_width'] > 0:
                    ctx['max_kind_width'] = max(10, ctx['max_kind_width'])
                if ctx['max_menu_width'] > 0:
                    ctx['max_menu_width'] = max(10, ctx['max_menu_width'])

                # Gathering
                self._profile_start(ctx, source.name)
                ctx['candidates'] = source.gather_candidates(ctx)
                self._profile_end(source.name)

                if ctx['candidates'] is None:
                    continue

                ctx['candidates'] = convert2candidates(ctx['candidates'])

                result = {
                    'name': source.name,
                    'source': source,
                    'context': ctx,
                    'is_async': ctx['is_async'],
                    'prev_linenr': ctx['position'][1],
                    'prev_input': ctx['input'],
                    'input': ctx['input'],
                    'complete_position': ctx['complete_position'],
                    'candidates': ctx['candidates'],
                }
                self._prev_results[source.name] = result
                results.append(result)
            except Exception:
                self._source_errors[source.name] += 1
                if source.is_silent:
                    continue
                if self._source_errors[source.name] > 2:
                    error(self._vim, 'Too many errors from "%s". '
                          'This source is disabled until Neovim '
                          'is restarted.' % source.name)
                    self._ignore_sources.append(source.name)
                    continue
                error_tb(self._vim, 'Errors from: %s' % source.name)

        return results
コード例 #19
0
    def merge_results(self, results, context_input):
        merged_results = []
        all_candidates = []
        for result in [
                x for x in results
                if not self.is_skip(x['context'], x['source'])
        ]:
            source = result['source']

            # Gather async results
            if result['is_async']:
                async_candidates = source.gather_candidates(result['context'])
                result['is_async'] = result['context']['is_async']
                if async_candidates is None:
                    continue
                result['context']['candidates'] += convert2candidates(
                    async_candidates)

            if not result['context']['candidates']:
                continue

            context = copy.deepcopy(result['context'])

            context['input'] = context_input
            context['complete_str'] = context['input'][
                context['char_position']:]
            context['is_sorted'] = False

            # Filtering
            ignorecase = context['ignorecase']
            smartcase = context['smartcase']
            camelcase = context['camelcase']

            # Set ignorecase
            if (smartcase or camelcase) and re.search(r'[A-Z]',
                                                      context['complete_str']):
                context['ignorecase'] = 0

            for f in [
                    self._filters[x] for x in source.matchers +
                    source.sorters + source.converters if x in self._filters
            ]:
                try:
                    self.profile_start(context, f.name)
                    if (isinstance(context['candidates'], dict)
                            and 'sorted_candidates' in context['candidates']):
                        context_candidates = []
                        sorted_candidates = context['candidates'][
                            'sorted_candidates']
                        context['is_sorted'] = True
                        for candidates in sorted_candidates:
                            context['candidates'] = candidates
                            context_candidates += f.filter(context)
                        context['candidates'] = context_candidates
                    else:
                        context['candidates'] = f.filter(context)
                    self.profile_end(f.name)
                except Exception:
                    self._filter_errors[f.name] += 1
                    if self._source_errors[f.name] > 2:
                        error(
                            self._vim, 'Too many errors from "%s". '
                            'This filter is disabled until Neovim '
                            'is restarted.' % f.name)
                        self._ignored_filters.add(f.path)
                        self._filters.pop(f.name)
                        continue
                    error_tb(self._vim, 'Could not filter using: %s' % f)

            context['ignorecase'] = ignorecase

            # On post filter
            if hasattr(source, 'on_post_filter'):
                context['candidates'] = source.on_post_filter(context)

            if context['candidates']:
                merged_results.append([context['candidates'], result])

        is_async = len([x for x in results if x['context']['is_async']]) > 0

        if not merged_results:
            return (is_async, -1, [])

        complete_position = min(
            [x[1]['context']['complete_position'] for x in merged_results])

        for [candidates, result] in merged_results:
            context = result['context']
            source = result['source']
            prefix = context['input'][
                complete_position:context['complete_position']]

            mark = source.mark + ' '
            for candidate in candidates:
                # Add prefix
                candidate['word'] = prefix + candidate['word']

                # Set default menu and icase
                candidate['icase'] = 1
                if (source.mark != ''
                        and candidate.get('menu', '').find(mark) != 0):
                    candidate['menu'] = mark + candidate.get('menu', '')
                if source.filetypes:
                    candidate['dup'] = 1

            all_candidates += candidates

        # self.debug(candidates)
        if context['vars']['deoplete#max_list'] > 0:
            all_candidates = all_candidates[:context['vars']
                                            ['deoplete#max_list']]

        return (is_async, complete_position, all_candidates)
コード例 #20
0
ファイル: deoplete.py プロジェクト: samjjc/dotfiles
    def gather_results(self, context):
        results = []

        for source_name, source in self.itersource(context):
            try:
                if source.disabled_syntaxes and 'syntax_names' not in context:
                    context['syntax_names'] = get_syn_names(self._vim)
                ctx = copy.deepcopy(context)
                charpos = source.get_complete_position(ctx)
                if charpos >= 0 and source.is_bytepos:
                    charpos = bytepos2charpos(ctx['encoding'], ctx['input'],
                                              charpos)
                ctx['complete_str'] = ctx['input'][charpos:]
                ctx['complete_position'] = charpos2bytepos(
                    ctx['encoding'], ctx['input'], charpos)
                ctx['max_abbr_width'] = min(source.max_abbr_width,
                                            ctx['max_abbr_width'])
                ctx['max_menu_width'] = min(source.max_menu_width,
                                            ctx['max_menu_width'])
                if ctx['max_abbr_width'] > 0:
                    ctx['max_abbr_width'] = max(20, ctx['max_abbr_width'])
                if ctx['max_menu_width'] > 0:
                    ctx['max_menu_width'] = max(10, ctx['max_menu_width'])

                if charpos < 0 or self.is_skip(ctx, source.disabled_syntaxes,
                                               source.min_pattern_length,
                                               source.max_pattern_length,
                                               source.input_pattern):
                    # Skip
                    continue

                # Gathering
                self.profile_start(ctx, source.name)
                ctx['candidates'] = source.gather_candidates(ctx)
                self.profile_end(source.name)

                if 'candidates' not in ctx or not ctx['candidates']:
                    continue

                ctx['candidates'] = convert2candidates(ctx['candidates'])

                # Filtering
                ignorecase = ctx['ignorecase']
                smartcase = ctx['smartcase']
                camelcase = ctx['camelcase']

                # Set ignorecase
                if (smartcase or camelcase) and re.search(
                        r'[A-Z]', ctx['complete_str']):
                    ctx['ignorecase'] = 0

                filters = source.matchers + source.sorters + source.converters
                for f in [
                        self._filters[x] for x in filters if x in self._filters
                ]:
                    try:
                        self.profile_start(ctx, f.name)
                        ctx['candidates'] = f.filter(ctx)
                        self.profile_end(f.name)
                    except Exception:
                        self._filter_errors[f.name] += 1
                        if self._source_errors[f.name] > 2:
                            error(
                                self._vim, 'Too many errors from "%s". '
                                'This filter is disabled until Neovim '
                                'is restarted.' % f.name)
                            self._ignored_filters.add(f.path)
                            self._filters.pop(f.name)
                            continue
                        error_tb(self._vim, 'Could not filter using: %s' % f)

                ctx['ignorecase'] = ignorecase

                # On post filter
                if hasattr(source, 'on_post_filter'):
                    ctx['candidates'] = source.on_post_filter(ctx)

                # Set default menu and icase
                mark = source.mark + ' '
                for candidate in ctx['candidates']:
                    candidate['icase'] = 1
                    if (source.mark != ''
                            and candidate.get('menu', '').find(mark) != 0):
                        candidate['menu'] = mark + candidate.get('menu', '')
                    if source.filetypes:
                        candidate['dup'] = 1

                results.append({
                    'name': source_name,
                    'source': source,
                    'context': ctx,
                })
            except Exception:
                self._source_errors[source_name] += 1
                if self._source_errors[source_name] > 2:
                    error(
                        self._vim, 'Too many errors from "%s". '
                        'This source is disabled until Neovim '
                        'is restarted.' % source_name)
                    self._ignored_sources.add(source.path)
                    self._sources.pop(source_name)
                    continue
                error_tb(self._vim,
                         'Could not get completions from: %s' % source_name)
        return results
コード例 #21
0
ファイル: child.py プロジェクト: noahgamboa/vim_runtime
    def _get_result(self, context, source):
        if source.disabled_syntaxes and 'syntax_names' not in context:
            context['syntax_names'] = get_syn_names(self._vim)

        ctx = copy.deepcopy(context)

        charpos = source.get_complete_position(ctx)
        if charpos >= 0 and source.is_bytepos:
            charpos = bytepos2charpos(
                ctx['encoding'], ctx['input'], charpos)

        ctx['char_position'] = charpos
        ctx['complete_position'] = charpos2bytepos(
            ctx['encoding'], ctx['input'], charpos)
        ctx['complete_str'] = ctx['input'][ctx['char_position']:]

        if charpos < 0 or self._is_skip(ctx, source):
            if source.name in self._prev_results:
                self._prev_results.pop(source.name)
            # Skip
            return {}

        if (source.name in self._prev_results and
                self._use_previous_result(
                    context, self._prev_results[source.name],
                    source.is_volatile)):
            return self._prev_results[source.name]

        ctx['is_async'] = False
        ctx['is_refresh'] = True
        ctx['max_abbr_width'] = min(source.max_abbr_width,
                                    ctx['max_abbr_width'])
        ctx['max_kind_width'] = min(source.max_kind_width,
                                    ctx['max_kind_width'])
        ctx['max_info_width'] = min(source.max_info_width,
                                    ctx['max_info_width'])
        ctx['max_menu_width'] = min(source.max_menu_width,
                                    ctx['max_menu_width'])
        if ctx['max_abbr_width'] > 0:
            ctx['max_abbr_width'] = max(20, ctx['max_abbr_width'])
        if ctx['max_kind_width'] > 0:
            ctx['max_kind_width'] = max(10, ctx['max_kind_width'])
        if ctx['max_info_width'] > 0:
            ctx['max_info_width'] = max(10, ctx['max_info_width'])
        if ctx['max_menu_width'] > 0:
            ctx['max_menu_width'] = max(10, ctx['max_menu_width'])

        # Gathering
        self._profile_start(ctx, source.name)
        ctx['candidates'] = source.gather_candidates(ctx)
        self._profile_end(source.name)

        if ctx['candidates'] is None:
            return {}

        ctx['candidates'] = convert2candidates(ctx['candidates'])

        return {
            'name': source.name,
            'source': source,
            'context': ctx,
            'is_async': ctx['is_async'],
            'prev_linenr': ctx['position'][1],
            'prev_input': ctx['input'],
            'input': ctx['input'],
            'complete_position': ctx['complete_position'],
            'candidates': ctx['candidates'],
        }