33// See the LICENSE file in the project root for more information.
44
55using System ;
6+ using System . CodeDom . Compiler ;
67using System . Collections . Generic ;
78using System . Collections . Immutable ;
89using System . Text ;
@@ -97,9 +98,12 @@ public async Task GenerateDocumentationProposalAsync(DocumentationCommentSnippet
9798 var summaryEndTag = comments . IndexOf ( "</summary>" , index , StringComparison . Ordinal ) ;
9899 if ( summaryEndTag != - 1 && summaryStartTag != - 1 )
99100 {
100- proposedEdits . Add ( new DocumentationCommentProposedEdit ( new TextSpan ( caret + startIndex , 0 ) , null , DocumentationCommentTagType . Summary ) ) ;
101+ proposedEdits . Add ( new DocumentationCommentProposedEdit ( new TextSpan ( caret + startIndex , 0 ) , symbolName : null , DocumentationCommentTagType . Summary ) ) ;
101102 }
102103
104+ // We may receive remarks from the model. In that case, we want to insert the remark tags and remark directly after the summary.
105+ proposedEdits . Add ( new DocumentationCommentProposedEdit ( new TextSpan ( summaryEndTag + "</summary>" . Length + startIndex , 0 ) , symbolName : null , DocumentationCommentTagType . Remarks ) ) ;
106+
103107 while ( true )
104108 {
105109 var typeParamEndTag = comments . IndexOf ( "</typeparam>" , index , StringComparison . Ordinal ) ;
@@ -145,7 +149,7 @@ public async Task GenerateDocumentationProposalAsync(DocumentationCommentSnippet
145149 var returnsEndTag = comments . IndexOf ( "</returns>" , index , StringComparison . Ordinal ) ;
146150 if ( returnsEndTag != - 1 )
147151 {
148- proposedEdits . Add ( new DocumentationCommentProposedEdit ( new TextSpan ( returnsEndTag + startIndex , 0 ) , null , DocumentationCommentTagType . Returns ) ) ;
152+ proposedEdits . Add ( new DocumentationCommentProposedEdit ( new TextSpan ( returnsEndTag + startIndex , 0 ) , symbolName : null , DocumentationCommentTagType . Returns ) ) ;
149153 }
150154
151155 while ( true )
@@ -218,7 +222,7 @@ private static async Task<IReadOnlyList<ProposedEdit>> GetProposedEditsAsync(
218222 }
219223
220224 var proposedEdit = new ProposedEdit ( new SnapshotSpan ( oldSnapshot , textSpan . Start , textSpan . Length ) ,
221- AddNewLinesToCopilotText ( copilotStatement , indentText , characterLimit : 120 ) ) ;
225+ AddNewLinesToCopilotText ( copilotStatement , indentText , edit . TagType , characterLimit : 120 ) ) ;
222226 list . Add ( proposedEdit ) ;
223227 }
224228
@@ -230,6 +234,10 @@ private static async Task<IReadOnlyList<ProposedEdit>> GetProposedEditsAsync(
230234 {
231235 return summary ;
232236 }
237+ else if ( edit . TagType == DocumentationCommentTagType . Remarks && documentationCommentDictionary . TryGetValue ( DocumentationCommentTagType . Remarks . ToString ( ) , out var remarks ) && ! string . IsNullOrEmpty ( remarks ) )
238+ {
239+ return remarks ;
240+ }
233241 else if ( edit . TagType == DocumentationCommentTagType . TypeParam && documentationCommentDictionary . TryGetValue ( symbolKey ! , out var typeParam ) && ! string . IsNullOrEmpty ( typeParam ) )
234242 {
235243 return typeParam ;
@@ -250,11 +258,13 @@ private static async Task<IReadOnlyList<ProposedEdit>> GetProposedEditsAsync(
250258 return null ;
251259 }
252260
253- static string AddNewLinesToCopilotText ( string copilotText , string ? indentText , int characterLimit )
261+ static string AddNewLinesToCopilotText ( string copilotText , string ? indentText , DocumentationCommentTagType tagType , int characterLimit )
254262 {
255263 // Double check that the resultant from Copilot does not produce any strings containing new line characters.
256264 copilotText = Regex . Replace ( copilotText , @"\r?\n" , " " ) ;
257265 var builder = new StringBuilder ( ) ;
266+ copilotText = BuildCopilotTextForRemarks ( copilotText , indentText , tagType , builder ) ;
267+
258268 var words = copilotText . Split ( ' ' ) ;
259269 var currentLineLength = 0 ;
260270 characterLimit -= ( indentText ! . Length + "/// " . Length ) ;
@@ -279,6 +289,22 @@ static string AddNewLinesToCopilotText(string copilotText, string? indentText, i
279289 }
280290
281291 return builder . ToString ( ) ;
292+
293+ static string BuildCopilotTextForRemarks ( string copilotText , string ? indentText , DocumentationCommentTagType tagType , StringBuilder builder )
294+ {
295+ if ( tagType is DocumentationCommentTagType . Remarks )
296+ {
297+ builder . AppendLine ( ) ;
298+ builder . Append ( indentText ) ;
299+ builder . Append ( "/// <remarks>" ) ;
300+ builder . Append ( copilotText ) ;
301+ builder . Append ( "</remarks>" ) ;
302+ copilotText = builder . ToString ( ) ;
303+ builder . Clear ( ) ;
304+ }
305+
306+ return copilotText ;
307+ }
282308 }
283309 }
284310
0 commit comments