diff options
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormatterService.cs')
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormatterService.cs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormatterService.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormatterService.cs index 834881f688..aa483788ef 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormatterService.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormatterService.cs @@ -29,6 +29,8 @@ using System.Linq; using System.Collections.Generic; using Mono.Addins; using MonoDevelop.Projects.Policies; +using MonoDevelop.Ide.Editor; +using MonoDevelop.Core.Text; namespace MonoDevelop.Ide.CodeFormatting { @@ -68,5 +70,23 @@ namespace MonoDevelop.Ide.CodeFormatting return null; } + + public static void Format (TextEditor editor, DocumentContext ctx, ISegment segment) + { + if (editor == null) + throw new ArgumentNullException ("editor"); + if (ctx == null) + throw new ArgumentNullException ("ctx"); + if (segment == null) + throw new ArgumentNullException ("segment"); + var fmt = GetFormatter (editor.MimeType); + if (fmt == null) + return; + if (fmt.SupportsOnTheFlyFormatting) { + fmt.OnTheFlyFormat (editor, ctx, segment.Offset, segment.EndOffset); + return; + } + editor.Text = fmt.FormatText (ctx.HasProject ? ctx.Project.Policies : null, editor.Text, segment.Offset, segment.EndOffset); + } } } |