-
Notifications
You must be signed in to change notification settings - Fork 395
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
Closed
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 499a62a
Add hosted analyzer class
JamesWTruher 1b7b9b1
more hosting updates
JamesWTruher 9e5cd87
Formatter seems to be working
JamesWTruher 8c0b30b
change calls to analyzer to be more like the cmdlet
JamesWTruher e5e31af
checkpoint
JamesWTruher 2de9d8f
Since RunspacePools are disposable, implement IDisposable for HostedA…
JamesWTruher 1034af8
add another supported library
JamesWTruher 795b68c
Remove IDisposable in Helper as we no longer create a runspace pool
JamesWTruher a71ac90
make helper disposable to remove all vestiges of runspaces
JamesWTruher 65aae15
add sensible defaults code
JamesWTruher 567f530
Add hosted analyzer class
JamesWTruher 8d7d2a6
more hosting updates
JamesWTruher 73fec1b
Formatter seems to be working
JamesWTruher 874628a
change calls to analyzer to be more like the cmdlet
JamesWTruher 67dc945
checkpoint
JamesWTruher dd5b919
Since RunspacePools are disposable, implement IDisposable for HostedA…
JamesWTruher 01f7957
add another supported library
JamesWTruher ed3436b
Remove IDisposable in Helper as we no longer create a runspace pool
JamesWTruher db5c2f7
make helper disposable to remove all vestiges of runspaces
JamesWTruher 1b85759
Merge branch 'hosting' of https://github.com/JamesWTruher/PSScriptAna…
JamesWTruher a3d58a8
Add locking to hosted analyzer methods which change analyzer state
JamesWTruher b38e35d
Add simple locking to hosted analyzer apis
JamesWTruher b2e76ee
Change hostedanalyzer fields to properties
JamesWTruher ba88ff8
Remove dispose of Helper.Instance.
JamesWTruher 7610d49
Add an overload for Fix which takes a settings object
JamesWTruher e43d72b
Adding tests for HostedAnalyzer
JamesWTruher c969ead
fix ToString
JamesWTruher c081444
Add C# tests for the hosted analyzer
JamesWTruher 0dcb55d
Fix up reference assembly build and when it should be built
JamesWTruher fe6f907
Merge branch 'master' into hosting
JamesWTruher 8ecc70c
remove reference from build for the moment
JamesWTruher 6422360
bug fix - change initializer for a couple of Settings properties
JamesWTruher 893b553
Start removing dead code
JamesWTruher 15d21ef
More code cleanup
JamesWTruher d76f87c
Code Cleanup
JamesWTruher 7c1e74a
Merge remote-tracking branch 'upstream/master' into hosting
JamesWTruher aad6ed0
Merge branch 'master' into hosting
JamesWTruher 89ba69f
incorporate feedback from https://github.com/PowerShell/PowerShellEdi…
JamesWTruher 8e27c8b
Fix typo in WriteError to add to correct collection
JamesWTruher a88bc3b
Remove Get-Runspace from tests, it wasn't being used
JamesWTruher 182d128
Create helper function so we can test hosted analyzer on PS4
JamesWTruher 7b40004
update json library version
JamesWTruher b1a93c8
Merge remote-tracking branch 'upstream/master' into hosting
JamesWTruher 0fa1e64
Fix typo in hosted analyzer tests
JamesWTruher 99e9387
remove some of the nupkg creation code which we're not doing
JamesWTruher f0868fb
Add the new APIs to the reference assembly
JamesWTruher 3e9d242
Update version to 1.18.4 for signing files in hosting release
JamesWTruher 24533f3
Add reference build to build All
JamesWTruher bbb5d75
global.json needed in directory for build
JamesWTruher 00a73e3
Add .nupkg to be signed
JamesWTruher c744561
Add support for format with settings and range
JamesWTruher 909f62a
Add a couple of new apis that are needed by Editor Services
JamesWTruher 3f1debe
Update reference library to include changes in previous hosted analyzer
JamesWTruher 798f8b2
Make Fix and Format similar from a signature basis
JamesWTruher 1e8c7d8
Merge branch 'master' into hosting
JamesWTruher 88f379c
match sdk version with base project
JamesWTruher 28501a6
Merge branch 'master' into hosting
bergmeister 4e6c2ae
Add documentation for hosted analyzer
JamesWTruher f65bb3e
Merge branch 'hosting' of https://github.com/JamesWTruher/PSScriptAna…
JamesWTruher 43af91c
Merge branch 'master' into hosting
JamesWTruher 2afcc2a
Merge branch 'master' into hosting
JamesWTruher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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[] | ||
{ | ||
"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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the above |
||
range = updatedRange; | ||
} | ||
|
||
return text.ToString(); | ||
} | ||
/// <summary> | ||
/// Format a powershell script. | ||
/// </summary> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
note sure if .net optimises that anyway but we could use a constant for this