-
Notifications
You must be signed in to change notification settings - Fork 234
Add support for a "Show Documentation" quick fix menu entry #789
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
Conversation
This requires a corresponding PR to VSCode to handle the new command: PowerShell.ShowCodeActionDocumentation Changed the use of the Diagnostic.Code field to hold the PSSA rule name. According to the LSP docs, this field is meant to be displayed and tslint uses it to display the vioated rule. Update the logic to use a combination of diagnostic fields to get a unique id in order to retrieve the stored "correction edits" when the textDocument/codeAction message is processed with the diagnostic array returned earlier. Also, observed a few times during startup that RunScriptDiagnostics was getting called with an empty filesToAnalyze array. Modified to return early in that case. Remove a private overload of DelayThenInvokeDiagnostics that wasn't being used.
This corresponds to PSES PR: PowerShell/PowerShellEditorServices#789 Currently this points to the PSSA development branch. Maybe that should point to the master branch. Could be a setting I suppose but that seems like overkill.
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.
LGTM! Thanks @rkeithhill. Left a minor comment, but I'm good to go as is :)
markerIndex.TryGetValue(diagnostic.Code, out correction)) | ||
if (string.IsNullOrEmpty(diagnostic.Code)) | ||
{ | ||
this.Logger.Write( |
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.
👍
private static Diagnostic GetDiagnosticFromMarker(ScriptFileMarker scriptFileMarker) | ||
{ | ||
return new Diagnostic | ||
{ | ||
Severity = MapDiagnosticSeverity(scriptFileMarker.Level), | ||
Message = scriptFileMarker.Message, | ||
Code = scriptFileMarker.Source + Guid.NewGuid().ToString(), | ||
Code = scriptFileMarker.RuleName, |
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 so much nicer!
@@ -1182,6 +1183,7 @@ private bool IsQueryMatch(string query, string symbolName) | |||
return symbolName.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0; | |||
} | |||
|
|||
// https://microsoft.github.io/language-server-protocol/specification#textDocument_codeAction |
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.
omg we should have comments like this all over... so great! (not in this PR 😄 )
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.
Looking good! Great to see your contributions, Keith 👍
Also update codeAction processing to ensure we don't have multiple show documentation commands for the same rule.
Addressed all the current PR change requests. |
Pinging @TylerLeonhardt for approval |
@TylerLeonhardt, nice username btw 😉 |
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.
LGTM! Just one nit
sb.Append("-"); | ||
sb.Append(end.Line); | ||
sb.Append(":"); | ||
sb.Append(end.Character); |
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.
Consider chaining these, e.g.
return new StringBuilder(256)
.Append(diagnostic.Source ?? "?")
.Append("_")
.Append(diagnostic.Code ?? "?")
.Append("_")
.Append((diagnostic.Severity != null) ? diagnostic.Severity.ToString() : "?")
.Append("_")
.Append(start.Line)
.Append(":")
.Append(start.Character)
.Append("-")
.Append(end.Line)
.Append(":")
.Append(end.Character)
.ToString();
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.
small nit... it might be useful to do:
StringBuilder sb = new StringBuilder(256)
.Append(diagnostic.Source ?? "?")
.Append("_")
.Append(diagnostic.Code ?? "?")
.Append("_")
.Append((diagnostic.Severity != null) ? diagnostic.Severity.ToString() : "?")
.Append("_")
.Append(start.Line)
.Append(":")
.Append(start.Character)
.Append("-")
.Append(end.Line)
.Append(":")
.Append(end.Character)
return sb.ToString();
so that we can throw a breakpoint on the return line and see what the contents of sb are. But I won't block on doing that vs what Patrick suggested
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.
Heh, I was just going to suggest this very thing. :-) Will fix.
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.
Honestly my biggest desire is for a function-return-variable in debug view.
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.
LGTM! Excited to see this 😄
This corresponds to PSES PR: PowerShell/PowerShellEditorServices#789 Currently this points to the PSSA development branch. Maybe that should point to the master branch. Could be a setting I suppose but that seems like overkill.
This requires a corresponding PR to VSCode to handle the new command:
PowerShell.ShowCodeActionDocumentation
Changed the use of the Diagnostic.Code field to hold the PSSA rule name.
According to the LSP docs, this field is meant to be displayed and
tslint uses it to display the vioated rule. Update the logic to use a
combination of diagnostic fields to get a unique id in order to
retrieve the stored "correction edits" when the
textDocument/codeAction message is processed with the diagnostic
array returned earlier.
Also, observed a few times during startup that RunScriptDiagnostics was
getting called with an empty filesToAnalyze array. Modified to return
early in that case.
Remove a private overload of DelayThenInvokeDiagnostics that wasn't
being used.