summary refs log tree commit diff
path: root/.vim
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2022-04-15 15:17:54 +0200
committerRobert Günzler <r@gnzler.io>2022-04-15 15:17:54 +0200
commitb8498c5ef83709cd97d75821d465930456d9c2a9 (patch)
treef59ca1ee0183a7c41919b82575e689da787ee118 /.vim
parentf69b968a47026734fbd8e7b7f7c2c6fe259cab64 (diff)
vim: fix job.lua quickfix reporting
Diffstat (limited to '.vim')
-rw-r--r--.vim/lua/job.lua45
1 files changed, 24 insertions, 21 deletions
diff --git a/.vim/lua/job.lua b/.vim/lua/job.lua
index c14e978..657a72d 100644
--- a/.vim/lua/job.lua
+++ b/.vim/lua/job.lua
@@ -11,6 +11,15 @@ local M = {
 function M.jobstart(opts)
   opts = opts or {}
 
+  -- required options
+  vim.tbl_extend('force', opts, {
+    enable_recording = true,  -- enable job:result()
+  })
+
+  -- default options
+  opts.populate_quickfix = opts.populate_quickfix or true
+  opts.enable_spinner = opts.enable_spinner or true
+
   local title
   if opts.format_title then
     title = opts.format_title(opts.command, opts.args)
@@ -19,15 +28,12 @@ function M.jobstart(opts)
     title = opts.command
   end
 
-  if opts.populate_quickfix == nil then
-    opts.populate_quickfix = true
-  end
-
-  opts.enable_recording = true -- enable job:result()
-
   opts.on_exit = vim.schedule_wrap(function(j, code)
-    spinner.on_progress('end', j.pid, j.pid)
-    spinner.on_exit(nil, nil, j.pid)
+    if opts.enable_spinner then
+      spinner.on_progress('end', j.pid, j.pid)
+      spinner.on_exit(nil, nil, j.pid)
+      table.remove(M.current_jobs, j.pid)
+    end
 
     local lines
     if code == 0 then
@@ -43,34 +49,30 @@ function M.jobstart(opts)
 
     -- only show quickfix if there is output
     if opts.populate_quickfix and #lines > 0 then
-      vim.bo.errorformat = '%m'
       vim.fn.setqflist({}, 'r', {
         title = title,
-        items = lines,
+        lines = lines,
+        efm = '%m',
       })
-      vim.api.nvim_command('doautocmd QuickFixCmdPost')
-    end
-
-    for k, v in ipairs(M.current_jobs) do
-      if v.pid == j.pid then
-        table.remove(M.current_jobs, k)
-        break
-      end
+      vim.cmd([[doautocmd QuickFixCmdPost]])
     end
   end)
 
   local j = Job:new(opts)
   j:start()
-  table.insert(M.current_jobs, j)
+  M.current_jobs[j.pid] = j
 
-  spinner.on_attach(j.pid, title, vim.fn.bufnr())
-  spinner.on_progress('begin', j.pid, j.pid)
+  if opts.enable_spinner then
+    spinner.on_attach(j.pid, title, vim.fn.bufnr())
+    spinner.on_progress('begin', j.pid, j.pid)
+  end
 
   return j
 end
 
 function M.make(extra_args)
   local makeprg = vim.fn.expandcmd(vim.opt.makeprg:get())
+  -- split makeprg into command + args
   local args = vim.split(makeprg, ' ')
   local command = args[1]
   table.remove(args, 1)
@@ -89,6 +91,7 @@ function M.sh(command_string)
     command = vim.env.SHELL,
     args = {'-c', command_string},
 
+    -- strip 'sh -c' from the title (used by progress reporting etc.)
     format_title = function(_, args)
       return List(args):slice(2,#args):join(' ')
     end