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
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'], }
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
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'], }
def gather_results(self, context): results = [] for source_name, source in list(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 if ctx['candidates'] and isinstance(ctx['candidates'][0], str): # Convert to dict ctx['candidates'] = [{ 'word': x } for x in 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 for filter in [ self.__filters[x] for x in source.matchers + source.sorters + source.converters if x in self.__filters ]: try: self.profile_start(ctx, filter.name) ctx['candidates'] = filter.filter(ctx) self.profile_end(filter.name) except Exception: self.__filter_errors[filter.name] += 1 if self.__source_errors[filter.name] > 2: error( self.__vim, 'Too many errors from "%s". ' 'This filter is disabled until Neovim ' 'is restarted.' % filter.name) self.__ignored_filters.add(filter.path) self.__filters.pop(filter.name) continue error_tb(self.__vim, 'Could not filter using: %s' % filter) 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', '') 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
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 if ctx['candidates'] and isinstance(ctx['candidates'][0], str): # Convert to dict ctx['candidates'] = [{'word': x} for x in 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 for filter in [self.__filters[x] for x in source.matchers + source.sorters + source.converters if x in self.__filters]: try: self.profile_start(ctx, filter.name) ctx['candidates'] = filter.filter(ctx) self.profile_end(filter.name) except: self.__filter_errors[filter.name] += 1 if self.__source_errors[filter.name] > 2: error(self.__vim, 'Too many errors from "%s". ' 'This filter is disabled until Neovim ' 'is restarted.' % filter.name) self.__filters.pop(filter.name) continue error_tb(self.__vim, 'Could not filter using: %s' % filter) 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', '') results.append({ 'name': source_name, 'source': source, 'context': ctx, }) except: 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.__sources.pop(source_name) continue error_tb(self.__vim, 'Could not get completions from: %s' % source_name) return results
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()