Dotneteers.net
All for .net, .net for all!

LearnVSXNow! Part #42 – Five Reasons to learn VS 2010 Editor Extensibility

The Visual Studio 2010 Beta 1 has been released only a few days ago. As Quan To wrote in his blog, this is a very important milestone in the life of the Visual Studio Team after a year and half. I think, this milestone is important for the lovers of Visual Studio Extensibility as well. We can touch something really cool thing that never existed before: a new WPF base editor with amazing extensibility features.

I am very proud of being an “extension” to the Microsoft team as an MVP together with all the others working within the VSX community, because I could be very close to them and have seen how they formed the product and how they’ve enhanced it. In the past we had a few public events like the VSX Developers Conference held in September, 2008 the latest PDC and TechEd Developer EMEA in November, TechEd 2009 North America in this month where more and more facts and demos were presented about the new editor and the new extensibility model.

Either you’ve seen any of them or not, in this article I would like to give you a very brief overview about the new editor extensibility and enlist a few reasons motivating you to learn this technology.

1) The new VS 2010 Editor is Cool!

If you read this article, there is a high likelihood that you have seen demos and screenshots about VS 2010 or even have installed VS 2010 Beta 1. The old text editor of Visual Studio has been put to the recycle bin and the VS team created a brand new text editor based on WPF. This was not just a “l’art pour l’art” change because “WPF is Microsoft’s new UX technology, so let’s use it”. Behind the decision there was a clear conception to create an editor able to use WPF’s power, like resolution-independent graphics, images, animations, video, styles, templates, etc. Anyone who dived deeply into WPF and tasted that power, hardly steps back.

Maybe it sounds a bit strange that you can use images (or even video) within a text editor, but it is not just theoretically, but practically true. I think, instead saying “the old text editor has been replaced with a new one”, it would be more precise to say that the old text editor has been replaced with a new source code editor with rich UX opportunities.

2) Clean and Straightforward Architecture

To be honest, I appreciate those guys who tried and managed to extend Visual Studio’s old–or actually the present–text editor, because it is a really hard task full with pitfalls coming basically from the lack of detailed documentation and samples, but mainly from the architectural discrepancies of the editor’s service interfaces. Names of objects and interfaces are often misleading and responsibilities are—let’s say—poorly designed. (Just look at the service interfaces with names like IVsTextLines or IVsTextBuffer to understand what I’m talking about, and these show only the top of the iceberg).

I had several times added small extensions, but I did not like creating them, because the result and the number of code lines to be written did not show a good ratio related to implementing other kind of extensions—even for Visual Studio.

The best news about the new editor—personally I think so—that it has a really clean architecture by means of number of concepts and responsibilities divided among them, and the clean and logical co-operation among the objects representing the concepts.

Without going into details right now, let me mention a few of them just to let you get into the picture. There are text buffers, snapshots, versions, text spans, text views, formatters, tags, etc. The architecture clearly separates handling the text to be edited and operations editing this text form the view that displays the text and providing surface for user interactions.

3) Managed Extensibility Framework

A new technology used in Visual Studio is the Managed Extensibility Framework (MEF) that is a part of the forthcoming .NET 4.0 framework. There are many definitions about what MEF is, argues about how it is related to Dependency Injection and IoC containers, and so on. Instead of making you confused with citing a few of them, I tell you my favorite one: MEF is a formalized contract to shift applications from being statically compiled to dynamically composed.

Without telling too much details about MEF—I definitely would like to dedicate a few articles for this technology—let me summarize the essence in a few sentences.

The whole application is composed of parts marked with metadata (.NET attributes). Services proffered to the application use the [Export] attribute; points where the application can be extended by appropriate services are marked with [Import] attribute. When the application runs, it uses a catalog to dynamically identify components that might be composed with it to form the functionality. For example, in case of Visual Studio 2010 it is the content (assemblies) of a few well-defined folders. MEF uses the catalog and a mechanism called “composition” to dynamically bind the appropriate proffered services to components looking for those specific services.

For editor extensibility using MEF is manifested in one the easiest way of adding new functionality to Visual Studio: you compile the extension and drop the resulted assembly into a certain folder. When Visual Studio starts next time, your extension is dynamically composed with the IDE.

