Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Krüger <mkrueger@xamarin.com>2013-08-29 09:12:28 +0400
committerMike Krüger <mkrueger@xamarin.com>2013-08-29 09:28:26 +0400
commit3f0760554e5b003f57eba7dd46cab24a9ef62f46 (patch)
treeddb9bf57f61612a9c633c3d6862d0f9541995e13 /main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting
parentacdd9843e2ab916b8f84bbf4f12f78d9f1f60386 (diff)
[Ide] Create project no longer crashes on formatting error.
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting')
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormatter.cs21
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormattingCommands.cs11
2 files changed, 26 insertions, 6 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormatter.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormatter.cs
index 566090fdb3..6160c8b056 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormatter.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormatter.cs
@@ -31,6 +31,7 @@ using System.Collections.Generic;
using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.Semantics;
+using MonoDevelop.Core;
namespace MonoDevelop.Ide.CodeFormatting
{
@@ -47,15 +48,29 @@ namespace MonoDevelop.Ide.CodeFormatting
public string FormatText (PolicyContainer policyParent, string input)
{
- return formatter.FormatText (policyParent ?? PolicyService.DefaultPolicies, mimeTypeChain, input);
+ try {
+ return formatter.FormatText (policyParent ?? PolicyService.DefaultPolicies, mimeTypeChain, input);
+ } catch (Exception e) {
+ LoggingService.LogError ("Error while formatting text.", e);
+ }
+ return input;
}
/// <summary>Formats a subrange of the input text.</summary>
/// <returns>The formatted text of the range.</returns>
+ /// <exception cref="T:System.ArgumentOutOfRangeException">When the offsets are out of bounds.</exception>
public string FormatText (PolicyContainer policyParent, string input, int fromOffset, int toOffset)
{
- return formatter.FormatText (policyParent ?? PolicyService.DefaultPolicies, mimeTypeChain,
- input, fromOffset, toOffset);
+ if (fromOffset < 0 || fromOffset > input.Length)
+ throw new ArgumentOutOfRangeException ("fromOffset", "should be >= 0 && < " + input.Length + " was:" + fromOffset);
+ if (toOffset < 0 || toOffset > input.Length)
+ throw new ArgumentOutOfRangeException ("fromOffset", "should be >= 0 && < " + input.Length + " was:" + toOffset);
+ try {
+ return formatter.FormatText (policyParent ?? PolicyService.DefaultPolicies, mimeTypeChain, input, fromOffset, toOffset);
+ } catch (Exception e) {
+ LoggingService.LogError ("Error while formatting text.", e);
+ }
+ return input.Substring (fromOffset, toOffset - fromOffset);
}
public bool SupportsOnTheFlyFormatting {
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormattingCommands.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormattingCommands.cs
index 602fa04b91..580d845f28 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormattingCommands.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormattingCommands.cs
@@ -28,6 +28,7 @@ using System;
using MonoDevelop.Components.Commands;
using MonoDevelop.Projects.Text;
using MonoDevelop.Ide.Gui;
+using MonoDevelop.Core;
namespace MonoDevelop.Ide.CodeFormatting
@@ -108,9 +109,13 @@ namespace MonoDevelop.Ide.CodeFormatting
formatter.OnTheFlyFormat (doc, selection.Offset, selection.EndOffset);
} else {
var pol = doc.Project != null ? doc.Project.Policies : null;
- string text = formatter.FormatText (pol, editor.Text, selection.Offset, selection.EndOffset);
- if (text != null) {
- editor.Replace (selection.Offset, selection.Length, text);
+ try {
+ string text = formatter.FormatText (pol, editor.Text, selection.Offset, selection.EndOffset);
+ if (text != null) {
+ editor.Replace (selection.Offset, selection.Length, text);
+ }
+ } catch (Exception e) {
+ LoggingService.LogError ("Error during format.", e);
}
}