提交 113a030b 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #15240 from CyrusNajmabadi/splitStrings

Typing <enter> after an interpolated string should not cause 'split string' to invoke.
......@@ -25,16 +25,9 @@ private class InterpolatedStringSplitter : StringSplitter
protected override SyntaxNode GetNodeToReplace() => _interpolatedStringExpression;
// Don't offer on $@"" strings. They support newlines directly in their content.
protected override bool CheckToken()
{
if (_interpolatedStringExpression.StringStartToken.Kind() == SyntaxKind.InterpolatedVerbatimStringStartToken)
{
// Don't offer on $@"" strings. They support newlines directly in their content.
return false;
}
return true;
}
=> _interpolatedStringExpression.StringStartToken.Kind() != SyntaxKind.InterpolatedVerbatimStringStartToken;
protected override BinaryExpressionSyntax CreateSplitString()
{
......
......@@ -18,21 +18,9 @@ public SimpleStringSplitter(Document document, int position, SyntaxNode root, So
_token = token;
}
// Don't split @"" strings. They already support directly embedding newlines.
protected override bool CheckToken()
{
if (CursorPosition <= _token.SpanStart || CursorPosition >= _token.Span.End)
{
return false;
}
if (_token.IsVerbatimStringLiteral())
{
// Don't split @"" strings. They already support directly embedding newlines.
return false;
}
return true;
}
=> !_token.IsVerbatimStringLiteral();
protected override SyntaxNode GetNodeToReplace() => _token.Parent;
......
......@@ -91,6 +91,13 @@ private static bool IsInterpolationOpenBrace(SyntaxToken token, int position)
public int? TrySplit()
{
var nodeToReplace = GetNodeToReplace();
if (CursorPosition <= nodeToReplace.SpanStart || CursorPosition >= nodeToReplace.Span.End)
{
return null;
}
if (!CheckToken())
{
return null;
......
......@@ -91,7 +91,7 @@ void M()
}
[WpfFact, Trait(Traits.Feature, Traits.Features.SplitStringLiteral)]
public async Task TestMissingAfterString()
public async Task TestMissingAfterString_1()
{
await TestNotHandledAsync(
@"class C
......@@ -104,7 +104,46 @@ void M()
}
[WpfFact, Trait(Traits.Feature, Traits.Features.SplitStringLiteral)]
public async Task TestMissingAfterInterpolatedString()
public async Task TestMissingAfterString_2()
{
await TestNotHandledAsync(
@"class C
{
void M()
{
var v = """" [||];
}
}");
}
[WpfFact, Trait(Traits.Feature, Traits.Features.SplitStringLiteral)]
public async Task TestMissingAfterString_3()
{
await TestNotHandledAsync(
@"class C
{
void M()
{
var v = """"[||]
}
}");
}
[WpfFact, Trait(Traits.Feature, Traits.Features.SplitStringLiteral)]
public async Task TestMissingAfterString_4()
{
await TestNotHandledAsync(
@"class C
{
void M()
{
var v = """" [||]
}
}");
}
[WpfFact, Trait(Traits.Feature, Traits.Features.SplitStringLiteral)]
public async Task TestMissingAfterInterpolatedString_1()
{
await TestNotHandledAsync(
@"class C
......@@ -116,6 +155,45 @@ void M()
}");
}
[WpfFact, Trait(Traits.Feature, Traits.Features.SplitStringLiteral)]
public async Task TestMissingAfterInterpolatedString_2()
{
await TestNotHandledAsync(
@"class C
{
void M()
{
var v = $"""" [||];
}
}");
}
[WpfFact, Trait(Traits.Feature, Traits.Features.SplitStringLiteral)]
public async Task TestMissingAfterInterpolatedString_3()
{
await TestNotHandledAsync(
@"class C
{
void M()
{
var v = $""""[||]
}
}");
}
[WpfFact, Trait(Traits.Feature, Traits.Features.SplitStringLiteral)]
public async Task TestMissingAfterInterpolatedString_4()
{
await TestNotHandledAsync(
@"class C
{
void M()
{
var v = $"""" [||]
}
}");
}
[WpfFact, Trait(Traits.Feature, Traits.Features.SplitStringLiteral)]
public async Task TestMissingInVerbatimString()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册