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

Question on opening the quickfixlist to show errors from a gcc compilation process

Open krishnakumarg1984 opened this issue 1 year ago • 5 comments

I am coming to Overseer from other task automation tools (asyncrun/asynctasks initially and later on, mg979/tasks.nvim) that load the output from the compilation command onto the quickfix window by parsing the errorformat.

I came to Overseer based on good experience with your other neovim plugins e.g. aerial, and was interested in a pure lua plugin for my compilations. Most importantly, the major compatibility with vscode's tasks.json format means that I can mostly reuse the standard json (with some minor modifications) that my colleagues are using.

While the documentation is quite extensive, and it is certainly a well thought out example of high quality software engineering, the documentation is missing simple recipes e.g. building, running and debugging a C++/python/rust application. While the demo video piqued my interest, it is certainly not satisying the needs of the tutorial. The exhaustive project documentation currently is less tailored to those who simply want to achieve simple end goals.

Here's a specific question. How can I use the following .vscode/tasks.json on a simple helloworld.cpp (with syntax error missing a semicolon) to automatically populate and open the quickfix window upon building?

.vscode/tasks.json

{
  "tasks": [
    {
      "type": "shell",
      "label": "g++ debug build: compile active file",
      "command": "g++",
      "args": [
        "-std=c++20",
        "-Wall",
        "-fdiagnostics-color=always",
        "-DDEBUG",
        "-O0",
        "-g",
        "-gdwarf-5",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}.x"
      ],
      "problemMatchers": "$cpp",
      "options": {
        "cwd": "${fileDirname}"
      },
      "group": {
        "kind": "build",
        "isDefault": true
      }
    }
  ],
  "version": "2.0.0"
}

helloworld.cpp (with syntax error, missing a semicolon in the cout statement within the loop)

#include <iostream>
#include <vector>
#include <string>

int main()
{
    std::vector<std::string> msg{"Hello", "C++"};

    for (const std::string &word : msg)
    {
        std::cout << word << " "
    }
    std::cout << endl;
}

krishnakumarg1984 avatar Aug 27 '22 19:08 krishnakumarg1984

There is a PR #4 in the works. Meanwhile you can check out this custom component that I created based on (but independent of) this PR that does the same. It is a lua table, but you can just convert that to json and put it in your task.json file

ranjithshegde avatar Aug 28 '22 08:08 ranjithshegde

As Ranjith said, that PR should address this and is in-progress but not finalized. There are some API changes I'd like to make to it before merging. It's been pending for a while because I've had a whole lot going on at work and outside of work, and requests on my open source projects have piled up. Just this last week I've started making headway on the backlog, but I'm out of time again for today. I hope to be able to come back and finish this one up no later than the end of next weekend.

stevearc avatar Aug 28 '22 18:08 stevearc

@krishnakumarg1984 after taking another look, your ask is actually independent of that PR. The issue was much simpler: the necessary problemMatcher wasn't included (because it was in the vscode-cpptools extension).

If you get the most recent master and change your tasks.json to have this line: "problemMatcher": "$gcc", that's all that's required to parse the output into diagnostics.

If you then make sure that you have the on_result_diagnostics_quickfix component (with open = true to auto-open quickfix), that should be all you need. This could look like:

require("overseer").setup({
  component_aliases = {
    default = {
      -- These are the default components listed in the README
      -- You probably want to keep them
      "on_output_summarize",
      "on_exit_set_status",
      "on_complete_notify",
      "on_complete_dispose",
      -- This puts the parsed results into the quickfix
      { "on_result_diagnostics_quickfix", open = true },
      -- This puts the parsed results into neovim's diagnostics
      "on_result_diagnostics",
    },
  },
})

stevearc avatar Aug 30 '22 15:08 stevearc

@ranjithshegde and @stevearc Thank you for your responses, and thank you for trying to address this request.

I updated the overseer setup call to use the above suggested table, and updated the problemMatcher line in tasks.json to use $gcc, and even after updating to the latest commit of overseer, I still am not able to make this work. i.e. the quickfix window does not open. In fact, the quickfix window seems to not even contain diagnostics. After :OverSeerRun and :OverSeerToggle!, I am getting some garbled characters in the overseer split. Please see the screenshot below which hopefully illustrates these problems.

  • The problematic source code in the top right split
  • Manually opened (with :copen) empty quickfix window in bottom right
  • Overseer window (with :OverSeerToggle!) in the left split

image

krishnakumarg1984 avatar Aug 31 '22 11:08 krishnakumarg1984

Some questions:

  • In your initial tasks.json file, you used the key "problemMatchers" instead of "problemMatcher". Have you corrected that?
  • If you expand the task all the way in the overseer list (default bound to L), do you see a "problem_matcher: " line underneath the vscode.result_vscode_task component? Screenshot from 2022-08-31 07-29-19
  • What does the full output of the command look like if you open the terminal?

stevearc avatar Aug 31 '22 14:08 stevearc