stevearc / overseer.nvim

A task runner and job management plugin for Neovim
MIT License
1.23k stars 56 forks source link

on_result_diagnostics_quickfix.set_empty_results not clearing diagnostics list #278

Open iainsmith opened 7 months ago

iainsmith commented 7 months ago

Neovim version (nvim -v)

NVIM v0.9.5 Build type: Release LuaJIT 2.1.1703358377

Operating system/version

MacOS 14.4 (23E214)

Describe the bug

👋 thanks for the great plugin!

After running a failing job that correctly sets diagnostics, a second successful job does not clear out the diagnostics. Re running the initial failing job does reset the diagnostics.

IMO, this is surprising and requires scripting to workaround, which could ideally be handled by the components. Maybe this is a bug with on_result_diagnostics_quickfix.set_empty_results = true or user error.

PS. Apologise for the minimal detail in the bug report, I'll try to follow up with some more screenshots / better reproduction steps.

What is the severity of this bug?

breaking (some functionality is broken)

Steps To Reproduce

Expected Behavior

Minimal example file

No response

Minimal init.lua

return {
  "stevearc/overseer.nvim",
  config = function()
    local overseer = require("overseer")
    overseer.setup({
      -- Aliases for bundles of components. Redefine the builtins, or create your own.
      component_aliases = {
        -- Most tasks are initialized with the default components
        default = {
          { "display_duration", detail_level = 2 },
          "on_output_summarize",
          "on_exit_set_status",
          "on_complete_notify",
          "on_complete_dispose",
          { "on_output_quickfix", open_on_match = true, items_only = true, set_diagnostics = true },
          { "on_result_diagnostics", remove_on_restart = true },
          { "on_result_diagnostics_quickfix", set_empty_results = true },
        },
      },
    })
  end,
}

## Example job config

```yaml
on_output_quickfix (Set all task output into the quickfix (on complete))
  close: false
  open: false
  tail: true
  errorformat: %f:%l:%c: error: %m
  items_only: true
  set_diagnostics: true
  open_on_exit: never
  open_on_match: true
on_result_diagnostics (If task result contains diagnostics, display them)
  remove_on_restart: true
on_result_diagnostics_quickfix (If task result contains diagnostics, add them to the quickfix)
  close: false
  open: false
  use_loclist: false
  set_empty_results: true
Result:
  diagnostics = {}

Additional context

No response

stevearc commented 5 months ago

I cannot replicate this. I'm using this task

overseer.register_template({
  name = "quickfix",
  builder = function()
    return {
      cmd = "./quick.sh",
      components = {
        "default",
        { "on_output_quickfix", open_on_match = true, items_only = true, set_diagnostics = true },
        { "on_result_diagnostics", remove_on_restart = true },
        { "on_result_diagnostics_quickfix", set_empty_results = true },
      },
    }
  end,
})

With this helper script as quick.sh

#!/bin/bash
echo 'lua/overseer/init.lua:22: error: this is an error'
echo 'lua/overseer/init.lua:44: error: this is an error'
# echo "success"

I run the task once, see the quickfix populated, comment/uncomment the quick.sh script to have it output no errors, then run a new task. The quickfix gets cleared for me.

Can you provide a minimal configuration that reproduces the issue?

lalitmeek commented 2 months ago

Hey @stevearc, I am also facing the same issue with yarn tsc-watch command.

I am using the following template for the task:

local tsc_errorformat = {
    "%E%f:%l:%c: error %m", -- Error: file, line, column, message
    "%E%f:%l:%c - error %m", -- Another common error format (seen in newer versions)
    "%C%m", -- Continued error messages
    "%-G%.%#", -- Ignore any other lines
}

return {
    name = "yarn-tsc-watch",
    builder = function()
        return {
            cmd = "yarn",
            args = { "tsc-watch" },
            cwd = vim.fn.getcwd(),
            name = "yarn-tsc-watch",
            components = {
                { "on_output_quickfix", set_diagnostics = true, open = false, errorformat = table.concat(tsc_errorformat, ","), open_on_match = true, close = true },
                { "on_result_diagnostics", remove_on_restart = true },
                { "on_result_diagnostics_quickfix", close = true, open = true, set_empty_result = true },
                { "on_result_notify", system = "unfocused" },
                "default",
            },
        }
    end,
    desc = "Run TypeScript compiler in watch mode (yarn tsc-watch)",
    condition = {
        callback = function()
            return vim.fn.filereadable("package.json") == 1
        end,
    },
}