NRefactory
NRefactory copied to clipboard
Format Document + open brackets = exception
Sorry I couldn't think of better title :) To reproduce this run Format document on following code:
namespace name
{
It's important there are only 2 lines and not 3(if 3 no exception is thrown). This is very reduced sample from code where I encountered error first time... Exception reported by MonoDevelop:
System.ArgumentOutOfRangeException: Should be < document.TextLength
Parameter name: offset
at ICSharpCode.NRefactory.CSharp.FormattingChanges.AddChange(Int32 offset, Int32 removedChars, String insertedText)
at ICSharpCode.NRefactory.CSharp.FormattingVisitor.AddChange(Int32 offset, Int32 removedChars, String insertedText)
at ICSharpCode.NRefactory.CSharp.FormattingVisitor.AdjustNewLineBlock(AstNode startNode, Int32 targetNewLineCount)
at ICSharpCode.NRefactory.CSharp.FormattingVisitor.EnsureNewLinesAfter(AstNode node, Int32 blankLines)
at ICSharpCode.NRefactory.CSharp.FormattingVisitor.<>c__DisplayClass15.<VisitNamespaceDeclaration>b__14(AstNode child)
at ICSharpCode.NRefactory.CSharp.FormattingVisitor.VisitChildrenToFormat(AstNode parent, Action`1 callback)
at ICSharpCode.NRefactory.CSharp.FormattingVisitor.VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration)
at ICSharpCode.NRefactory.CSharp.NamespaceDeclaration.AcceptVisitor(IAstVisitor visitor)
at ICSharpCode.NRefactory.CSharp.FormattingVisitor.<>c__DisplayClass11.<VisitSyntaxTree>b__10(AstNode child)
at ICSharpCode.NRefactory.CSharp.FormattingVisitor.VisitChildrenToFormat(AstNode parent, Action`1 callback)
at ICSharpCode.NRefactory.CSharp.FormattingVisitor.VisitSyntaxTree(SyntaxTree unit)
at ICSharpCode.NRefactory.CSharp.SyntaxTree.AcceptVisitor(IAstVisitor visitor)
at ICSharpCode.NRefactory.CSharp.CSharpFormatter.AnalyzeFormatting(IDocument document, SyntaxTree syntaxTree, CancellationToken token)
at MonoDevelop.CSharp.Formatting.OnTheFlyFormatter.GetFormattingChanges(PolicyContainer policyParent, IEnumerable`1 mimeTypeChain, Document document, String input, DomRegion formattingRegion, Int32& formatStartOffset, Int32& formatLength, Boolean formatLastStatementOnly)
at MonoDevelop.CSharp.Formatting.OnTheFlyFormatter.Format(PolicyContainer policyParent, IEnumerable`1 mimeTypeChain, Document data, Int32 startOffset, Int32 endOffset, Boolean exact, Boolean formatLastStatementOnly)
at MonoDevelop.CSharp.Formatting.OnTheFlyFormatter.Format(Document data, Int32 startOffset, Int32 endOffset, Boolean exact)
at MonoDevelop.CSharp.Formatting.CSharpFormatter.OnTheFlyFormat(Document doc, Int32 startOffset, Int32 endOffset)
at MonoDevelop.Ide.CodeFormatting.CodeFormatter.OnTheFlyFormat(Document doc, Int32 startOffset, Int32 endOffset)
at MonoDevelop.Ide.CodeFormatting.FormatBufferHandler.Run(Object tool)
at MonoDevelop.Components.Commands.CommandHandler.InternalRun(Object dataItem)
at MonoDevelop.Components.Commands.CommandManager.DefaultDispatchCommand(ActionCommand cmd, CommandInfo info, Object dataItem, Object target, CommandSource source)
at MonoDevelop.Components.Commands.CommandManager.DispatchCommand(Object commandId, Object dataItem, Object initialTarget, CommandSource source)