IntelliSense Improvements in Visual Studio 2019
We’ve made many great improvements to C++ IntelliSense over the course of the Visual Studio 2019 release. We’ve collected a few of the highlights in case you are interested in upgrading to Visual Studio 2019 or just want to learn how to be more productive when writing C++ code. If you have followed our blog since the 2019 Previews, you may be familiar with some of these features already. We hope you find this collection helpful. If you want to try all these features out, please grab the latest release of Visual Studio 2019.
Many of these features are rooted in community suggestions. If you have any suggestions or run into issues with Visual Studio, please let us know on Developer Community. Your feedback really does help us deliver a great product!
We strive to make Visual Studio the best IDE for working with the latest language standards. That involves a lot of work in our compilers and standard library but is not complete without the corresponding IntelliSense in the IDE to back these new features up while you are editing your code.
C++20 includes great new features such as modules, coroutines, concepts, ranges, the three-way operator, designated initializers and many more. All these features are supported in the IDE by the IntelliSense features you know and love.
For instance: coroutine support:
Most of these features deserve a blog post on their own, so here they are if you want to learn more:
We want to make it as easy as possible to update your codebases to use the latest languages standards. One way to do this is with our code analysis, code tidying, and C++ linting tools. These work together and allow you to turn the dial in Visual Studio depending on how comprehensive you want to be in analyzing and updating your code. These features range from the very lightweight like our new C++ Linters that run inside the IntelliSense engine, to features like clang-tidy that bring in many more checks, and all the way up to the complete rulesets that MSVC’s Code Analysis provides.
In-Editor Code Analysis
The Microsoft Visual C++ Compiler has had extensive support for code analysis for some time. However, before VS 2019, you needed to compile your code before you could see any warnings or errors from this comprehensive analysis. In the latest version of Visual Studio, code analysis runs in the background for any files you are editing and results are shown directly in the IDE’s editor:
We introduced the IntelliSense C++ linter as a complement to the more comprehensive code analysis that now runs in the background. The IntelliSense linter gives instantaneous results for the most critical issues, instantly, as you type. Currently, the linter is focused on common C++ typos, common bugs such arithmetic and operator mismatches, performance issues, and security issues such pointer arithmetic problems.
This complements the more comprehensive code analysis from the compiler. While code analysis is much more flexible and powerful than the linter, it also takes longer to provide results because the translation unit must be compiled first. The linter is now enabled by default in Visual Studio. You can learn more about the IntelliSense Linter here.
C++ Concept IntelliSense
One of the great new features in C++20 is concepts. Visual Studio makes it easier than ever to create to create and use concepts in your code. In the first template in the code below we have defined a concept ‘is_cat’ that defines the properties of a cat. In the second template we use that concept to constrain the types that can be passed to it. This is fully supported by IntelliSense automatically and you can see that the Member List contains the methods defined by the concept above (‘pet’ and ‘meow’).
We didn’t need to provide any information to the IDE beyond the code and no types needed to be manually entered into the template bar (to the right of the second template). All the information instead comes from the concepts defined in the code.
If you work with C++, you have no doubt encountered a great deal of templated code. Working with this in an IDE can be tricky because the IDE doesn’t know exactly how these templates are going to be instantiated. The new Template IntelliSense Bar in Visual Studio 2019 helps solve this problem. Using the Template Bar, you can tell the IDE how your template will be used and receive full IntelliSense based on those types. If you place the cursor in any template, you will see the new template bar:
You may have noticed the “Instantiations” item in the type dropdown below. Visual Studio can now scan your entire codebase to automatically provide suggestions on how the template may be used. You can learn more about the Template Bar here.
Perfect Forwarding IntelliSense (make_unique, make_shared, emplace, emplace_back)
One piece of community feedback that we have received has been to improve the IntelliSense for perfect forwarding templates in C++. We’ve taken the first steps towards that by improving the way a few perfect forwarding templates in the STL are handled. In particular, make_unique, make_shared, emplace, and emplace_back.
Here is how this looked before:
Notice how the parameter help doesn’t list the actual parameters of your type. In the latest version of Visual Studio, it is much more convenient:
We don’t want to stop with just these four STL functions though. We are investigating ways to support your own perfect forwarding templates here as well. As always, we would love to hear your feedback about this. If you are interested in this feel free to open a suggestion on Developer Community.
In addition to language conformance and modernization tools, we also want Visual Studio to be the most productive IDE on the market to get work done. With that in mind, we have added a number of productivity focused IntelliSense features in 2019.
IntelliCode uses machine learning to provide better code-completion recommendations. We added IntelliCode support for C++ in Visual Studio 2019. By default, IntelliCode will give you recommendations on popular libraries such as STL.
We took this a step further in Visual Studio 2019 16.5 where we added the ability to train IntelliCode on your own codebase. This enables you to get smarter completion recommendations on your team’s own types. To keep your Team Completion model up-to-date, you can automate the training process using GitHub Actions or Azure Pipelines.
Intelligent Member List Filtering
The Member List now takes more of your code’s context into account when listing available members. For instance, if you invoke the member list on a const variable, all non-const variables will no longer be shown in the list. Partial matches are also now highlighted in bold in the Member List as well.
Another feature we received feedback from the community about was that our customers wanted Doxygen support in the IDE in addition to XML doc comments. In Visual Studio 2019, Doxygen is now fully supported in C++ and will provide information in the Quick Info and Parameter Help UIs:
Visual Studio does not default to Doxygen style comments, but they can be enabled in “Tools > Options > Text Editor > C/C++ > Code Style > General”. Additionally, you can add your preferred type of doc comment to your project’s .editorconfig file. You can learn more about Doxygen support here.
IntelliSense Colorization and Quick Info Improvements
To help you be as productive as possible, we’ve made several enhancements to the Quick Info, Parameter Help, and Member List UIs. The first thing you might notice is that these UIs are now fully colorized to match the editor:
Quick Info also now allows you to easily search for errors or function and type names online. You can now just hover over any red squiggle in the editor instead of searching through the error list:
Snippet Commit Options
We’ve received feedback to make the commit options for snippets and the Member List more flexible. The defaults remain the same, but there are new options to choose between Enter, Space, and Tab now in “Tools Options > Text Editor > C/C++ > Advanced > IntelliSense”:
Platform Support and Extensibility
We have introduced new flexibility and extensibility in our IntelliSense engines to support a wide variety of platforms, such as Windows, Linux, and consoles. This includes the ability to configure the IntelliSense engine with a CMake toolchain file. These toolchains can be checked in to your code and each configuration can have a unique toolchain bringing an unprecedented amount of flexibility.
Additionally, we have made several updates to the way IntelliSense is handled for remote machines. This improves the accuracy of remote IntelliSense by automatically downloading system and library headers from the remote machine (or WSL) and using them to provide full fidelity IntelliSense with the actual headers on the machine you are targeting.
Send Us Feedback
Please grab a copy of the latest update to Visual Studio and try it out. We would love to hear your feedback about Visual Studio. Please submit any suggestions to Developer Community.