|
|
|
@ -31,11 +31,17 @@ namespace CSharpBinding.FormattingStrategy
@@ -31,11 +31,17 @@ namespace CSharpBinding.FormattingStrategy
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void Format(ITextEditor editor, int offset, int length, CSharpFormattingOptionsContainer optionsContainer) |
|
|
|
|
{ |
|
|
|
|
SyntaxTree syntaxTree = SyntaxTree.Parse(editor.Document); |
|
|
|
|
if (syntaxTree.Errors.Count > 0) { |
|
|
|
|
// Don't format files containing syntax errors!
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TextEditorOptions editorOptions = editor.ToEditorOptions(); |
|
|
|
|
optionsContainer.CustomizeEditorOptions(editorOptions); |
|
|
|
|
var formatter = new CSharpFormatter(optionsContainer.GetEffectiveOptions(), editorOptions); |
|
|
|
|
formatter.AddFormattingRegion(new DomRegion(editor.Document.GetLocation(offset), editor.Document.GetLocation(offset + length))); |
|
|
|
|
var changes = formatter.AnalyzeFormatting(editor.Document, SyntaxTree.Parse(editor.Document)); |
|
|
|
|
var changes = formatter.AnalyzeFormatting(editor.Document, syntaxTree); |
|
|
|
|
changes.ApplyChanges(offset, length); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|