overseer.nvim icon indicating copy to clipboard operation
overseer.nvim copied to clipboard

on_output_quickfix not using value of errorformat option

Open stevearc opened this issue 2 years ago • 9 comments

          overseer config
  {
    "stevearc/overseer.nvim",
    cmd = {
      "OverseerOpen",
      "OverseerClose",
      "OverseerToggle",
      "OverseerSaveBundle",
      "OverseerLoadBundle",
      "OverseerDeleteBundle",
      "OverseerRunCmd",
      "OverseerRun",
      "OverseerInfo",
      "OverseerBuild",
      "OverseerQuickAction",
      "OverseerTaskAction ",
      "OverseerClearCache",
    },
    opts = {
      task_list = { default_detail = 2 },
      component_aliases = {
        -- Most tasks are initialized with the default components
        default = {
          { "display_duration" },
          { "on_output_summarize" },
          "on_exit_set_status",
          "on_complete_notify",
          "on_complete_dispose",
          { "on_output_quickfix" },
        },
      },
    },
    keys = function()
      local prefix = "<leader>r"
      return {
        { prefix .. "o", "<Cmd>OverseerToggle<cr>", desc = "Task: Open" },
        { prefix .. "t", "<Cmd>OverseerRun<cr>", desc = "Task: Run" },
        {
          prefix .. "s",
          function()
            local overseer = require "overseer"
            local tasks = overseer.list_tasks { recent_first = true }
            if vim.tbl_isempty(tasks) then
              vim.notify("No tasks found", vim.log.levels.WARN)
            else
              overseer.run_action(tasks[1], "restart")
            end
          end,
          desc = "Task: Restart",
        },
      }
    end,
    dependencies = {
      "folke/which-key.nvim",
      optional = true,
      opts = { defaults = { ["<leader>r"] = { name = "+run/task", mode = "n" } } },
    },
  },

:Make

vim.api.nvim_create_user_command("Make", function(params)
  -- Insert args at the '$*' in the makeprg
  local cmd, num_subs = vim.o.makeprg:gsub("%$%*", params.args)
  if num_subs == 0 then cmd = cmd .. " " .. params.args end
  local task = require("overseer").new_task {
    cmd = vim.fn.expandcmd(cmd),
    components = {
      { "on_output_quickfix", open = not params.bang, open_height = 8, errorformat = vim.o.efm },
      "default",
    },
  }
  task:start()
end, {
  desc = "Run your makeprg as an Overseer task",
  nargs = "*",
  bang = true,
})

Program.cs

string? test = "1"

Console.WriteLine("" + test[0] + test[^1]);

:Make result uses :compiler dotnet

FAILURE: dotnet build -nologo -consoleloggerparameters:NoSummary 
dotnet build -nologo -consoleloggerparameters:NoSummary 
on_output_quickfix (Set all task output into the quickfix (on complete))
  errorformat: %E%f(%l\,%c): %trror %m,%W%f(%l\,%c): %tarning %m,%-G%.%#
  open_height: 8
  open: true
  tail: true
  close: false
  set_diagnostics: false
  open_on_match: false
  open_on_exit: never
  items_only: false
display_duration (Display the run duration)
  detail_level: 1
00:01
on_output_summarize (Summarize task output in the task list)
  max_lines: 4
out: /home/zspher/personal/test/src/c_sharp/src/hello-world/Program.cs(3,28): error CS1002: ; expected [/home/zspher/personal/test/src/c_sharp/src/hello-world/hello-world.csproj]
out: /home/zspher/personal/test/src/c_sharp/src/hello-world/Program.cs(3,42): error CS1002: ; expected [/home/zspher/personal/test/src/c_sharp/src/hello-world/hello-world.csproj]
out: /home/zspher/personal/test/src/c_sharp/src/hello-world/Program.cs(3,42): error CS1022: Type or namespace definition, or end-of-file expected [/home/zspher/personal/test/src/c_sharp/src/hello-world/hello-wor
out: ld.csproj]
on_exit_set_status (Sets final task status based on exit code)
on_complete_notify (vim.notify when task is completed)
  statuses: FAILURE, SUCCESS
  on_change: false
  system: never
on_complete_dispose (After task is completed, dispose it after a timeout)
  statuses: SUCCESS, FAILURE, CANCELED
  timeout: 300

Normal result

FAILURE: dotnet build -nologo -consoleloggerparameters:NoSummary 
dotnet build -nologo -consoleloggerparameters:NoSummary 
display_duration (Display the run duration)
  detail_level: 1
00:02
on_output_summarize (Summarize task output in the task list)
  max_lines: 4
