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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
a6f77d3
add sensible defaults code
JamesWTruher Mar 10, 2019
499a62a
Add hosted analyzer class
JamesWTruher Jun 25, 2019
1b7b9b1
more hosting updates
JamesWTruher Jun 27, 2019
9e5cd87
Formatter seems to be working
JamesWTruher Jul 8, 2019
8c0b30b
change calls to analyzer to be more like the cmdlet
JamesWTruher Jul 19, 2019
e5e31af
checkpoint
JamesWTruher Sep 5, 2019
2de9d8f
Since RunspacePools are disposable, implement IDisposable for HostedA…
JamesWTruher Sep 10, 2019
1034af8
add another supported library
JamesWTruher Sep 10, 2019
795b68c
Remove IDisposable in Helper as we no longer create a runspace pool
JamesWTruher Sep 12, 2019
a71ac90
make helper disposable to remove all vestiges of runspaces
JamesWTruher Sep 13, 2019
65aae15
add sensible defaults code
JamesWTruher Mar 10, 2019
567f530
Add hosted analyzer class
JamesWTruher Jun 25, 2019
8d7d2a6
more hosting updates
JamesWTruher Jun 27, 2019
73fec1b
Formatter seems to be working
JamesWTruher Jul 8, 2019
874628a
change calls to analyzer to be more like the cmdlet
JamesWTruher Jul 19, 2019
67dc945
checkpoint
JamesWTruher Sep 5, 2019
dd5b919
Since RunspacePools are disposable, implement IDisposable for HostedA…
JamesWTruher Sep 10, 2019
01f7957
add another supported library
JamesWTruher Sep 10, 2019
ed3436b
Remove IDisposable in Helper as we no longer create a runspace pool
JamesWTruher Sep 12, 2019
db5c2f7
make helper disposable to remove all vestiges of runspaces
JamesWTruher Sep 13, 2019
1b85759
Merge branch 'hosting' of https://github.com/JamesWTruher/PSScriptAna…
JamesWTruher Sep 16, 2019
a3d58a8
Add locking to hosted analyzer methods which change analyzer state
JamesWTruher Sep 23, 2019
b38e35d
Add simple locking to hosted analyzer apis
JamesWTruher Oct 7, 2019
b2e76ee
Change hostedanalyzer fields to properties
JamesWTruher Oct 8, 2019
ba88ff8
Remove dispose of Helper.Instance.
JamesWTruher Oct 15, 2019
7610d49
Add an overload for Fix which takes a settings object
JamesWTruher Oct 21, 2019
e43d72b
Adding tests for HostedAnalyzer
JamesWTruher Oct 21, 2019
c969ead
fix ToString
JamesWTruher Oct 21, 2019
c081444
Add C# tests for the hosted analyzer
JamesWTruher Oct 28, 2019
0dcb55d
Fix up reference assembly build and when it should be built
JamesWTruher Oct 29, 2019
fe6f907
Merge branch 'master' into hosting
JamesWTruher Oct 29, 2019
8ecc70c
remove reference from build for the moment
JamesWTruher Oct 29, 2019
6422360
bug fix - change initializer for a couple of Settings properties
JamesWTruher Oct 30, 2019
893b553
Start removing dead code
JamesWTruher Nov 1, 2019
15d21ef
More code cleanup
JamesWTruher Nov 5, 2019
d76f87c
Code Cleanup
JamesWTruher Nov 11, 2019
7c1e74a
Merge remote-tracking branch 'upstream/master' into hosting
JamesWTruher Nov 11, 2019
aad6ed0
Merge branch 'master' into hosting
JamesWTruher Nov 12, 2019
89ba69f
incorporate feedback from https://github.com/PowerShell/PowerShellEdi…
JamesWTruher Nov 12, 2019
8e27c8b
Fix typo in WriteError to add to correct collection
JamesWTruher Nov 13, 2019
a88bc3b
Remove Get-Runspace from tests, it wasn't being used
JamesWTruher Nov 13, 2019
182d128
Create helper function so we can test hosted analyzer on PS4
JamesWTruher Nov 13, 2019
7b40004
update json library version
JamesWTruher Nov 13, 2019
b1a93c8
Merge remote-tracking branch 'upstream/master' into hosting
JamesWTruher Nov 14, 2019
0fa1e64
Fix typo in hosted analyzer tests
JamesWTruher Nov 14, 2019
99e9387
remove some of the nupkg creation code which we're not doing
JamesWTruher Nov 14, 2019
f0868fb
Add the new APIs to the reference assembly
JamesWTruher Nov 14, 2019
3e9d242
Update version to 1.18.4 for signing files in hosting release
JamesWTruher Nov 18, 2019
24533f3
Add reference build to build All
JamesWTruher Nov 21, 2019
bbb5d75
global.json needed in directory for build
JamesWTruher Nov 21, 2019
00a73e3
Add .nupkg to be signed
JamesWTruher Nov 21, 2019
c744561
Add support for format with settings and range
JamesWTruher Nov 29, 2019
909f62a
Add a couple of new apis that are needed by Editor Services
JamesWTruher Dec 6, 2019
3f1debe
Update reference library to include changes in previous hosted analyzer
JamesWTruher Dec 6, 2019
798f8b2
Make Fix and Format similar from a signature basis
JamesWTruher Dec 12, 2019
1e8c7d8
Merge branch 'master' into hosting
JamesWTruher Dec 12, 2019
88f379c
match sdk version with base project
JamesWTruher Dec 12, 2019
28501a6
Merge branch 'master' into hosting
bergmeister Jan 16, 2020
4e6c2ae
Add documentation for hosted analyzer
JamesWTruher Jan 28, 2020
f65bb3e
Merge branch 'hosting' of https://github.com/JamesWTruher/PSScriptAna…
JamesWTruher Jan 28, 2020
43af91c
Merge branch 'master' into hosting
JamesWTruher Jan 28, 2020
2afcc2a
Merge branch 'master' into hosting
JamesWTruher Feb 5, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Engine/Commands/GetScriptAnalyzerRuleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public string[] Name
/// <summary>
/// Severity: Array of the severity types to be enabled.
/// </summary>
/// </summary>
[ValidateSet("Warning", "Error", "Information", IgnoreCase = true)]
[Parameter(Mandatory = false)]
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
Expand Down
3 changes: 2 additions & 1 deletion Engine/Engine.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>1.18.3</VersionPrefix>
<VersionPrefix>1.18.4</VersionPrefix>
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
<AssemblyName>Microsoft.Windows.PowerShell.ScriptAnalyzer</AssemblyName>
<PackageId>Engine</PackageId>
<RootNamespace>Microsoft.Windows.PowerShell.ScriptAnalyzer</RootNamespace> <!-- Namespace needs to match Assembly name for ressource binding -->
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
Expand Down
53 changes: 53 additions & 0 deletions Engine/Formatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,59 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer
/// </summary>
public class Formatter
{
/// <summary>
/// Format a powershell script.
/// </summary>
/// <param name="scriptDefinition">A string representing a powershell script.</param>
/// <param name="settings">Settings to be used for formatting</param>
/// <param name="range">The range in which formatting should take place.</param>
/// <param name="runspace">The runspace entrance into the powershell engine.</param>
/// <param name="writer">The writer for operation message.</param>
/// <returns></returns>
public static string Format(
string scriptDefinition,
Settings settings,
Range range,
System.Management.Automation.Runspaces.Runspace runspace,
IOutputWriter writer)
{
// todo implement notnull attribute for such a check
ValidateNotNull(scriptDefinition, "scriptDefinition");
ValidateNotNull(settings, "settings");

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

{
"PSPlaceCloseBrace",
"PSPlaceOpenBrace",
"PSUseConsistentWhitespace",
"PSUseConsistentIndentation",
"PSAlignAssignmentStatement",
"PSUseCorrectCasing"
};

var text = new EditableText(scriptDefinition);
foreach (var rule in ruleOrder)
{
if (!settings.RuleArguments.ContainsKey(rule))
{
continue;
}

var currentSettings = GetCurrentSettings(settings, rule);
ScriptAnalyzer.Instance.UpdateSettings(currentSettings);
ScriptAnalyzer.Instance.Initialize(runspace, writer, null, null, null, null, true, false, null, false);

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

range = updatedRange;
}

return text.ToString();
}
/// <summary>
/// Format a powershell script.
/// </summary>
Expand Down
24 changes: 23 additions & 1 deletion Engine/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer
/// <summary>
/// This Helper class contains utility/helper functions for classes in ScriptAnalyzer.
/// </summary>
public class Helper
public class Helper : IDisposable
{
#region Private members

Expand Down Expand Up @@ -67,6 +67,28 @@ internal set

#endregion

private bool disposed = false;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if ( disposed )
{
return;
}

if ( disposing )
{
CommandInfoCache.Dispose();
}

disposed = true;
}

#region Properties

/// <summary>
Expand Down
Loading