Skip to content

A new hosting model which is easier for Editor Services and other script analyzer hosting #1361

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

Closed
wants to merge 62 commits into from

Conversation

JamesWTruher
Copy link
Contributor

PR Summary

This implements a new approach for hosting script analyzer for C# developers. It does not require the developer to manage the powershell engine or runspaces, and handles that internally. It does not need the developer to call the analyzer via pipeline.invoke. It provides a number of APIs which will make it easier for EditorServices to use ScriptAnalyzer.

PR Checklist

Had to make the initialization of the analyzer optional as it was clobbering the settings that had been created in the formatter
Hosting seems to work, starting to work on nuget packaging
Had to make the initialization of the analyzer optional as it was clobbering the settings that had been created in the formatter
Hosting seems to work, starting to work on nuget packaging
There really isn't a good way to do this as the underlying apis aren't really thread safe, but we can do _something_ to the hosted analyzer
If someone is using both the hosted analyzer and the module there may be some unexpected behaviors but doing something is probably better than doing nothing.
Disposing the helper seems to cause downstream problems.
Add async calls to the analyzer
Add a simple tostring method to the HostedAnalyzer
This will check to be sure that we can actually using the nupgk in a project
update the version to 1.18.4
@@ -0,0 +1,5 @@
{
"sdk": {
"version": "2.2.402"
Copy link
Collaborator

@bergmeister bergmeister Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.net core 2.2 has reached EOL in December already and PSSA has already moved on to 3.1.101 in the root directory. I think we can simply remove the file

@bergmeister bergmeister changed the title WIP: A new hosting model which is easier for Editor Services and other script analyzer hosting A new hosting model which is easier for Editor Services and other script analyzer hosting Jan 16, 2020
Helper.Instance = new Helper(runspace.SessionStateProxy.InvokeCommand, writer);
Helper.Instance.Initialize();

var ruleOrder = new string[]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note sure if .net optimises that anyway but we could use a constant for this


Range updatedRange;
bool fixesWereApplied;
text = ScriptAnalyzer.Instance.Fix(text, range, out updatedRange, out fixesWereApplied);
Copy link
Collaborator

@bergmeister bergmeister Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the above bool fixesWereApplied line can be inlined just by using out bool fixesWereApplied here. Same for the Range parameter

/// PSUseConsistentWhitespace
/// PSUseConsistentIndentation
/// PSAlignAssignmentStatement
/// PSUseCorrectCasing
Copy link
Collaborator

@bergmeister bergmeister Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the exact list of those rules could change, I'd take them out of the comment therefore. Same for other comments

/// <summary>
/// The encapsulated results of the analyzer
/// </summary>
public class AnalyzerResult
Copy link
Collaborator

@bergmeister bergmeister Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move each class/enum into its own file if it is public

public IEnumerable<string> ExcludeRules => excludeRules;
public IEnumerable<string> Severities => severities;
public IEnumerable<string> CustomRulePath => customRulePath;
public List<string> IncludeRules => includeRules;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this change is needed?

Copy link
Collaborator

@bergmeister bergmeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of code and quite complex but if it makes it better on the PSES side of things or performance wise, then go for it. Most comments are minor but would be nice to be be addressed.

{
// the rule does not exist, that's a problem, first create it and then add the key/value pair
Dictionary<string, object> settingDictionary;
if ( ! RuleArguments.TryGetValue(rule, out settingDictionary))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variable declaration can be inlined: out Dictionary<string, object> settingDictionary, also in a few lines below

<owners>Microsoft,PowerShellTeam</owners>
<projectUrl>https://github.com/PowerShell/PSScriptAnalyzer</projectUrl>
<iconUrl>https://raw.githubusercontent.com/powershell/psscriptanalyzer/master/logo.png</iconUrl>
<licenseUrl>https://github.com/PowerShell/PowerShell/blob/master/LICENSE.txt</licenseUrl>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<licenseUrl>https://github.com/PowerShell/PowerShell/blob/master/LICENSE.txt</licenseUrl>
<licenseUrl>https://github.com/PowerShell/PSScriptAnalyzer/blob/master/LICENSE</licenseUrl>

@bergmeister
Copy link
Collaborator

Close and re-open to re-trigger CI

@bergmeister bergmeister closed this Feb 5, 2020
@bergmeister bergmeister reopened this Feb 5, 2020
@JamesWTruher
Copy link
Contributor Author

I'm going to close this as it's not needed at the moment.

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

Successfully merging this pull request may close these issues.

2 participants