out: /home/zspher/personal/test/src/c_sharp/src/hello-world/Program.cs(3,28): error CS1002: ; expected [/home/zspher/personal/test/src/c_sharp/src/hello-world/hello-world.csproj]
out: /home/zspher/personal/test/src/c_sharp/src/hello-world/Program.cs(3,42): error CS1002: ; expected [/home/zspher/personal/test/src/c_sharp/src/hello-world/hello-world.csproj]
out: /home/zspher/personal/test/src/c_sharp/src/hello-world/Program.cs(3,42): error CS1022: Type or namespace definition, or end-of-file expected [/home/zspher/personal/test/src/c_sharp/src/hello-world/hello-wor
out: ld.csproj]
on_exit_set_status (Sets final task status based on exit code)
on_complete_notify (vim.notify when task is completed)
  statuses: FAILURE, SUCCESS
  system: never
  on_change: false
on_complete_dispose (After task is completed, dispose it after a timeout)
  statuses: SUCCESS, FAILURE, CANCELED
  timeout: 300
on_output_quickfix (Set all task output into the quickfix (on complete))
  open: false
  close: false
  open_on_exit: never
  set_diagnostics: false
  open_on_match: false
  tail: true
  items_only: false

Originally posted by @portus-zephyr in https://github.com/stevearc/overseer.nvim/issues/246#issuecomment-1868433568

stevearc avatar Dec 24 '23 05:12 stevearc

this only happens if using :compiler and not :compiler!.

:comp[iler][!] {name}		Set options to work with compiler {name}.
				Without the "!" options are set for the
				current buffer.  With "!" global options are
				set.

zspher avatar Dec 24 '23 05:12 zspher

I cannot reproduce this problem. I'm also confused because in your report you have the lines

on_output_quickfix (Set all task output into the quickfix (on complete))
  errorformat: %E%f(%l\,%c): %trror %m,%W%f(%l\,%c): %tarning %m,%-G%.%#

which indicates that it's using the dotnet errorformat explicitly. I found something that might cause us to not use the correct errorformat in some cases, but it wouldn't be happening for you since you're passing in the efm explicitly.

I'm really not sure what this could be. I'll need a way to repro this on my computer or a lot more debugging from you (lots of logging of the efm and getqflist results in the component).

stevearc avatar Dec 28 '23 04:12 stevearc

to add context I did the following

  1. :compiler dotnet
  2. run dotnet run in overseer cmd
  3. checked :cope

the resulting quickfix list did not consume / show any errors as the global efm is gcc

what I would like to happen is if local efm is consumed by on_output_quickfix so quickfixlist can show errors/warnings with location and everything. This uses efm set by neovim/runtime/compiler.

For now I'm using the following workarounds:

  1. :Make (as above) (uses buffer efm)
    • can only be used with makeprg and not tasks.json
  2. compiler! (set global compiler & efm)
    • can be used with tasks.json but uses the global efm

zspher avatar Dec 28 '23 06:12 zspher

I cannot reproduce this problem. I'm also confused because in your report you have the lines

on_output_quickfix (Set all task output into the quickfix (on complete))
  errorformat: %E%f(%l\,%c): %trror %m,%W%f(%l\,%c): %tarning %m,%-G%.%#

which indicates that it's using the dotnet errorformat explicitly. I found something that might cause us to not use the correct errorformat in some cases, but it wouldn't be happening for you since you're passing in the efm explicitly.

I'm really not sure what this could be. I'll need a way to repro this on my computer or a lot more debugging from you (lots of logging of the efm and getqflist results in the component).

yup, deliberately set efm using :Make (copies efm from the local buffer instead of the global efm).

So it uses dotnet efm because I did :compiler dotnet. If I did :compiler csc, it should switch to csc efm

zspher avatar Dec 28 '23 06:12 zspher

In that case, the change that I just made might fix the issue you were having with the efm not being picked up by tasks.json

stevearc avatar Dec 28 '23 20:12 stevearc

just checked, didn't work. still uses global efm (default efm from :comp gcc) ~~tho efm is explicitly defined in on_output_quickfix errorformat~~ (edit: set { "on_output_quickfix", errorformat = vim.o.efm } in component_aliases)

FAILURE: (vscode) make run current file
dotnet run
display_duration (Display the run duration)
  detail_level: 1
00:01
on_output_summarize (Summarize task output in the task list)
  max_lines: 4
out: /home/zspher/personal/test/src/c_sharp/src/hello-world/Program.cs(4,54): error CS1525: Invalid expression term ')' [/home/zspher/personal/test/src/c_sharp/src/hello-world/hello-world.csproj]
out: 
out: The build failed. Fix the build errors and run again.
on_exit_set_status (Sets final task status based on exit code)
on_complete_notify (vim.notify when task is completed)
  on_change: false
  statuses: FAILURE, SUCCESS
  system: never
on_complete_dispose (After task is completed, dispose it after a timeout)
  statuses: SUCCESS, FAILURE, CANCELED
  timeout: 300
