dotnet/roslyn

InterpolatedStringExpression inserts a space on its own.

オープン

#39,923 opened on 2019/11/21

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)C# (4,257 件のフォーク)batch import
Area-AnalyzersBughelp wanted

Repository metrics

Stars
 (20,414 個のスター)
PR merge metrics
 (平均マージ 6d 17h) (30d で 256 merged PRs)

説明

Version Used: 3.3.1 Steps to Reproduce:

Dim Workspace As New AdhocWorkspace()

Dim generator As SyntaxGenerator = SyntaxGenerator.GetGenerator(Workspace, LanguageNames.VisualBasic)

Dim InterpolationBroken As SyntaxNode = VisualBasic.SyntaxFactory.InterpolatedStringExpression(New SyntaxList(Of VisualBasic.Syntax.InterpolatedStringContentSyntax)({
                                                                                                                                                                             VisualBasic.SyntaxFactory.Interpolation(generator.IdentifierName("uApp.AccentColor.ToString")),
                                                                                                                                                                             VisualBasic.SyntaxFactory.Interpolation(VisualBasic.SyntaxFactory.ParseExpression("If(uApp.ThemeIsDark,""Dark"","""")"))}))

Dim InterpolationWorking As SyntaxNode = VisualBasic.SyntaxFactory.InterpolatedStringExpression(New SyntaxList(Of VisualBasic.Syntax.InterpolatedStringContentSyntax)({
                                                                                                                                                                              VisualBasic.SyntaxFactory.Interpolation(generator.IdentifierName("uApp.AccentColor.ToString")),
                                                                                                                                                                              VisualBasic.SyntaxFactory.InterpolatedStringText(VisualBasic.SyntaxFactory.InterpolatedStringTextToken("", "")),
                                                                                                                                                                              VisualBasic.SyntaxFactory.Interpolation(VisualBasic.SyntaxFactory.ParseExpression("If(uApp.ThemeIsDark,""Dark"","""")"))}))

Dim txtoutputBroken = generator.CompilationUnit(generator.ExpressionStatement(InterpolationBroken)).NormalizeWhitespace

Dim txtoutputWorking = generator.CompilationUnit(generator.ExpressionStatement(InterpolationWorking)).NormalizeWhitespace

Expected Behavior: Output Stirng should be $"{uApp.AccentColor.ToString}{If(uApp.ThemeIsDark, "Dark", "")}" No added space between the Interpolations

Actual Behavior: Current output string is $"{uApp.AccentColor.ToString} {If(uApp.ThemeIsDark, "Dark", "")}" With a space between the Interpolations

I had to manually add a InterpolatedStringText with a empty string to make the space between the two Interpolations not appear. I don't understand why it is adding the space by default, messing up the formatting of the output string.

コントリビューターガイド