Django Editor in VS 2010 – Part 0 (Background)

Look here for complete source

The purpose of this post series is to give you a concrete proof (with code samples) of how easy it is to build custom text editors with Visual Studio 2010. But before we dive into the details please bear with me as I give you some background.

Ok we've got NDjango - nice language, everybody's happy with it, just loves it, fine. Now, how about an editor for ndjango templates? NDjango is django ported to .NET so, naturally, the editor is supposed to be integrated with Visual Studio.

What would be necessary here is a text editor with syntax highlighting, error reporting and code completion to support django syntax in the templates built for .NET applications. Django templates can be used to generate text files of various types - including html, json, xml to name a few. So all features of the django template editor should work in addition to the features already provided, i.e. for an html file syntax highlighting and code completion should work both for django as well as for the existing html.

Visual Studio 2008 provides variety of ways for custom editor  integration. It also allows building custom editors on top of the generic text editor. While building the editor this way is certainly doable, it is really heavy lifting. You need to implement your own language service with your own implementation of IVsLanguageInfo, IVsCompletionSet, IVsLanguageDebugInfo, - the list goes on and on.

And this is not the worst of it. After you are done with all the plumbing registering and have your nice editor for your nice language, you still have a problem. The Visual Studio Core Editor used as a starting point is a bare bones editor with not much beyond simple cut copy paste. If you need more - you are the one to implement it. If you need html support (at least I do) - build it.

Wouldn't it be nice if instead of building all this stuff from scratch I could piggy back on the existing editors? - Oh well...

As I was gathering my courage before I plunge head first into the task of building the NDjango Language service somebody told me to have a look at Visual Studio 2010 beta 1. So I did and now I am writing this still in awe at how much simpler it is.  

The simplicity comes in two flavors. First of all now rather than writing your own you indeed amend the behavior of the existing editors providing simple plug-ins for the functions you want to affect - i.e. coloring your tags. Secondly, thanks to MEF, the plumbing necessary for your plugins to play nice with Visual Studio is virtually non-existing.

OK. Now it is time to stop blabbering and start dig into specifics. In the next post I will start with the colorization code for the NDjango template editor.

Leave a Reply