File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed
src/PowerShellEditorServices/Services/PowerShellContext/Handlers Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change 55
66using System ;
77using System . Collections . Generic ;
8- using System . Linq ;
98using System . Management . Automation . Language ;
109using System . Threading ;
1110using System . Threading . Tasks ;
@@ -80,23 +79,37 @@ public async Task<CommentHelpRequestResult> Handle(CommentHelpRequestParams requ
8079 vscodeSnippetCorrection : true ,
8180 placement : helpLocation ) ) ;
8281
83- string helpText = analysisResults ? . FirstOrDefault ( ) ? . Correction ? . Edits [ 0 ] . Text ;
82+ if ( analysisResults == null || analysisResults . Count == 0 )
83+ {
84+ return result ;
85+ }
86+
87+ string helpText = analysisResults [ 0 ] ? . Correction ? . Edits [ 0 ] . Text ;
8488
8589 if ( helpText == null )
8690 {
8791 return result ;
8892 }
8993
90- result . Content = ScriptFile . GetLinesInternal ( helpText ) . ToArray ( ) ;
94+ List < string > helpLines = ScriptFile . GetLinesInternal ( helpText ) ;
9195
9296 if ( helpLocation != null &&
9397 ! helpLocation . Equals ( "before" , StringComparison . OrdinalIgnoreCase ) )
9498 {
9599 // we need to trim the leading `{` and newline when helpLocation=="begin"
100+ helpLines . RemoveAt ( helpLines . Count - 1 ) ;
101+
96102 // we also need to trim the leading newline when helpLocation=="end"
97- result . Content = result . Content . Skip ( 1 ) . ToArray ( ) ;
103+ helpLines . RemoveAt ( 0 ) ;
104+ }
105+
106+ // Trim trailing newline from help text.
107+ if ( string . IsNullOrEmpty ( helpLines [ helpLines . Count - 1 ] ) )
108+ {
109+ helpLines . RemoveAt ( helpLines . Count - 1 ) ;
98110 }
99111
112+ result . Content = helpLines . ToArray ( ) ;
100113 return result ;
101114 }
102115 }
You can’t perform that action at this time.
0 commit comments