Monthly Archives: January 2018

Visual Studio 2017 Extension development tutorial part 6: Follow a span of code with TrackingSpan

Tutorial Table of Contents:

Part 1: Introduction to VS extensibility
Part 2: Add Menu Item
Part 3: Add command to context menu and get selected code
Part 4: Show a popup Window
Part 5: Highlight code in Editor

During the tutorial we are going to build a VS extensions called CodyDocs and place it on GitHub. Each tutorial part is a standalone tutorial on a specific topic and can be viewed individually. CodyDocs will save code documentation (code comments) in a separate file and the extension will allow to view and edit the documentation in the editor itself.

Part 6: Follow a span of code with TrackingSpan

In this tutorial we’re going to learn how to follow (track) code range (aka Span) in Visual Studio’s code editor. By tracking code span, I mean being able to follow the location of a specific code span, while the user edits the document.

For example, in our case, say we added documentation to a certain method MyMethod, which was in row 20 and column 1-12. This documentation was serialized to a file. Now, the user added some code and MyMethod is no longer in row 20. It’s now in row 30.

We’ll see how to “mark” the initial code span in row 20 and find out the new location when the document changes.

Continue reading

7 Debugging Techniques you should know in C# .NET

I think I spend more time debugging code than writing code, designing software architecture, trying to reproduce bugs and even going to meetings! Debugging is the biggest time consumer we have as developers.

As time goes by, I keep learning new tricks that make my debugging more effective. I’ve gathered in this post 7 debugging techniques that I learned relatively late into my career and I consider advanced (though sometimes something advanced for some is trivial for others). Enjoy and I hope you learn something new!

Continue reading

Visual Studio 2017 Extension development tutorial part 5: Highlight code in Editor

Tutorial Table of Contents:

Part 1: Introduction to VS extensibility
Part 2: Add Menu Item
Part 3: Add command to context menu and get selected code
Part 4: Show a popup Window
part 6: Follow a span of code with TrackingSpan

During the tutorial we are going to build a VS extensions called CodyDocs and place it on GitHub. Each tutorial part is a standalone tutorial on a specific topic and can be viewed individually. CodyDocs will save code documentation in a separate file and the extension will allow to view and edit the documentation in the editor itself.

Part 5: Highlight code in Editor

In this tutorial we’re going to learn how to highlight code in Visual Studio’s code editor. This includes highlighting text by changing Background color, changing Foreground color and adding border.

If you followed the rest of the series, in the previous tutorial we allowed the user to select text and add documentation for the selection. The documentation was then serialized to a file. In this part, we will show how to highlight all the text spans that have had documentation added to them.

Continue reading