Visual Studio 2010 MEF vs MPF?

I am learning the addition of a new programming language in visual sudio 2010 and I am a bit confused about the best approach.

I looked through MPF and found some examples of how to do syntax highlighting, link an external parser, etc., and it seems pretty simple.

Then I read about something called MEF and how this is a new extensibility model for visual studio. I played with this, and I have syntax highlighting working following some patterns. Now, with MEF, I get lost on how I communicate in my parser for my langauge, like MPF using ParseSOurce, etc. I am using ANTLR btw.

Is MEF only for the visual aspects of the editor, such as highlighting, decoration, etc., or is it possible / recommended to use language services with it?

From what I am compiling, MEF is a new recommended approach, but it is more difficult to create a new language than regular MPF. Does MPF have a good approach?

+6
source share
3 answers

MEF (Managed Extensibility Framework) is a general .NET programming approach for extending programs such as Visual Studio. VS packages / extensions can use the new VS-MEF classes (contracts) instead of MPF classes. MEF is recognized by classes decorated with [Export] attributes. Typically, you inherit a specific class as a color element and export it to Visual Studio, which then looks at all the exports in your MEF package and imports them.

The MPF (Managed Package Framework) is similar to the class system around the old COM shells of the non-managed / native VS extension model. You programmatically extend Visual Studio by receiving services and implementing MPF class methods (MPF classes, in turn, implement COM-like interfaces. COM-swooning VS. For example, LanguageService implements IVsLanguageInfo and some other interfaces, but it just โ€œcollectsโ€ the interface methods, which can then be overridden in the implementation class of LanguageService ).

If you want to implement a complete programming language, you combine MPF and MEF. You use MEF for parts of the editor, such as tokenization (which is required for syntax highlighting), highlighting, shape matching, etc. And MPF for other VS objects, such as new tool windows, property pages, etc.

Instead of MPF, you can also use old COM wrappers, but the MPF classes already do some COM work for you, which you will have to deal with if you choose COM wrappers.

You can also implement a tokenizer, etc. with MPF, but I tried it and found it much more unintuitive than MEF. If you ask me, it is much more complicated and will require more Braindamage than MEF, but I still have to go through with MEF, as I got with MPF.

This confuses me a bit because MSDN mixes MEF and MPF articles, as I noticed. You should carefully monitor which subdivision of MSDN you go to, you can easily switch from the MEF category to MPF by accident. However, MSDN hints at the fact that there are some general articles on the VS extension, for example here: http://msdn.microsoft.com/en-us/library/cc138569.aspx

+4
source

I am currently implementing a language service exclusively with MEF (in VS2013).

In addition to syntax highlighting (which you can do with ITagger<ClassificationTag> ) and several other special purpose MEF built-in interfaces (for example, for parameter pages and various intellisense types) that you implement as needed, do things like background analysis, you usually implement IVsTextViewCreationListener and do things when the file opens; Alternatively, you can traverse the hierarchy of projects in the background using the Initialize package method as an entry point.

Intellisense features, etc. often require you to respond to a specific command (or track keystrokes to know when, for example, the completion list window pops up); you can handle this by implementing IOleCommandTarget and processing the appropriate commands (you manually intercept your command handler by calling AddCommandFilter on IVsTextView when creating a text view).

So far, I have not come across anything that I cannot do with MEF (except for things that cannot be done at all); I have never looked in MPF โ€‹โ€‹since I do not need it.

(Note that at the end of the day, the code tends to resemble MEF plumbing soup, VS SDK interfaces and helper classes, and EnvDTE goop.)

0
source

Use MEF for functions that are displayed through MEF. Other functions are processed in each case (ask a specific question if you have problems with the implementation of a particular function). The only thing that I still use MPF is project systems (MPF for projects, or MPFProj ). For processing syntax analysis, I recommend taking a look at my implementation of BackgroundParser (MIT license). It works pretty well, although looking back, I would like to use TPL for it and make ReParseImpl return Task instead of synchronous execution.

0
source

Source: https://habr.com/ru/post/917051/