Browse Source

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
shortcuts
Siegfried Pammer 16 years ago
parent
commit
f3a87b2596
  1. 15
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs
  2. 52
      src/AddIns/BackendBindings/VBNetBinding/Test/FormattingStrategy/IndentationTests.cs

15
src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs

@ -610,7 +610,8 @@ namespace VBNetBinding.FormattingStrategy @@ -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 @@ -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 @@ -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<string> indentation)
{

52
src/AddIns/BackendBindings/VBNetBinding/Test/FormattingStrategy/IndentationTests.cs

@ -64,6 +64,58 @@ End Class"; @@ -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()) {

Loading…
Cancel
Save