1

I'm trying to make more daily use of Visual Studio Code, but there's one feature I really miss from my existing GVim setup: I use syntastic to compile C++ source when I save the current file, and then I can jump directly to error lines in the editor.

Is there any way to set up VS Code to do something similar?

I know that I can create a tasks.json and have Ctrl+Shift+B compile the whole project, but the turnaround for that is excessive. I just want to compile the current file when saving it, and have the error list be navigable (presumably in the Problems tab).

Success criteria:

  • When I save a C++ file, it runs a configured g++ command, rather than build the entire project.
  • It should somehow parse the output from that, and make the warnings and errors easily navigable so that I can step through them with a simple keystroke. Navigation should place my cursor on the relevant line. In Visual Studio, this used to be bound to the F8 key.
0

1 Answer 1

0

VS Code is not an IDE, it is a text editor with extension support, and it cannot be treated as such. Natively, it does not have any features allowing it to parse error output from a build task and visualize it in the editor.

The linter has the ability to markup the editor when syntax errors are present, but that is all the stock linter is capable of doing. It is the only part of VS Code that has the ability to use the Problems panel and annotate the editor with syntax errors.

That said, you are able to accomplish the 1st point you require. You can set up a keybind that executes more than one command. In your case, a keybind that would save the file and then build it. Something like:

{
    "key": "ctrl+shift+b",
    "command": "workbench.action.files.save",
    "command": "workbench.action.tasks.build"
}

in keybindings.json would save the file and then execute the default build task when you press Ctrl+Shift+B.

6
  • Given that this isn't necessarily valid JSON (two keys with the same name is implementation-defined), I'm not convinced it'll work. Have you successfully done this? Oct 3, 2017 at 8:41
  • Fair enough; it still doesn't answer all of my question, though. The parts missing: how do I run a shell command on the current file from there? How do I get the results, parsed, into (e.g.) the Problems tab? Do I need to write my own plugin? Oct 3, 2017 at 14:47
  • If you have the command you need to get run in a build task, you can point the command of the keybind to execute the default one as shown above. The output of the build task will appear in the Terminal tab.
    – ifconfig
    Oct 3, 2017 at 15:04
  • using the #relativeFile keyword, you can have the build task compile the currently in-focus editor. See: stackoverflow.com/questions/45679035/….
    – ifconfig
    Oct 3, 2017 at 17:55
  • ...and how do I get the errors and warnings in such a form that I can easily navigate from one to the other? Oct 3, 2017 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.