Skip to content

Commit

Permalink
Merge pull request #30379 from CyrusNajmabadi/virtualCharFormatSpecifier
Browse files Browse the repository at this point in the history
Do not try to convert interpolated string format specifiers into virtual chars
  • Loading branch information
dpoeschl committed Oct 9, 2018
2 parents 4bb1ffe + eff472b commit 83d1890
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
Expand Up @@ -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(@"}}"));
}
}
}
Expand Up @@ -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
Expand Up @@ -48,17 +48,21 @@ protected override ImmutableArray<VirtualChar> TryConvertToVirtualCharsWorker(Sy
? TryConvertVerbatimStringToVirtualChars(token, "@\"", "\"", escapeBraces: false)
: TryConvertStringToVirtualChars(token, "\"", "\"", escapeBraces: false);
}
else if (token.Kind() == SyntaxKind.InterpolatedStringTextToken)
{
var interpolatedString = (InterpolatedStringExpressionSyntax)token.Parent.Parent;
return interpolatedString.StringStartToken.Kind() == SyntaxKind.InterpolatedVerbatimStringStartToken
? TryConvertVerbatimStringToVirtualChars(token, "", "", escapeBraces: true)
: TryConvertStringToVirtualChars(token, "", "", escapeBraces: true);
}
else

if (token.Kind() == SyntaxKind.InterpolatedStringTextToken)
{
return default;
// 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)
{
return interpolatedString.StringStartToken.Kind() == SyntaxKind.InterpolatedVerbatimStringStartToken
? TryConvertVerbatimStringToVirtualChars(token, "", "", escapeBraces: true)
: TryConvertStringToVirtualChars(token, "", "", escapeBraces: true);
}
}

return default;
}

private bool IsInDirective(SyntaxNode node)
Expand Down
Expand Up @@ -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]>
Expand All @@ -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

Expand Down

0 comments on commit 83d1890

Please sign in to comment.