Makefile Tools December 2021 Update: Problem Matchers and Compilation Database Generation

Julia

The December 2021 update of the Makefile Tools extension for Visual Studio Code is here, bringing you support for problem matchers (to easily view errors and warnings in the editor), the ability to generate a compile_commands.json file for your project, and a bunch of other enhancements and bug fixes! To find out more about all the enhancements, check out our release notes on GitHub.

Problem matchers

If you’ve used the C++ extension for VS Code, you’re probably familiar with the Problems panel, where you can navigate through a list of compiler errors and warnings found in your project. VS Code uses a problem matcher to display the errors and warnings in the Problems panel.

For example, if you’re missing a semi-colon in your source file, you’ll see the compiler error in the Problems panel. Selecting the problem brings you to the line of code generating the error or warning. To fix the problem, click on the lightbulb and choose from a list of Quick Actions.

A screenshot of the Problems Pane in VS Code, showing errors and warnings found by GCC and make in the project

Now, let’s say you don’t have any compiler errors, but make displays a bunch of warnings when you build your project. Until now, there wasn’t a way to see those warnings in the Problems panel. With this latest release of the Makefile Tools extension, you’ll see all of make’s errors and warnings in the Problems panel after you build your program.

A screenshot showing make's warnings in the Problems Pane in VS Code after building a project with Makefile Tools.

To enable make errors and warnings in the Problems panel, add “problemMatchers”: [“$gcc”] to your makefile configuration in settings.json, like this:

"makefile.configurations": [

        {

            "name": "MyConfiguration",

            "problemMatchers": [

                "$gcc"

            ],

            "makeArgs": ["any", "other", "args", "you", "want"]

        },

]

If you’re on Windows using MSVC, set the problemMatcher to “$msCompile” instead of “$gcc”. Contributions from the community to support additional problem matchers are welcome! Problem matchers are defined in the extension’s package.json file.

Generate compile_commands.json

As a C++ developer, you might find yourself wanting a compilation database, which is a file that stores compilation instructions for the source files in your project. Compilation databases are used by many Clang tools and editors/IDEs. A common compilation database format is compile_commands.json, which contains command objects, one for each translation unit in the project. Each command object specifies the translation unit’s main file, the compile command, and the working directory where the compile command is run.

With this latest release of the Makefile Tools extension, you can generate a compile_commands.json file for your project. All you have to do is specify the path to the target compile_commands.json file in settings.json, like this:

"makefile.compileCommandsPath": ".vscode/compile_commands.json"

Then configure your project to generate compile_commands.json at the specified location.

A screenshot of the contents of a compile_commands.json file generated by the Makefile Tools extension

Thank you rapgenic for the request and for contributing to this feature!

Give it a try

Download the Makefile Tools extension for Visual Studio Code today, give it a try, and let us know what you think. Check out this blog post to learn how to get started with Makefile Tools.

If you run into any issues, or have any suggestions, please report them in the Issues section of our GitHub repository. Be sure to check out the Makefile Tools documentation for troubleshooting tips and a list of tested repositories and their configuration instructions.

We can be reached via the comments below or in email at makefiletools@microsoft.com. You can also find our team on Twitter at @VisualC.

 

 

0 comments

Leave a comment