Skip to content

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

Merged
merged 5 commits into from
Nov 15, 2018

Conversation

rkeithhill
Copy link
Contributor

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 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.
rkeithhill added a commit to PowerShell/vscode-powershell that referenced this pull request Nov 4, 2018
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.
Copy link
Contributor

@rjmholt rjmholt left a 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(
Copy link
Contributor

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,
Copy link
Contributor

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
Copy link
Member

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 😄 )

Copy link
Member

@TylerLeonhardt TylerLeonhardt left a 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.
@rkeithhill
Copy link
Contributor Author

Addressed all the current PR change requests.

@rjmholt
Copy link
Contributor

rjmholt commented Nov 13, 2018

Pinging @TylerLeonhardt for approval

@rjmholt
Copy link
Contributor

rjmholt commented Nov 13, 2018

@TylerLeonhardt, nice username btw 😉

Copy link
Collaborator

@SeeminglyScience SeeminglyScience left a 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);
Copy link
Collaborator

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();

Copy link
Member

@TylerLeonhardt TylerLeonhardt Nov 13, 2018

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Member

@TylerLeonhardt TylerLeonhardt left a 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 😄

@rkeithhill rkeithhill merged commit 19d5c5b into master Nov 15, 2018
@rkeithhill rkeithhill deleted the rkeithhill/support-quick-fix-show-doc branch November 15, 2018 01:24
rkeithhill added a commit to PowerShell/vscode-powershell that referenced this pull request Nov 15, 2018
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants