Example of extending C# with custom syntax powered by Visual Studio editor support?

Topics: APIs, General
Nov 5, 2014 at 1:54 PM
Edited Nov 5, 2014 at 1:54 PM
Hi,

Is there a Roslyn sample that would demonstrate the following:

1) Extending C# with a small/medium complexity feature (e.g. "do-until" loop or a shorthand for "public get set property");

2) Getting syntax colouring and some basic static analysis in Visual Studio 2014 for the language extension above - all powered by Roslyn.

Is this even possible?

Thank you.
Nov 5, 2014 at 10:10 PM
Roslyn doesn't have any concept of "language extension" and as far as I know, it's not a goal of Roslyn to make those easier.

If you really wanted to do something like this, you would need to modify many parts of the Roslyn source code.
Nov 6, 2014 at 9:25 AM
Lame :(.

Are there any tutorials on how to create and package custom code analyzers (to enforce extra rules on vanilla C#) and then import them into Visual Studio 2014? Are they supposed to be published via NuGet?

I am pretty sure I have seen a new project tree node above References - something like "Analyzers" - in one of their videos.
Nov 7, 2014 at 3:13 PM
Analyzers in Visual Studio "14" let you see the entire syntax tree and semantic model for the source code in use. They're supposed to be included in NuGet packages to provide code issue (error, squigglies) and refactoring support for the NuGet package's library. For example, a serialization library could provide an error squiggly if you were trying to serialize an object not marked as [Serializable]. I don't think there's any public documentation on analyzers, not that I've been able to find at least.

Extending the language in such a way that doesn't make all of the other tools built on top of Roslyn fall apart, not to mention those built without Roslyn, is a very hard task that has to be accounted for at every step of the design, not only for the compiler but for the language itself. You're basically pulling the rug under many assumptions at many points throughout the parser, compiler and other language analysis. It all has to be updated in sync - and that's now possible for you to do using a Roslyn fork, but it's not possible to do in a plug-and-play manner without a serious amount of infrastructure work.
Nov 7, 2014 at 3:29 PM
JesperTreetop wrote:
I don't think there's any public documentation on analyzers, not that I've been able to find at least.
Same here. They like to talk about "Roslyn and the future of development" but it's always just some C#6 syntactic sugar (that doesn't even need .NET Framework modifications). I am not ungrateful, but would really like to hear the whole story in details - before their release date in 2015.
Nov 10, 2014 at 8:01 AM
It seems to me that the next version of Visual Studio is about to be given a name and a beta. Here's hoping the analyzers have settled down enough to have (at least preliminary) documentation as part of that.