In-editor code analysis in Visual Studio 2019 Preview 2

eli fessler

eli

The C++ team has been working to refresh the Code Analysis experience inside Visual Studio. Last year, we blogged about some in-progress features in this area. We’re happy to announce that in Visual Studio 2019 Preview 2, we’ve integrated code analysis directly into the editor, improved upon previously experimental features, and enabled this as the default experience.

In-editor warnings & background analysis

Code analysis now runs automatically in the background, and warnings display as green squiggles in-editor. Analysis re-runs every time you open a file in the editor and when you save your changes.

If you wish to disable – or re-enable – this feature, you can do so via the Tools > Options > Text Editor > C++ > Experimental > Code Analysis menu, where you’ll also be able to toggle squiggles displaying in-editor or the entire new C++ Code Analysis/Error List experience.

Squiggle display improvements

We’ve also made a few improvements to the display style of in-editor warnings. Squiggles are now only displayed underneath the code segment that is relevant to the warning. If we cannot find the appropriate code segment, we fall back to the Visual Studio 2017 behavior of showing the squiggle for the entire line.

Visual Studio 2017

Visual Studio 2019

We’ve also made performance improvements, especially for source files with many C++ code analysis warnings. Latency from when the file is analyzed until green squiggles appear has been greatly improved, and we’ve also enhanced the overall UI performance during code analysis squiggle display.

Light bulb suggestions & quick fixes

We’ve begun adding light bulb suggestions to provide automatic fixes for warnings. Please see the C++ Productivity Improvements in Visual Studio 2019 Preview 2 blog post for more information.

Send us feedback

Thank you to everyone who helps make Visual Studio a better experience for all. Your feedback is critical in ensuring we can deliver the best Code Analysis experience. We’d love for you to download Visual Studio 2019 Preview 2, give it a try, and let us know how it’s working for you in the comments below or via email (visualcpp@microsoft.com). If you encounter problems or have a suggestion, please let us know through Help > Send Feedback > Report A Problem / Provide a Suggestion or via Visual Studio Developer Community. You can also find us on Twitter @VisualC.

eli fessler
eli fessler

Follow eli   

1 Comments
Avatar
Chris McKillroy 2019-06-16 22:14:17
As a C++ newbie, I absolutely love the green squiggles, often they are like a teacher looking over my shoulders, but there's some oddities sometimes. E.g. I am writing a test for some code in a custom  allocator and have a const T* pointer td_array_base and want to derive a pointer to an element inside the buffer it is pointing to:testdata* ptr = const_cast<testdata*>( td_array_base );I am getting the green squiggles to "not cast away const" (26492).But testdata* ptr = td_array_base;doesn't work either and I get the error: ("Cant initialize testdata* from const testdata*").Ofc I'm going for the green squiggles here, but I had several cases, where I would have needed to use a pair of #pragma warning( 12345678 : disable) ..#pragma warning( 12345678 : enable) to neutralize the squiggles ( OFC I could just keep and learn to love them ;) )However: a simple tool to cast away the squiggles for a single line in certain cases would be cool to have,e.g. like ("wrap line in pragma disable warning") - for the specific warning.