on_output_quickfix (Set all task output into the quickfix (on complete))
  errorformat: %*[^"]"%f"%*\D%l: %m,"%f"%*\D%l: %m,%-G%f:%l: (Each undeclared identifier is reported only once,%-G%f:%l: for each function it appears in.),%-GIn file included from %f:%l:%c:,%-GIn file included from %f:%l:%c\,,%-GIn file included from %f:%l:%c,%-GIn file included from %f:%l,%-G%*[ ]from %f:%l:%c,%-G%*[ ]from %f:%l:,%-G%*[ ]from %f:%l\,,%-G%*[ ]from %f:%l,%f:%l:%c:%m,%f(%l):%m,%f:%l:%m,"%f"\, line %l%*\D%c%*[^ ] %m,%D%*\a[%*\d]: Entering directory %*[`']%f',%X%*\a[%*\d]: Leaving directory %*[`']%f',%D%*\a: Entering directory %*[`']%f',%X%*\a: Leaving directory %*[`']%f',%DMaking %*\a in %f,%f|%l| %m
  close: false
  tail: true
  open_on_exit: never
  set_diagnostics: false
  open_on_match: false
  items_only: false
  open: false
on_result_diagnostics (If task result contains diagnostics, display them)
on_result_diagnostics_quickfix (If task result contains diagnostics, add them to the quickfix)
  set_empty_results: false
  close: false
  use_loclist: false
  open: false

zspher avatar Dec 29 '23 06:12 zspher

I wouldn't expect it to work if you use { "on_output_quickfix", errorformat = vim.o.efm } in component_aliases, because it will be resolved whenever config is imported and never updated. Have you tried without explicitly passing the vim.o.efm?

stevearc avatar Jan 06 '24 15:01 stevearc

have removed errorformat and the problem still persists

Program.cs

for (int i = 0; i < 10; i++)
{
    Console.WriteLine("Hello, World!")
}

Tests:

  1. when using :comp dotnet
FAILURE: (vscode) make run current file
dotnet run
display_duration (Display the run duration)
  detail_level: 1
00:01
on_output_summarize (Summarize task output in the task list)
  max_lines: 4
out: /home/zspher/personal/test/src/c_sharp/src/blank-proj/Program.cs(4,39): error CS1002: ; expected [/home/zspher/personal/test/src/c_sharp/src/blank-proj/blank-proj.csproj]
out: 
out: The build failed. Fix the build errors and run again.
on_exit_set_status (Sets final task status based on exit code)
on_complete_notify (vim.notify when task is completed)
  system: never
  on_change: false
  statuses: FAILURE, SUCCESS
on_complete_dispose (After task is completed, dispose it after a timeout)
  statuses: SUCCESS, FAILURE, CANCELED
  timeout: 300
on_output_quickfix (Set all task output into the quickfix (on complete))
  close: false
  open: false
  open_on_exit: never
  set_diagnostics: false
  open_on_match: false
  tail: true
  items_only: false
on_result_diagnostics (If task result contains diagnostics, display them)
on_result_diagnostics_quickfix (If task result contains diagnostics, add them to the quickfix)
  set_empty_results: false
  open: false
  use_loclist: false
  close: false

quickfixlist

|| /home/.../blank-proj/Program.cs(4,39): error CS1002: ; expected [/home/.../blank-proj/blank-proj.csproj]
|| 
|| The build failed. Fix the build errors and run again.
|| 
|| [Process exited 1]
  1. when using :comp! dotnet
FAILURE: (vscode) make run current file
dotnet run
display_duration (Display the run duration)
  detail_level: 1
00:01
on_output_summarize (Summarize task output in the task list)
  max_lines: 4
out: /home/zspher/personal/test/src/c_sharp/src/blank-proj/Program.cs(4,39): error CS1002: ; expected [/home/zspher/personal/test/src/c_sharp/src/blank-proj/blank-proj.csproj]
out: 
out: The build failed. Fix the build errors and run again.
on_exit_set_status (Sets final task status based on exit code)
on_complete_notify (vim.notify when task is completed)
  on_change: false
  statuses: FAILURE, SUCCESS
  system: never
on_complete_dispose (After task is completed, dispose it after a timeout)
  statuses: SUCCESS, FAILURE, CANCELED
  timeout: 300
on_output_quickfix (Set all task output into the quickfix (on complete))
  open_on_exit: never
  close: false
  open_on_match: false
  items_only: false
  tail: true
  set_diagnostics: false
  open: false
on_result_diagnostics (If task result contains diagnostics, display them)
on_result_diagnostics_quickfix (If task result contains diagnostics, add them to the quickfix)
  set_empty_results: false
  close: false
  open: false
  use_loclist: false

quickfixlist

Program.cs|4 col 39 error| CS1002: ; expected [/home/.../blank-proj/blank-proj.csproj]

zspher avatar Jan 06 '24 15:01 zspher

I can't find anything obviously wrong anymore; this is going to take more investigation. Filing this as a P1 (would like to work on it, but given my current support load probably not any time soon)

stevearc avatar Jan 14 '24 17:01 stevearc