Task-specific customisation of notification and floating terminal for vscode tasks.json (and different behaviour in success and failure cases for each task)
I have a very specific request regarding the combination of notifications and floating terminakl output.
Let's say I have a C++ compilation task defined in .vscode/tasks.json, the relevent entry being:
{
"label": "Compile file (C++20 debug build) with g++",
"type": "shell",
"command": "g++",
"args": [
"-std=c++20",
"-Wall",
"-O0",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.x"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": "$gcc",
"group": {
"kind": "build",
"isDefault": true
}
}
When I run this task, I usually get an empty floating point terminal with just [Process exited 0]. In this case, I just desire to only have the notification SUCCESS.... message from Overseer. i.e. I don't want to have the floating point terminal with just the empty output. However, in the failure case, I would like to only have the quickfix menu opened with the relevant compilation error lines correctly populating the quickfix line:row:column format, along with the exit code of the compilation process. i.e. I don't want the failure notification from overseer.
Now, here comes the second important aspect. In the same .vscode/tasks.json file, I have a run task for running the compiled output.
{
"label": "Run executable",
"type": "shell",
"command": "${fileDirname}/${fileBasenameNoExtension}.x",
"options": {
"cwd": "${fileDirname}"
}
}
I would like this task to be run without the notification in the success case i.e. only with the floating terminal open. For failure case, I would still like the notification from overseer.
So you're asking about customizing the behavior of individual tasks that are defined in the tasks.json file. The way to do this would be with template hooks. For example, for the first task you can add a hook that sets the correct components on it to open the quickfix and change when the notifications occur:
overseer.add_template_hook({ module = "vscode", name = "^Compile file" }, function(task_defn, util)
util.add_component(task_defn, { "on_result_diagnostics_quickfix", open = true })
util.add_component(task_defn, { "on_complete_notify", statuses = { "SUCCESS" } })
end)
For the second, it's a bit trickier. It's perhaps more straightforward to do this by invoking the API directly, seen in this example https://github.com/stevearc/overseer.nvim/blob/9eb40e2ca8d73086e49b07e7f2d981fa725c9aa7/doc/overseer.txt#L449-L454
But if you want the output terminal to open in a float any time the task is run (e.g. even from :OverseerRun), then you'll need to need to make a custom component for it. I would call it something like "on_start_open_terminal". Once you have your component, you can use it the same way in the hooks:
overseer.add_template_hook({ module = "vscode", name = "^Run executable" }, function(task_defn, util)
util.add_component(task_defn, "on_start_open_terminal")
end)
So you're asking about customizing the behavior of individual tasks that are defined in the tasks.json file.
Yes. This is exactly the functionality that the built-in into VSCode's tasks parsing and described in detail under the Output Behaviour heading in their documentation.
You can imagine that it is sometimes quite bothersome for toggleterm to pop-up and display nothing (especially when the tasks success or failure is described by the notification popup).
in this example, I am running the clean task which just gets rid of the compiled executable from the current folder on disk. And this is the pop-up I get:
The popping up of the toggleterm floating terminal and the success notification is redundant and frankly annoying when working on long sessions with repeated compilation runs.
Separately, I didn't quite understand your suggested solution. This sort of hard-coded customisation can make sense only on a per-project basis? Can you please provide the full configuration lua (I haven't yet learnt the lua config syntax)? Anything like this is to be configured on a per-project basis. i.e. the overseer plugin should be installed globally for the user, and only the custom options that are specific to each project should appear in the Overseer menu for that project files alone. Neovim since 0.9 has built-in support for a project-local config calleed .nvim.lua. Perhaps could you detail how to configure this in such a split-up manner?
I still think this workaround is quite brittle because the changes in the text to the tasks.json file shall not automatically propagate to overseer. For example, in my current project, my colleagues have already renamed ^Compile file label for which you provided a workaround, to Build executable from current file, and they retain the desired behavious automatically in VSCode, whereas this simple label change breaks it.
The reveal and revealProblems keys in VSCode's tasks.json handle this quite elegantly. I'd like to request some level of support for at least a partial set of such keys within overseer.
As you suggest, you can use :help exrc for project-local configurations. I have a recipe documenting its use for defining custom tasks, but you could add the calls to add_template_hook there as well.
I've put off supporting the output behavior for a while because the vim UI and overseer UI is so different from VS Code, but now that I'm looking I do have a few ideas for how I could do at least basic compatibility. I'm still chewing through a large backlog of issues and PRs, but I'll put this on the backburner and try to get to it when I have the time
I've added support for VSCode's output behavior in 2d52e80