class Torkify::Vim::Quickfix::Populator

Attributes

api[R]
errors_populated[R]
excluded_buffers[R]

Public Class Methods

new(api) click to toggle source
# File lib/torkify/vim/quickfix.rb, line 57
def initialize(api)
  @api = api
  @excluded_buffers = []
  @errors_populated = 0
end

Public Instance Methods

exclude(file) click to toggle source
# File lib/torkify/vim/quickfix.rb, line 63
def exclude(file)
  if file && file.length > 0
    bufnum = @api.buffer_from_file(file)
    if bufnum > 0 && !@excluded_buffers.include?(bufnum)
      @excluded_buffers << bufnum
    end
  end
  self
end
populate(errors) click to toggle source
# File lib/torkify/vim/quickfix.rb, line 73
def populate(errors)
  determine_excluded_buffers errors
  existing = api.get

  kept_errors = exclude_errors existing
  all_errors = kept_errors + errors
  @errors_populated = all_errors.length

  if error_list_changed?(existing, all_errors)
    api.set kept_errors + errors
  end
  self
end

Protected Instance Methods

determine_excluded_buffers(errors) click to toggle source
# File lib/torkify/vim/quickfix.rb, line 96
def determine_excluded_buffers(errors)
  unique_file_errors = errors.uniq { |e| e['filename'] }
  unique_file_errors.each { |e| exclude e['filename'] }
end
error_list_changed?(existing, new) click to toggle source
# File lib/torkify/vim/quickfix.rb, line 90
def error_list_changed?(existing, new)
    existing_msgs = existing.map { |e| e['text'] }.sort
    new_msgs = new.map { |e| e['text'] }.sort
    existing_msgs != new_msgs
end
exclude_errors(errors) click to toggle source
# File lib/torkify/vim/quickfix.rb, line 101
def exclude_errors(errors)
  if errors && errors.any?
    errors.dup.keep_if { |e|
      e['type'] == 'E' && !excluded_buffers.include?(e['bufnr'].to_i)
    }
  else
    []
  end
end