Must-have plugins and a few utilities for C / C ++ development in VS Code
Surprisingly, but so far on Habré there is no good selection of plug-ins for Visual Studio Code for those who write in C / C ++. Microsoft only published an article on its blog , a very basic level with instructions for setting it up. But the majority of Habr's readers, especially from developers, will do without such detailed instructions. There are only a few collections for web developers, but not for C ++.
Perhaps this is due to the fact that most C ++ developers use heavy IDE, first of all, of course, Visual Studio.
But on Linux and MacOS with full-fledged IDE, things are not so simple, and a heavy development environment is not always needed or simply do not want to use it.
I want to draw your attention to useful plugins that make life and work easier, and also to tell you about the useful settings and features of VS Code that you could simply miss.
The question to consider VS Code IDE or only the code editor is very holivarny and is not the purpose of this article. I’ll still consider it IDE, since it offers minimal IDE scripts, such as autocompletion and debugging, with minimal effort.
A bit of history
The first IDE that I used when starting my path as a developer was already historical, Borland C ++ 2.0. Then I moved to Visual Studio 6.0 and remained (and still remain) a fan of this IDE. But at some point it became necessary to write under Linux (it was, probably, 2006). In Linux, at first, I was shocked by the lack of a serious IDE - I tried Eclipse, tormented and spat. I will not go into the history, but in the end I figured out Make, CMake, learned how to quickly write the corresponding files, then there were linker scripts, gdb, kdb and a lot of interesting things. At that time I fell in love and actively used vim for 5 years. Then I gradually switched to Sublime Text, then to its second version, and now to the third.
Now I’m writing less code, and I’m more involved in the development of products and processes, but I still have to write periodically - these are personal projects and help to our partners with embedding our SDK.
And since the SDK is not only for Windows, but also for Linux and MacOS, the code has to be written in them. Last year I tried VS Code, and it became for me a good alternative to Sublime Text.
If we compare them briefly, then Sublime Text, in my personal opinion, gives more options for setting up and working, but VS Code gives more out of the box. And if there is no personal selection of extensions for Sublime Text at hand or if you have never used this editor at all, then Visual Studio Code is an excellent thing.
I'll start with a few very useful extensions. There are not so many of them for C / C ++ developers in VS Code and the main one is of course:
C / C ++ for Visual Studio Code
Link to the marketplace
This is the main extension for supporting C / C ++ in VS Code, which is developed by Microsoft. A detailed description of everything that it gives is on the page in the market, but here I will mention only the most important thing (in my opinion of course):
- Code Formatting (using clang-format)
- Search for characters by code
- Go to Definition / Declaration (including Peek)
- Class / Method Navigation
- Signature Help
- Quick Info (Hover)
- Error Squiggles
Debugging support for Windows (PDB, MinGW / Cygwin), Linux and macOS applications
Main article from Microsoft about the extension and its capabilities with beautiful pictures is here - link .
It should be noted that Microsoft is great well done and constantly updating this extension. And the new features of this extension are published only in the dev blog from Microsoft and are not very noticeable. So I decided to tell here about the newest ones.
Global Settings for IntelliSense
In May 2018, VS Code added the ability to set any parameters for IntelliSense in user settings.json. These settings are automatically applied to all projects.
A very useful thing when most of the projects you work with use a common set of include, the same compiler, and so on.
Built-in terminal support for debugging
In December 2018, Microsoft added the ability to debug C / C ++ applications in the embedded terminal, instead of opening a separate window with a terminal. This feature is controlled by the externalConsole parameter in launch.json.
So far, only cppdbg is supported and only on Linux and Windows, but MacOS also promised to be delivered soon. It looks like this:
This thing was added literally last month. There is nothing special to tell here, so I’ll just give an example from Microsoft.
We write a simple class Box and add comments in a standard format: A
comment is associated with classes or functions to members of the class and shown in tooltips when hovering over the corresponding object.
It looks like this:
Work with containers
In the latest update of February 6, Microsoft added work with C ++ in Docker containers. Now you can not only collect code in containers, but also debug it inside containers. Details - in the blog of Microsoft .
I myself do not use containers for work - there is no need. But surely this will be useful to many, so I decided to include it in the article.
Well, now back to the other extensions for VS Code, which will help you in the development.
link to the marketplace
Another fairly global plugin for C / C ++ / Objective-C developer in VS Code. The main feature - the extension was designed and tested on very large projects, for example, on Chromium. Therefore, it is useful where the standard extension from Microsoft and IntelliSense sucks (this often happens when you have more than 100MB of C ++ source code).
The list of all the main features is:
- code completion (with both help and snippets)
- finding definition / references
- call (caller / callee) hierarchy , inheritance (base / derived) hierarchy
- symbol rename
- document symbols and approximate search of workspace symbol
- hover information
- code actions (clang FixIts)
- preprocessor skipped regions
- #include auto-complete, undefined type include insertion, include quick-jump (goto definition, document links)
- auto-implement functions without a definition
- semantic highlighting, including support for rainbow semantic highlighting
At the beginning I wanted to translate this list, but then I realized that most of the concepts do not have beautiful generally accepted translations, so I decided to leave it as it is. On the links you will find a more detailed description and demonstration of specific features.
The extension is very useful, but there is no activity on github since November 2018. And judging by the issue - Is this project dead? # 867 project really stalled. Banner picked up the fork https://github.com/MaskRay/ccls , but I have not checked it yet, so I can not recommend it. Most likely, ccls will eventually replace cquery.
Easy C ++ projects
link to the marketplace
If the two previous extensions were global with many possibilities, then it performs a simple function - creating a simple project for MSVC, GCC or Clang.
- create sample makefile for project
- create VS Code configurations for build and run
- create VS Code configurations for debugging (supported by Visual Studio Debugger, GDB and LLDB)
- generate new classes from a small list of templates
It is useful for both beginners and experienced developers. It will help to throw in a simple Helloworld project when you need to quickly check something.
It works like this:
As the name implies, the extension adds support for CMake. As suggested in the comments, you can of course register everything with your hands, but with the extension it will be more convenient.
After installation, you will need to make the minimum setting. Select toolchain:
Then select the configuration for the assembly:
And that's it. You can work.
The extension can also generate the simplest CMake files for projects.
link to the marketplace
Extensions for creating TODO lists for VS Code are several. You can choose any. I liked that the most. The only drawback is that it requires https://github.com/BurntSushi/ripgrep , which is not everywhere out of the box and is not very convenient to install. It’s not in the standard Debian repositories yet.
The result of the work looks like this:
link to the marketplace.
As the name suggests, the extension improves git work. It should be noted that, by default, some git support is already built into VS Code, but very limited.
The main feature of GitLens is the display directly in the edited line who and in what commit changed it the last time. The extension also adds an advanced search for file history, a search for commits, a convenient view for comparing multiple versions of a file, and much more. To demonstrate the work, I simply insert gif from the market page, which clearly shows the possibilities of expansion.
link to the marketplace
Another extension that improves work with git, namely the display of history. Why in GitLens I could not find a suitable display of the project history with all the branches. If someone knows how to make a similar view (see below) using GitLens, be sure to write in the comments, I will be very grateful.
link to the marketplace
One of the many extensions that adds icons for files and directories in the Explorer pane. There are lots of such extensions in the market, and this is the most popular. Feel free to choose any other, I liked these icons.
link to the marketplace
Another useful extension, the purpose of which is evident from the name.
To synchronize your settings, use GitHub account token and Gist. For me personally, one of the most useful extensions is because I use both Windows, and Linux, and Mac.
Code Spell Checker
If your English is still far from ideal or you want to prevent typos, then this extension will definitely not be superfluous. If necessary, you can add support for the Russian language .
Of the nice features - not only emphasizes erroneous words, but also offers the correct options.
WakaTime marketplace link is a service that shows beautiful statistics \ graphics \ metrics for your programming. The stuff is purely aesthetic, but I really like it. The extension accordingly adds support for the service when working in VSCode. About the service itself, you can read here .
An example of beautiful graphics:
The main features of the service are free and no subscriptions are required.
On this with all the extensions. I would also like to share some useful settings of the VS Code itself, which can be useful to the community.
Some useful settings
By default, VSCode sends telemetry on crash, as well as some data and error information to Microsoft. If for some reason this does not suit you, then safely turn it off in the settings:
- Telemetry: Enable Crash Report
- Telemetry: Enable Telemetry
I also advise everyone to turn on autosave files. Stuck banal, but to deny its usefulness is difficult. I rescued more than once. By default, for some reason off.
- Files: Auto Save
The following setting enables the display of non-printing characters in the code. In my personal opinion, it’s an extremely useful thing, which allows you to immediately notice that the file in the next project is formatted with tabs, not spaces. And in general, will allow to notice the extra characters where they should not be.
- Editor: Render Whitespace
For anyone who likes smooth scrolling:
- Smooth scrolling
Display of variables directly in the code when debugging. Another very useful thing, which for some reason is turned off. The most big-eyed have probably already noticed an example of how this setting works in one of the previous screenshots, but just in case I will add another
- Inline values
I myself found the following setting only when writing an article. ZenMode allows you to hide all unnecessary windows and menus and leave only the current code file. Now I will constantly use it on the tablet when I have to try something in the code. On the tablet, the remaining windows are often not needed, and there is a shortage of storage space. Recommend!
If someone wants to share their interesting extensions for VS Code or pay attention to the useful settings - welcome in the comments. I am pleased to add an article to make it even more useful.