Browse Source

Fix #511: Automatic code formatting grabs closing curly brackets when adding properties

pull/516/head
Andreas Weizel 11 years ago
parent
commit
4e45d98165
  1. 8
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormatter.cs

8
src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormatter.cs

@ -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);
}
}

Loading…
Cancel
Save