未验证 提交 6c0056cb 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #33397 from tiesmaster/fix-33253

Fix #33253: Smart Indent does not handle fluent sequences correctly
......@@ -222,8 +222,7 @@ private IndentationResult GetIndentationBasedOnToken(SyntaxToken token)
return GetIndentationOfLine(sourceText.Lines.GetLineFromPosition(nonTerminalNode.GetFirstToken(includeZeroWidth: true).SpanStart), OptionSet.GetOption(FormattingOptions.IndentationSize, token.Language));
}
// default case
return GetDefaultIndentationFromToken(token);
goto default;
}
case SyntaxKind.CloseBracketToken:
......@@ -237,8 +236,7 @@ private IndentationResult GetIndentationBasedOnToken(SyntaxToken token)
return GetIndentationOfLine(sourceText.Lines.GetLineFromPosition(nonTerminalNode.GetFirstToken(includeZeroWidth: true).SpanStart));
}
// default case
return GetDefaultIndentationFromToken(token);
goto default;
}
case SyntaxKind.XmlTextLiteralToken:
......@@ -251,6 +249,16 @@ private IndentationResult GetIndentationBasedOnToken(SyntaxToken token)
return GetIndentationFromCommaSeparatedList(token);
}
case SyntaxKind.CloseParenToken:
{
if (token.Parent.IsKind(SyntaxKind.ArgumentList))
{
return GetDefaultIndentationFromToken(token.Parent.GetFirstToken(includeZeroWidth: true));
}
goto default;
}
default:
{
return GetDefaultIndentationFromToken(token);
......
......@@ -2711,6 +2711,95 @@ void M(object o)
expectedIndentation: 16);
}
[WpfFact]
[WorkItem(33253, "https://github.com/dotnet/roslyn/issues/33253")]
[Trait(Traits.Feature, Traits.Features.SmartIndent)]
public void EnterAfterFluentSequences_1()
{
var code = @"public class Test
{
public void Test()
{
new List<DateTime>()
.Where(d => d.Kind == DateTimeKind.Local ||
d.Kind == DateTimeKind.Utc)
.ToArray();
}
}";
AssertSmartIndent(
code: code,
indentationLine: 7,
expectedIndentation: 12);
}
[WpfFact]
[WorkItem(33253, "https://github.com/dotnet/roslyn/issues/33253")]
[Trait(Traits.Feature, Traits.Features.SmartIndent)]
public void EnterAfterFluentSequences_2()
{
var code = @"public class Test
{
public void Test()
{
new List<DateTime>()
.Where(d => d.Kind == DateTimeKind.Local ||
d.Kind == DateTimeKind.Utc)
.ToArray();
}
}";
AssertSmartIndent(
code: code,
indentationLine: 7,
expectedIndentation: 16);
}
[WpfFact]
[WorkItem(33253, "https://github.com/dotnet/roslyn/issues/33253")]
[Trait(Traits.Feature, Traits.Features.SmartIndent)]
public void EnterAfterFluentSequences_3()
{
var code = @"public class Test
{
public void Test()
{
new List<DateTime>().Where(d => d.Kind == DateTimeKind.Local ||
d.Kind == DateTimeKind.Utc)
.ToArray();
}
}";
AssertSmartIndent(
code: code,
indentationLine: 6,
expectedIndentation: 12);
}
[WpfFact]
[WorkItem(33253, "https://github.com/dotnet/roslyn/issues/33253")]
[Trait(Traits.Feature, Traits.Features.SmartIndent)]
public void EnterAfterFluentSequences_4()
{
var code = @"public class Test
{
public void Test()
{
new List<DateTime>().Where(d => d.Kind == DateTimeKind.Local || d.Kind == DateTimeKind.Utc)
.ToArray();
}
}";
AssertSmartIndent(
code: code,
indentationLine: 5,
expectedIndentation: 12);
}
private void AssertSmartIndentInProjection(
string markup, int expectedIndentation,
int? expectedBlankLineIndentation = null,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册