In part 2 of the tutorial we created a simple VS extension with a single Menu item.
The extension will eventually be able to add code documentation in a separate file (.cs.cdocs) and view it in a nice Heads-Up display. The tutorial explains every step of the way to build such an extension.
For starters, we need the ability to select a piece of code and add documentation, which is what we’ll be doing here.
We’re going to add a new Menu item to the code editor’s context menu. When invoked, the extension will find the selected text and its Span (From where to where). Then, it’s just a matter of showing a nice Popup window for the user to edit the documentation.
The previous blog post introduced the wonderful world of Visual Studio extensions.
Let’s start and do some coding. During the tutorial we are going to build a VS extensions called CodyDocs and place it on GitHub.
CodyDocs will save code documentation in a separate file and the extension will allow to view and edit the documentation in the editor itself.
In the first part, we’ll start with a simple “Hello World” program. We’ll create an extensions with a Menu item that does something. I’ll make things a bit more interesting and make the menu item act as a checkbox.
Starting the project
A great way to start any feature is to add a button to disable it. So first order of business: Add a checkable menu item to Enable and Disable the feature our extension performs.
First, we’ll create a new project with File -> New Project -> VSIX project and call it CodyDocs.
Now to be able to enable and disable the feature, we need the ability to store a bool value that stores our setting.
Ever used Resharper, CodeMaid, WebEssentials, OzCode or CodeRush?
Those are pretty incredible tools, right?
Ever thought about developing an extensions for yourself and your team? Maybe a little something that edits the very difficult configuration files your company invented?
Or how about an extensions that automatically performs a localization merge?
There are a lot of advantages to in-house VS extensions and some big companies even have a dedicated team to work on in-house VS extensions. Extensions development is a very useful skill to have in your toolbox.
Working on OzCode, an awesome extension that helps debugging, I discovered a new world of knowledge. I’m going to write a series of blog posts introducing the wonderful world of VS extensibility.
So what can a VS extension do?
If you used Resharper or any other mentioned extension, you know the extension can do almost anything. Here are some examples:
- Add commands to VS Menu.
- Analyze code files with Roslyn.
- Change code files and projects.
In my previous company, we experienced a reoccurring nightmare. It went something like this:
New critical bug arrived from QA:
Program suddenly crashed. Reproduces 1 / 10 times. Reproduce steps – unclear.
The development team, after realizing they are unable to reproduce the bug on their development machine would claim the bug doesn’t reproduce, moving the ticket back to QA.
In return, the QA team reproduced the bug, moving the ticket back to dev.
Then, the development team would claim another layer of the code caused the bug, moving the ticket to a second development team maintaining that code.
The second development team, with spite, would find an obscure line of code in the log file proving the bug is actually not in their layer of code, moving the ticket to the original dev team.
This would go on until either the development team succeeded in moving the bug to backlog or, in rare cases and by sheer luck, the development team was able to solve the bug.
In our defense, all the coders who originally built the system were long gone, the application was huge and complicated.
I guess not much of an excuse but eventually we learned some tricks to help us solve those pesky crash bugs.
Well, some developers learned. Others kept claiming the bug doesn’t reproduce 🙂
Introducing our bag of tricks: