From f3a87b25962dcfb648bb8cf4ecdfc618f8f5ce14 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 20 May 2009 21:20:41 +0000 Subject: [PATCH] fixed VB .NET Indentation: multiline statements indented correctly (forums/t/9532) git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4094 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../VBNetFormattingStrategy.cs | 15 +++++- .../FormattingStrategy/IndentationTests.cs | 52 +++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs index 662730e902..ee6f2dddea 100644 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs +++ b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs @@ -610,7 +610,8 @@ namespace VBNetBinding.FormattingStrategy } if (IsBlockStart(lexer, currentToken, prevToken)) { - ApplyToRange(textArea, indentation, oldLine, currentToken.Location.Line, begin, end); + int line = GetLastVisualLine(currentToken.Location.Line, textArea); + ApplyToRange(textArea, indentation, oldLine, line, begin, end); if (!inInterface && !isMustOverride && !isDeclare && !isDelegate) { Indent(textArea, indentation); @@ -622,7 +623,7 @@ namespace VBNetBinding.FormattingStrategy if (currentToken.Kind == Tokens.Interface) inInterface = true; - oldLine = currentToken.Location.Line; + oldLine = line; } prevToken = currentToken; @@ -638,6 +639,16 @@ namespace VBNetBinding.FormattingStrategy return indentation.Peek().Length; } + + int GetLastVisualLine(int line, TextArea area) + { + string text = StripComment(area.Document.GetText(area.Document.GetLineSegment(line - 1))); + while (text.EndsWith("_", StringComparison.Ordinal)) { + line++; + text = StripComment(area.Document.GetText(area.Document.GetLineSegment(line - 1))); + } + return line; + } void Unindent(Stack indentation) { diff --git a/src/AddIns/BackendBindings/VBNetBinding/Test/FormattingStrategy/IndentationTests.cs b/src/AddIns/BackendBindings/VBNetBinding/Test/FormattingStrategy/IndentationTests.cs index 986f95d137..bd3f09f5b3 100644 --- a/src/AddIns/BackendBindings/VBNetBinding/Test/FormattingStrategy/IndentationTests.cs +++ b/src/AddIns/BackendBindings/VBNetBinding/Test/FormattingStrategy/IndentationTests.cs @@ -64,6 +64,58 @@ End Class"; RunFormatTest(code, expected); } + [Test] + public void IfLineContinuationTest() + { + string expected = @"Public Class Test + Private Sub Tester() + If True _ + Then + test() + End If + End Sub +End Class"; + + string code = @"Public Class Test +Private Sub Tester() +If True _ +Then +test() +End If +End Sub +End Class"; + + RunFormatTest(code, expected); + } + + [Test] + public void IfMultiLineContinuationTest() + { + string expected = @"Public Class Test + Private Sub Tester() + If IsCorrect(i) _ + And _ + IsHIgherThan(i, 5) _ + Then + test() + End If + End Sub +End Class"; + + string code = @"Public Class Test +Private Sub Tester() +If IsCorrect(i) _ +And _ +IsHIgherThan(i, 5) _ +Then +test() +End If +End Sub +End Class"; + + RunFormatTest(code, expected); + } + void RunFormatTest(string code, string expectedCode) { using (TextEditorControl editor = new TextEditorControl()) {