diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2012-06-04 10:19:37 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2012-06-04 10:19:37 +0400 |
commit | a5de964c5880f19234f1c503dcfab23943d022bc (patch) | |
tree | fe7b68fef67e437b4349ef947d736a111e207c04 /main/src | |
parent | ee471e548bb2e6a59c2799ef5b02a711b6f25476 (diff) |
Fixed 'Bug 5485 - "Format document on save" doesn't'.
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/OnTheFlyFormatter.cs | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/OnTheFlyFormatter.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/OnTheFlyFormatter.cs index 4e77243056..6c3a7770f4 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/OnTheFlyFormatter.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/OnTheFlyFormatter.cs @@ -49,19 +49,19 @@ namespace MonoDevelop.CSharp.Formatting public static void Format (MonoDevelop.Ide.Gui.Document data, TextLocation location) { - Format (data, location, location); + Format (data, location, location, false); } - public static void Format (MonoDevelop.Ide.Gui.Document data, TextLocation startLocation, TextLocation endLocation) + public static void Format (MonoDevelop.Ide.Gui.Document data, TextLocation startLocation, TextLocation endLocation, bool exact = true) { - Format (data, data.Editor.LocationToOffset (startLocation), data.Editor.LocationToOffset (endLocation)); + Format (data, data.Editor.LocationToOffset (startLocation), data.Editor.LocationToOffset (endLocation), exact); } - public static void Format (MonoDevelop.Ide.Gui.Document data, int startOffset, int endOffset) + public static void Format (MonoDevelop.Ide.Gui.Document data, int startOffset, int endOffset, bool exact = true) { var policyParent = data.Project != null ? data.Project.Policies : PolicyService.DefaultPolicies; var mimeTypeChain = DesktopService.GetMimeTypeInheritanceChain (CSharpFormatter.MimeType); - Format (policyParent, mimeTypeChain, data, startOffset, endOffset); + Format (policyParent, mimeTypeChain, data, startOffset, endOffset, exact); } @@ -150,24 +150,34 @@ namespace MonoDevelop.CSharp.Formatting } } - public static void Format (PolicyContainer policyParent, IEnumerable<string> mimeTypeChain, MonoDevelop.Ide.Gui.Document data, int startOffset, int endOffset) + public static void Format (PolicyContainer policyParent, IEnumerable<string> mimeTypeChain, MonoDevelop.Ide.Gui.Document data, int startOffset, int endOffset, bool exact) { if (data.ParsedDocument == null) return; var ext = data.GetContent<CSharpCompletionTextEditorExtension> (); if (ext == null) return; - var seg = ext.typeSystemSegmentTree.GetMemberSegmentAt (startOffset - 1); - if (seg == null) - return; - var member = seg.Entity; - if (member == null || member.Region.IsEmpty || member.BodyRegion.End.IsEmpty) - return; - - // Build stub - int formatStartOffset; - var text = BuildStub (data, seg, startOffset, endOffset, out formatStartOffset); - int formatLength = endOffset - seg.Offset; + string text; + int formatStartOffset, formatLength, realTextDelta; + if (exact) { + text = data.Editor.Text; + formatStartOffset = startOffset; + formatLength = endOffset - startOffset; + realTextDelta = 0; + } else { + var seg = ext.typeSystemSegmentTree.GetMemberSegmentAt (startOffset - 1); + if (seg == null) + return; + var member = seg.Entity; + if (member == null || member.Region.IsEmpty || member.BodyRegion.End.IsEmpty) + return; + + // Build stub + text = BuildStub (data, seg, startOffset, endOffset, out formatStartOffset); + formatLength = endOffset - seg.Offset; + realTextDelta = seg.Offset - formatStartOffset; + } + // Get changes from formatting visitor var changes = GetFormattingChanges (policyParent, mimeTypeChain, data, text); if (changes == null) @@ -176,7 +186,6 @@ namespace MonoDevelop.CSharp.Formatting // Do the actual formatting // var originalVersion = data.Editor.Document.Version; - int realTextDelta = seg.Offset - formatStartOffset; int startDelta = 1; using (var undo = data.Editor.OpenUndoGroup ()) { try { |