未验证 提交 36179333 编写于 作者: C Cheryl Borley 提交者: GitHub

Don't complete statement when in multi-line verbatim string that is passed to a method (#34177)

* Fixes #34176

* Fix test name

* Update tests - WIP

* Fix conditional

* Improve conditional

* add tests and check for caret before string
上级 525883f2
......@@ -242,9 +242,10 @@ private static bool IsStatementOrFieldDeclaration(SyntaxNode currentNode, ISynta
=> syntaxFacts.IsStatement(currentNode) || currentNode.IsKind(SyntaxKind.FieldDeclaration);
private static bool IsInAString(SyntaxNode currentNode, SnapshotPoint caret)
// If caret is at the end of the line, it is outside the string
// Check to see if caret is before or after string
=> currentNode.IsKind(SyntaxKind.InterpolatedStringExpression, SyntaxKind.StringLiteralExpression)
&& caret.Position != caret.GetContainingLine().End;
&& caret.Position < currentNode.Span.End
&& caret.Position > currentNode.SpanStart;
private static bool StatementIsACandidate(SyntaxNode currentNode, int caretPosition)
{
......
......@@ -134,6 +134,28 @@ public void ArgumentListOfMethodInvocation_SemicolonAlreadyExists()
VerifyTypingSemicolon(code, expected);
}
[WorkItem(34176, "https://github.com/dotnet/roslyn/pull/34177")]
[WpfFact, Trait(Traits.Feature, Traits.Features.CompleteStatement)]
public void ArgumentListOfMethodInvocation_StringAsMethodArgument()
{
var code = CreateTestWithMethodCall(@"var test = Console.WriteLine( $$""Test"")");
var expected = CreateTestWithMethodCall(@"var test = Console.WriteLine( ""Test"");$$");
VerifyTypingSemicolon(code, expected);
}
[WorkItem(34176, "https://github.com/dotnet/roslyn/pull/34177")]
[WpfFact, Trait(Traits.Feature, Traits.Features.CompleteStatement)]
public void ArgumentListOfMethodInvocation_StringAsMethodArgument2()
{
var code = CreateTestWithMethodCall(@"var test = Console.WriteLine( ""Test""$$ )");
var expected = CreateTestWithMethodCall(@"var test = Console.WriteLine( ""Test"" );$$");
VerifyTypingSemicolon(code, expected);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.CompleteStatement)]
public void ArgumentListOfMethodInvocation_MultiLine()
{
......@@ -2952,6 +2974,29 @@ public void DontComplete_String3()
VerifyNoSpecialSemicolonHandling(code);
}
[WorkItem(34176, "https://github.com/dotnet/roslyn/issues/34176")]
[WpfFact, Trait(Traits.Feature, Traits.Features.CompleteStatement)]
public void DontComplete_VerbatimStringAsMethodArgument_EndOfLine_NotEndOfString()
{
var code = @"
var code = Foo(@""$$
"") ;
";
VerifyNoSpecialSemicolonHandling(code);
}
[WorkItem(34176, "https://github.com/dotnet/roslyn/issues/34176")]
[WpfFact, Trait(Traits.Feature, Traits.Features.CompleteStatement)]
public void DontComplete_VerbatimStringAsMethodArgument_EndOfString_NotEndOfLine()
{
var code = @"
var code = Foo(@"" $$"" //comments
);
";
VerifyNoSpecialSemicolonHandling(code);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.CompleteStatement)]
public void DontComplete_InterpolatedString()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册