4) The Editor was Designed and Implemented with Extensibility in Mind

As I mentioned, I really like the architecture of the new editor. Another great design principle of the architecture is that the editor was designed with this extensibility in mind. The evidence of this is the fact that internally parts of the editor are composed into a whole “application” by MEF. Actually, what you get with Visual Studio 2010 is a “simple” core editor that is extended by a few dozens of components to form the whole behavior you perceive when working with the editor. When writing your own extensions those have “equal rights” with the ones shipped with Visual Studio.

5) Creating Extensions is Easy!

Thanks to MEF and the architecture of the editor, you have nice patterns and even project templates to create your own extensions. Right now Visual Studio 2010 SDK provides four editor extensibility project templates out of the box: Editor Margin, Editor Classifier, Editor Text Adornment, Editor Viewport Adornment. Each of them provides a simple but functional extension and helping comments to find out the pattern used to create that extension and gives you hints how to start with your own customized extension. If you have ever tried to create a Visual Studio Add-In or a VSPackage before, you will find creating editor extensions more straightforward and using the “real” .NET feeling free from any COM-like stuff.

If you need more samples, try the Extension Manager—this is also new to Visual Studio—and you will find lots of third party extensions, many of them available with source code!


Posted May 22 2009, 07:11 AM by inovak
Filed under: ,

Comments

Mihai Lazar wrote re: LearnVSXNow! Part #42 – Five Reasons to learn VS 2010 Editor Extensibility
on Fri, May 22 2009 7:48

This all has an Ohhh! Yeah feeling to it.. I'm curious when my company will buy the new VS

progg.ru wrote Five Reasons to learn VS 2010 Editor Extensibility
on Fri, May 22 2009 12:00

Thank you for submitting this cool story - Trackback from progg.ru

Quan To's Visual Studio Extensibility blog wrote 5 Reasons to learn about extending VS 2010
on Fri, May 22 2009 21:33

One of our Visual Studio Extensibility MVPs just put together a great blog about why you should learn

Tune Up Your PC » Post Topic » 5 Reasons to learn about extending VS 2010 wrote Tune Up Your PC » Post Topic » 5 Reasons to learn about extending VS 2010
on Fri, May 22 2009 22:43

Pingback from  Tune Up Your PC  » Post Topic   » 5 Reasons to learn about extending VS 2010

DotNetShoutout wrote LearnVSXNow! Part #42 – Five Reasons to learn VS 2010 Editor Extensibility - DiveDeeper's blog - Dotneteers.net
on Sat, May 23 2009 21:33

Thank you for submitting this cool story - Trackback from DotNetShoutout

Fei wrote re: LearnVSXNow! Part #42 – Five Reasons to learn VS 2010 Editor Extensibility
on Tue, May 26 2009 2:02

Hello, do you have any idea weather a plugin project can be combined with an extersion project?

inovak wrote re: LearnVSXNow! Part #42 – Five Reasons to learn VS 2010 Editor Extensibility
on Tue, May 26 2009 6:22

Hey Fei,

Unfortunately, I do not really understand what you mean by plugin project... Maybe a VS Add-In? And what do you mean by combining?

DiveDeeper's blog wrote LearnVSXNow! Part #43 – Introducing the Managed Extensibility Framework
on Tue, May 26 2009 8:11

Visual Studio has many points to extend and also many ways to do that. We can customize Visual Studio

GA30 wrote re: LearnVSXNow! Part #42 – Five Reasons to learn VS 2010 Editor Extensibility
on Sun, Jun 28 2009 23:47

Inovak,

Do you have any clues how custom editors, like the the BlogItemEditor, are affected by VS 2010? Is there a new way of creating custom editors like BlogItemEditor?

inovak wrote re: LearnVSXNow! Part #42 – Five Reasons to learn VS 2010 Editor Extensibility
on Mon, Jun 29 2009 8:29

Hey GA30,

As I know this time, VS 2010 will not bring too much new things about creating custom editors. In September I will start moving VSXtra to VS 2010 Beta 1.

I have a few feedbacks from community members using VSXtra that the binaries compiled with VS 2008 work with VS 2010 Beta1 seemlessly. Of course, VSXtra need a careful testing under VS 2010, that is what I'm oing to do in September.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?