@@ -117,17 +117,19 @@ internal static ImmutableArray<string> GenerateStandardText(Document document, B
117117 }
118118 }
119119
120+ internal static SyntaxList < XmlNodeSyntax > BuildStandardTextSyntaxList ( BaseTypeDeclarationSyntax typeDeclaration , string preText , string postText )
121+ {
122+ TypeParameterListSyntax typeParameterList = GetTypeParameterList ( typeDeclaration ) ;
123+
124+ return XmlSyntaxFactory . List (
125+ XmlSyntaxFactory . Text ( preText ) ,
126+ BuildSeeElement ( typeDeclaration . Identifier , typeParameterList ) ,
127+ XmlSyntaxFactory . Text ( postText . EndsWith ( "." ) ? postText : ( postText + "." ) ) ) ;
128+ }
129+
120130 internal static SyntaxList < XmlNodeSyntax > BuildStandardTextSyntaxList ( BaseTypeDeclarationSyntax typeDeclaration , string newLineText , string preText , string postText )
121131 {
122- TypeParameterListSyntax typeParameterList ;
123- if ( typeDeclaration is ClassDeclarationSyntax classDeclaration )
124- {
125- typeParameterList = classDeclaration . TypeParameterList ;
126- }
127- else
128- {
129- typeParameterList = ( typeDeclaration as StructDeclarationSyntax ) ? . TypeParameterList ;
130- }
132+ TypeParameterListSyntax typeParameterList = GetTypeParameterList ( typeDeclaration ) ;
131133
132134 return XmlSyntaxFactory . List (
133135 XmlSyntaxFactory . NewLine ( newLineText ) ,
@@ -136,15 +138,23 @@ internal static SyntaxList<XmlNodeSyntax> BuildStandardTextSyntaxList(BaseTypeDe
136138 XmlSyntaxFactory . Text ( postText . EndsWith ( "." ) ? postText : ( postText + "." ) ) ) ;
137139 }
138140
141+ private static TypeParameterListSyntax GetTypeParameterList ( BaseTypeDeclarationSyntax typeDeclaration )
142+ {
143+ if ( typeDeclaration is ClassDeclarationSyntax classDeclaration )
144+ {
145+ return classDeclaration . TypeParameterList ;
146+ }
147+
148+ return ( typeDeclaration as StructDeclarationSyntax ) ? . TypeParameterList ;
149+ }
150+
139151 private static Task < Document > GetTransformedDocumentAsync ( Document document , SyntaxNode root , XmlElementSyntax node , CancellationToken cancellationToken )
140152 {
141153 var typeDeclaration = node . FirstAncestorOrSelf < BaseTypeDeclarationSyntax > ( ) ;
142154 var declarationSyntax = node . FirstAncestorOrSelf < BaseMethodDeclarationSyntax > ( ) ;
143155
144156 var standardText = GenerateStandardText ( document , declarationSyntax , typeDeclaration , cancellationToken ) ;
145157
146- string newLineText = document . Project . Solution . Workspace . Options . GetOption ( FormattingOptions . NewLine , LanguageNames . CSharp ) ;
147-
148158 string trailingString = string . Empty ;
149159
150160 var newContent = RemoveMalformattedStandardText ( node . Content , standardText [ 0 ] , standardText [ 1 ] , ref trailingString ) ;
@@ -157,7 +167,17 @@ private static Task<Document> GetTransformedDocumentAsync(Document document, Syn
157167 }
158168 }
159169
160- var list = BuildStandardTextSyntaxList ( typeDeclaration , newLineText , standardText [ 0 ] , standardText [ 1 ] + trailingString ) ;
170+ SyntaxList < XmlNodeSyntax > list ;
171+ if ( IsMultiLine ( node ) )
172+ {
173+ string newLineText = document . Project . Solution . Workspace . Options . GetOption ( FormattingOptions . NewLine , LanguageNames . CSharp ) ;
174+ list = BuildStandardTextSyntaxList ( typeDeclaration , newLineText , standardText [ 0 ] , standardText [ 1 ] + trailingString ) ;
175+ }
176+ else
177+ {
178+ list = BuildStandardTextSyntaxList ( typeDeclaration , standardText [ 0 ] , standardText [ 1 ] + trailingString ) ;
179+ }
180+
161181 newContent = newContent . InsertRange ( 0 , list ) ;
162182
163183 newContent = RemoveTrailingEmptyLines ( newContent ) ;
@@ -171,6 +191,12 @@ private static Task<Document> GetTransformedDocumentAsync(Document document, Syn
171191 return Task . FromResult ( newDocument ) ;
172192 }
173193
194+ private static bool IsMultiLine ( XmlElementSyntax node )
195+ {
196+ var lineSpan = node . GetLineSpan ( ) ;
197+ return lineSpan . StartLinePosition . Line != lineSpan . EndLinePosition . Line ;
198+ }
199+
174200 private static Task < Document > GetTransformedDocumentAsync ( Document document , SyntaxNode root , XmlEmptyElementSyntax node )
175201 {
176202 var typeDeclaration = node . FirstAncestorOrSelf < BaseTypeDeclarationSyntax > ( ) ;
0 commit comments