Extensible formatting in Roslyn?
Asked Answered
H

1

7

I have found the code formatting present in the Roslyn CTP quite lacking. But Dustin Campbell mentioned in his talk (around 42:00 mark) that:

The actual formatting engine is also extensible. There's a rules engine there so you can add formatting rules and do custom stuff if you want to, as well.

But when looking at the actual code, I have found only the Format(SyntaxNode) extension method that internally uses an internal class SyntaxFormatter.

My question is: where is the extensibility? Is it present in the Roslyn CTP?

Hypergolic answered 23/4, 2012 at 23:36 Comment(0)
L
4

With the release of the Roslyn June 2012 CTP, this extensibility is now available. To invoke formatting, look at the Format extension method that is in Roslyn.Services.dll (don't forget to add a using Roslyn.Services;.

To expose your own formatting rules, try implementing the Roslyn.Services.Formatting.IFormattingRule interface. Unfortunately, we don't have a sample of this yet, but feel free to ask questions for any issues you run into.

Legg answered 24/4, 2012 at 2:57 Comment(1)
Looks like IFormattingRule is now internal to CodeAnalysis.Workspaces. Any suggestions for what mere consumers of this DLL should do to implement custom formatting rules for, say, code fixes?Roar

© 2022 - 2024 — McMap. All rights reserved.