Hello C++ World!
Update (1/6/2015): Check out all these features in action — as well as how they’ve been improved since Preview — in this video!
With Wednesday’s release of Visual Studio 2015 Preview, we are pleased to present you with new and improved coding productivity features, not the least of which is (finally) Refactoring for C++! Special thanks goes out to you folks who tried out the Visual Studio “14” CTPs and left us feedback; we tried to incorporate as many suggestions as we could in time for Preview, and we will continue to polish the features!
I wanted to take some time to call out the refactoring features, from the basics of how to invoke each feature, to neat little tricks that you might enjoy! The following features will be covered in this post:
- Rename
- Extract Function
- Implement Pure Virtuals
- Create Declaration/Definition
- Move Function Definition
- Convert to Raw-String Literal
- To hide comments/strings from the preview window results, leave “Search comments/strings” unchecked.
- To show all comments/strings in the preview window, but leave each entry unchecked by default, leave “Rename comments/strings” unchecked.
- To show and check by default all comments/strings, check “Rename comments/strings.”
-
For more information (from the feature’s extension days), watch “Rename” Refactoring for Visual C++ on Channel 9.
Extract Function was our second-most requested feature. We’re still tweaking it a bit, so we’ve released it as an extension for the time being; please give us feedback on the feature! Once you’ve installed the extension, select a block of code, right-click, and find the feature under “Refactor…” (You can also invoke it using Ctrl+R, Ctrl+M.)
- The tool has some built-in error checking, like if you select a partial expression, but for best results, try to select valid, well-formed code.
- The extracted function will match your current context. For example, if you extract code from a member function, the extracted function will be a member function as well (and a forward declaration will be created for you).
Implement Pure Virtuals stubs out all the pure virtuals from the base classes that a class inherits. Both multiple and recursive inheritances are supported. The feature can be invoked from the class definition.
- The feature encourages good coding practice, so it will create forward declarations in the header and the definition stubs in the source. If a namesake source doesn’t exist, it will be created.
-
Invoke the feature on an inherited base to implement pure virtuals only from that particular base.
- A single undo operation will remove all created forward declarations and definitions, but it will not remove a generated .cpp (if one was created).
- For more information (from the feature’s CTP days), watch this video.
Aside: The previous three features rely on IntelliSense being available for the current Translation Unit (TU) where the features are invoked. If IntelliSense is not working (which you can usually infer by the lack of semantic colorization), or if your code has a lot of compile errors/red squiggles, the features will not work as reliably.
Create Declaration/Definition allows you to quickly create a function’s counterpart from either its forward declaration or its definition. To support good coding practices and to alleviate context switching, the Peek Definition feature shows you where the counterpart was created. Activate the feature via LightBulb.
Before:
After:
- The feature encourages good coding practice, so it will position the created function relative to neighboring functions. If no context is evident, it will find the namesake .h or .cpp to place the function, or create one if it doesn’t exist.
- A green squiggle appears (along with a LightBulb when hovered over) when we detect that a function has been declared but not defined.
-
Want to create counterparts for multiple functions? Just select code so that it contains all the functions you need (your selection doesn’t even have to be precise!), right-click, go to Refactor…, and invoke the feature.
- If you don’t like where the feature placed the counterpart, use the copy-to-clipboard feature via the LightBulb, and then paste it where it is supposed to go.
-
For more information (from the feature’s CTP days), watch this video.
- Shares the following features with Create Declaration/Definition: relative positioning, Peek Definition, batch/mass operation
-
For more information (from the feature’s CTP days), watch this video.
-
Only those escape sequences having textual implications are supported:
- \n – new line
- \t – tab
- \’ – single quote
- \” – double quote
- \? – question mark
- \\ – backslash
- If your string contains any other escape sequence, it will give you a failure message with the first unsupported escape sequence found.
- There is no feature to convert back to a non-raw-string literal — just use the undo key 😉
Please try out the features, and leave us your feedback, negative and positive. Thank you for your time, and for helping us make Visual Studio a better product!
Best regards,
Gabriel Ha
Visual C++ PM
0 comments