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 5
5
6
6
using System ;
7
7
using System . Collections . Generic ;
8
- using System . Linq ;
9
8
using System . Management . Automation . Language ;
10
9
using System . Threading ;
11
10
using System . Threading . Tasks ;
@@ -80,23 +79,37 @@ public async Task<CommentHelpRequestResult> Handle(CommentHelpRequestParams requ
80
79
vscodeSnippetCorrection : true ,
81
80
placement : helpLocation ) ) ;
82
81
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 ;
84
88
85
89
if ( helpText == null )
86
90
{
87
91
return result ;
88
92
}
89
93
90
- result . Content = ScriptFile . GetLinesInternal ( helpText ) . ToArray ( ) ;
94
+ List < string > helpLines = ScriptFile . GetLinesInternal ( helpText ) ;
91
95
92
96
if ( helpLocation != null &&
93
97
! helpLocation . Equals ( "before" , StringComparison . OrdinalIgnoreCase ) )
94
98
{
95
99
// we need to trim the leading `{` and newline when helpLocation=="begin"
100
+ helpLines . RemoveAt ( helpLines . Count - 1 ) ;
101
+
96
102
// 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 ) ;
98
110
}
99
111
112
+ result . Content = helpLines . ToArray ( ) ;
100
113
return result ;
101
114
}
102
115
}
You can’t perform that action at this time.
0 commit comments