Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 4e45d98

Browse files
committed
Fix #511: Automatic code formatting grabs closing curly brackets when adding properties
1 parent 9744db9 commit 4e45d98

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,17 @@ internal class CSharpFormatterHelper
3131
/// </summary>
3232
public static void Format(ITextEditor editor, int offset, int length, CSharpFormattingOptionsContainer optionsContainer)
3333
{
34+
SyntaxTree syntaxTree = SyntaxTree.Parse(editor.Document);
35+
if (syntaxTree.Errors.Count > 0) {
36+
// Don't format files containing syntax errors!
37+
return;
38+
}
39+
3440
TextEditorOptions editorOptions = editor.ToEditorOptions();
3541
optionsContainer.CustomizeEditorOptions(editorOptions);
3642
var formatter = new CSharpFormatter(optionsContainer.GetEffectiveOptions(), editorOptions);
3743
formatter.AddFormattingRegion(new DomRegion(editor.Document.GetLocation(offset), editor.Document.GetLocation(offset + length)));
38-
var changes = formatter.AnalyzeFormatting(editor.Document, SyntaxTree.Parse(editor.Document));
44+
var changes = formatter.AnalyzeFormatting(editor.Document, syntaxTree);
3945
changes.ApplyChanges(offset, length);
4046
}
4147
}

0 commit comments

Comments
 (0)