class Torkify::Vim::Quickfix::API

Public Class Methods

new(vim) click to toggle source
# File lib/torkify/vim/quickfix.rb, line 5
def initialize(vim)
  @stringifier = Stringifier.new
  @vim = vim
end

Public Instance Methods

buffer_from_file(file) click to toggle source
# File lib/torkify/vim/quickfix.rb, line 25
def buffer_from_file(file)
  @vim.expr("bufnr(\"#{file}\")").to_i
end
clear() click to toggle source
# File lib/torkify/vim/quickfix.rb, line 41
def clear
  @vim.expr("setqflist([])")
  @vim.send ':cclose<CR>'
  self
end
get() click to toggle source
# File lib/torkify/vim/quickfix.rb, line 10
def get
  existing = "[" + @vim.expr('getqflist()').gsub(/(?<=})\n(?={)/, ",") + "]"
  qflist = existing.gsub(/(?<=[^\\])"/, '\"')
                   .gsub("'", '"')
                   .gsub("\n", '\n')
  if qflist.length > 0
    JSON.parse(qflist)
  else
    []
  end
rescue => e
  Torkify.logger.fatal { "Couldn't retrieve vim quickfix list: {#{e.class.name}} #{e.message}" }
  []
end
open() click to toggle source
# File lib/torkify/vim/quickfix.rb, line 47
def open
  if @vim.expr("mode()") == "n"
    @vim.send ':cw<CR>'
  end
end
set(errors) click to toggle source
# File lib/torkify/vim/quickfix.rb, line 29
def set(errors)
  error_strings = errors.map { |e| @stringifier.convert e }
  if error_strings.any?
    error_strings.each_slice(100).each_with_index do |strings, i|
      action = i == 0 ? '' : ', "a"'
      @vim.expr("setqflist([#{strings.join(",")}]#{action})")
    end
  else
    clear
  end
end