提交 eff472bd 编写于 作者: C Cyrus Najmabadi

Do not try to convert interpolated string format specifiers into virtual chars.

上级 4bb1ffe5
......@@ -3079,5 +3079,15 @@ public async Task TestDirectiveStringLiteral()
{
await TestInMethodAsync(@"#line 1 ""a\b""");
}
[WorkItem(30378, "https://github.com/dotnet/roslyn/issues/30378")]
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task TestFormatSpecifierInInterpolation()
{
await TestInMethodAsync(@"var goo = $""goo{{1:0000}}bar"";",
Keyword("var"),
Escape(@"{{"),
Escape(@"}}"));
}
}
}
......@@ -721,5 +721,13 @@ End Operator"
Await TestAsync("#region ""goo""""bar""",
Escape(""""""))
End Function
<WorkItem(30378, "https://github.com/dotnet/roslyn/issues/30378")>
<Fact, Trait(Traits.Feature, Traits.Features.Classification)>
Public Async Function TestFormatSpecifierInInterpolation() As Task
Await TestInMethodAsync("dim goo = $""goo{{1:0000}}bar""",
Escape("{{"),
Escape("}}"))
End Function
End Class
End Namespace
......@@ -48,17 +48,21 @@ protected override ImmutableArray<VirtualChar> TryConvertToVirtualCharsWorker(Sy
? TryConvertVerbatimStringToVirtualChars(token, "@\"", "\"", escapeBraces: false)
: TryConvertStringToVirtualChars(token, "\"", "\"", escapeBraces: false);
}
else if (token.Kind() == SyntaxKind.InterpolatedStringTextToken)
if (token.Kind() == SyntaxKind.InterpolatedStringTextToken)
{
// The sections between `}` and `{` are InterpolatedStringTextToken *as are* the
// format specifiers in an interpolated string. We only want to get the virtual
// chars for this first type.
if (token.Parent.Parent is InterpolatedStringExpressionSyntax interpolatedString)
{
var interpolatedString = (InterpolatedStringExpressionSyntax)token.Parent.Parent;
return interpolatedString.StringStartToken.Kind() == SyntaxKind.InterpolatedVerbatimStringStartToken
? TryConvertVerbatimStringToVirtualChars(token, "", "", escapeBraces: true)
: TryConvertStringToVirtualChars(token, "", "", escapeBraces: true);
}
else
{
return default;
}
return default;
}
private bool IsInDirective(SyntaxNode node)
......
......@@ -4,6 +4,7 @@ Imports System.Collections.Immutable
Imports System.Composition
Imports Microsoft.CodeAnalysis.Host.Mef
Imports Microsoft.CodeAnalysis.EmbeddedLanguages.VirtualChars
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Namespace Microsoft.CodeAnalysis.VisualBasic.EmbeddedLanguages.VirtualChars
<ExportLanguageService(GetType(IVirtualCharService), LanguageNames.VisualBasic), [Shared]>
......@@ -21,7 +22,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.EmbeddedLanguages.VirtualChars
If token.Kind() = SyntaxKind.StringLiteralToken Then
Return TryConvertSimpleDoubleQuoteString(token, """", """", escapeBraces:=False)
ElseIf token.Kind() = SyntaxKind.InterpolatedStringTextToken Then
End If
If token.Kind() = SyntaxKind.InterpolatedStringTextToken AndAlso
TypeOf token.Parent.Parent Is InterpolatedStringExpressionSyntax Then
Return TryConvertSimpleDoubleQuoteString(token, "", "", escapeBraces:=True)
End If
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册