Skip to content

Commit 6340108

Browse files
TylerLeonhardtrjmholt
authored andcommitted
Remove extra newline in GetComment feature (#1080)
1 parent 2a7e8b6 commit 6340108

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/PowerShellEditorServices/Services/PowerShellContext/Handlers/GetCommentHelpHandler.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
using System;
77
using System.Collections.Generic;
8-
using System.Linq;
98
using System.Management.Automation.Language;
109
using System.Threading;
1110
using 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
}

0 commit comments

Comments
 (0)