Skip to content
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

What the hosted PSSA could look like #1078

Draft
wants to merge 7 commits into
base: master
from

Conversation

@TylerLeonhardt
Copy link
Member

@TylerLeonhardt TylerLeonhardt commented Oct 31, 2019

This is DRAFT. CI will fail because there's no nuget package on nuget.org!

This is the bare minimum work that I would do to adopt the hosted analyzer. It already cuts the code in AnalysisService.cs by half!

I recommend just looking at my version of the AnalysisService.cs and looking around for HostedAnalyzer, Analyze(, Format( - so you can see how the hosted analyzer is used there.

Some additional work that could be done:

  • Replace all instances of Hashtable (when pertaining to PSSA) with the proper Settings type
  • Remove the ScriptFileMarker type which seems to be some intermediate type between a DiagnosticRecord from PSSA and the outgoing (aka language server protocol) type of Diagnostic. I tried it, it's totally possible to switch over to using Diagnostic everywhere ScriptFileMarker is used. That would remove another type and a good chunk of code.
  • Now that ScriptFileMarker is gone, we can continue to remove random types like MarkerCorrection could be removed but this involves understanding CodeAction request more

cc @JamesWTruher
Some notes that I took on the Hosted Analyzer:

  • Analyze() - Invoke-ScriptAnalyzer has a -Severity param. Can we have a severity param?
  • Fix() - Invoke-Formatter Has a -Range parameter that we use. Can we have a range parameter?
  • Settings.*RuleArgument() - should return Settings objects so we can chain them like the builder pattern
  • Format() - Invoke-Formatter Has a -Range parameter that we use. Can we have a range parameter?
  • Can it be possible to create a Settings object from a list of strings (which are the rules we care about)?
  • Fix() & Format() - should those also have the ability to pass the AST in addition to the script? No they should not.
  • Cancellation support... this might be too much work... but it'd be nice. I've kinda worked around it in this PR by "cancelling" anything else after we get a response back from Analyze() deferred.
@TylerLeonhardt TylerLeonhardt force-pushed the TylerLeonhardt:initial-hosted-pssa branch from e5aac44 to a038c32 Nov 27, 2019
@PowerShell PowerShell deleted a comment Nov 27, 2019
@rjmholt rjmholt self-requested a review Nov 27, 2019
@TylerLeonhardt
Copy link
Member Author

@TylerLeonhardt TylerLeonhardt commented Dec 9, 2019

Codacy Here is an overview of what got changed by this pull request:

Issues
======
+ Solved 18
- Added 1
           

Complexity increasing per file
==============================
- src/PowerShellEditorServices/Services/Analysis/AnalysisService.cs  5
- src/PowerShellEditorServices/Services/Analysis/MarkerCorrection.cs  1
- src/PowerShellEditorServices/Services/Analysis/DiagnosticCreationHelper.cs  4
         

Complexity decreasing per file
==============================
+ src/PowerShellEditorServices/Services/TextDocument/Handlers/FormattingHandlers.cs  -1
+ src/PowerShellEditorServices/Services/PowerShellContext/Handlers/GetCommentHelpHandler.cs  -4
         

See the complete overview on Codacy

}
// If cancellation didn't throw an exception,
// clean up the existing token
_existingRequestCancellation.Dispose();
_analyzerSettings = _analyzer.CreateSettings(s_includedRules);
_analyzerSettings.Severities.AddRange(new [] {
RuleSeverity.Error.ToString(),
RuleSeverity.Information.ToString(),

This comment has been minimized.

@rjmholt

rjmholt Dec 10, 2019
Member

Should this be RuleSeverity.Warning? Why is it that these are strings if we've gone to the effort to load the types?

scriptFile.DiagnosticMarkers);
}
}
if (!ct.CanBeCanceled || ct.IsCancellationRequested)

This comment has been minimized.

@rjmholt

rjmholt Dec 10, 2019
Member

Why do we break if we can't cancel the token?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.