-
Notifications
You must be signed in to change notification settings - Fork 237
Remove extra newline in GetComment feature #1080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Management.Automation.Language; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
@@ -80,21 +79,27 @@ public async Task<CommentHelpRequestResult> Handle(CommentHelpRequestParams requ | |
vscodeSnippetCorrection: true, | ||
placement: helpLocation)); | ||
|
||
string helpText = analysisResults?.FirstOrDefault()?.Correction?.Edits[0].Text; | ||
string helpText = analysisResults?[0]?.Correction?.Edits[0].Text; | ||
|
||
if (helpText == null) | ||
{ | ||
return result; | ||
} | ||
|
||
result.Content = ScriptFile.GetLinesInternal(helpText).ToArray(); | ||
List<string> helpLines = ScriptFile.GetLinesInternal(helpText); | ||
|
||
if (helpLocation != null && | ||
!helpLocation.Equals("before", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
// we need to trim the leading `{` and newline when helpLocation=="begin" | ||
// we also need to trim the leading newline when helpLocation=="end" | ||
result.Content = result.Content.Skip(1).ToArray(); | ||
helpLines = helpLines.GetRange(1, helpLines.Count - 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It might be better to use helpLines.RemoveAt(0);
helpLines.RemoveAt(helpLines.Count - 1); |
||
} | ||
|
||
// Trim trailing newline from help text. | ||
if (string.IsNullOrEmpty(helpLines[helpLines.Count - 1])) | ||
{ | ||
result.Content = helpLines.GetRange(0, helpLines.Count - 1).ToArray(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be where If there's no empty line at the end, it seems we don't assign So maybe instead the way to go is: if (string.IsNullOrEmpty(helpLines[helpLines.Count - 1]))
{
helpLines.RemoveAt(helpLines.Count - 1);
}
result.Content = helpLines.ToArray();
return result; |
||
} | ||
|
||
return result; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is technically less safe; if there are no results we'll crash. But if we know we're going to get a correction that's ok (looks like we make the assumption that the result we get will have an edit, but that is conditioned on
Correction
being non-null).Don't know enough about the context above to know whether the assumption is safe.
But the alternative is cheap I suppose: