
In today’s post, I’d like to show off another highly requested feature coming to SyntaxEditor for WPF/Silverlight in the 2011.2 version: code fragments!
What Are Code Fragments?
There are often cases where a customer wants to use our advanced C#/VB languages from the .NET Languages Add-on to allow the user to edit either a method body, or even simply an expression. The problem is that for automated IntelliPrompt to continue working, there must be a valid containing class, member, etc. In these scenarios though, the developer doesn’t generally want the end user to be able to see or edit those.
Code fragments is a perfect solution for this scenario. Documents now allow you to optionally set header and footer text. When set, this text is prepended (header) and postpended (footer) to the document snapshot’s text when it is submitted to the language’s parser.
Here’s the new sample for this feature:

You can see that the middle editor is normally what an end user would see, just a set of C# statements. However when the C# parser gets text from that editor to parse, it actually sees the concatenation of the header/fragment/footer text together, and builds an AST and reports syntax errors accordingly. In the screenshot, there is a syntax error squiggle line after firstItem since it expects a close parenthesis.

In the screenshot above, I’ve displayed a completion list for the firstItem variable. This variable was implicitly typed to be an int because its initializer came from the result of a LINQ method on a List<int>, which came in as a parameter from the containing method in the header text.
That’s really cool stuff! With this feature you can now edit statements or an expression in an editor with full IntelliPrompt capabilities. And this all will work seamlessly with any custom language too!
This new feature will be released as part of the 2011.2 version.