-
Notifications
You must be signed in to change notification settings - Fork 236
Remove all pipelines #690
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
Remove all pipelines #690
Conversation
@@ -32,27 +33,11 @@ public void PauseDebugger(Runspace runspace) | |||
out DebuggerResumeAction? debuggerResumeAction) | |||
{ | |||
IEnumerable<TResult> executionResult = null; | |||
|
|||
using (var nestedPipeline = currentRunspace.CreateNestedPipeline()) | |||
using (var pwsh = PowerShell.Create()) |
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.
I'd use the type name rather than var
here, since it's not apparent from Create()
.
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.
I think static Create
factory methods are common enough (especially in the PS engine) that they might as well be the same syntax as new PowerShell()
. I don't feel particularly strongly about it or anything, just weighing in.
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.
I left it as is this time since it's the pattern we currently use everywhere.
Pipeline pipeline = null; | ||
|
||
try | ||
using (var pwsh = PowerShell.Create()) |
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.
Same comment on var
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.
I left it as is this time since it's the pattern we currently use everywhere.
finally | ||
{ | ||
pipeline.Dispose(); | ||
return results.FirstOrDefault(); |
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.
Does this make the check above it redundant?
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.
no because you can pass in an alternative default value if you'd like.
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.
Oh right. Well the two calls to FirstOrDefault
still feel a bit redundant, and the first call is only relevant to reference types anyway.
So we could achieve the same with:
if (results.Count == 0)
{
return defaultValue;
}
return results.FirstOrDefault() ?? defaultValue;
Just a thought though
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.
Technically the final thing could just be results.First()
since having no results there is either impossible or a very strange bug...
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.
How about
results.DefaultIfEmpty(defaultValue).First();
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.
Oooh, yes! I thought that was a thing, but never used it before...
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.
fixed :)
{ | ||
executionResult = results.Cast<TResult>(); | ||
} | ||
pwsh.Runspace = currentRunspace; |
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.
I seem to recall seeing somewhere that setting Runspace
here to currentRunspace
does something special. It might be worth a comment about that if so.
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.
What special does it do? :)
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.
Like it replaces nested pipelines or something? Maybe I'm remembering wrong...
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.
I believe your thinking of PowerShell.Create(RunspaceMode.CurrentRunspace)
. In this case it's just a field, nothing special.
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.
Ok perfect!
using System.Management.Automation.Runspaces; | ||
|
||
namespace Microsoft.PowerShell.EditorServices.Session | ||
{ | ||
using System.Management.Automation; |
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.
There's a problem with putting this using
statement outside the namespace isn't there? We should leave a comment as to why.
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.
not sure why yet... :(
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.
LGTM
@@ -32,27 +33,11 @@ public void PauseDebugger(Runspace runspace) | |||
out DebuggerResumeAction? debuggerResumeAction) | |||
{ | |||
IEnumerable<TResult> executionResult = null; | |||
|
|||
using (var nestedPipeline = currentRunspace.CreateNestedPipeline()) | |||
using (var pwsh = PowerShell.Create()) |
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.
I think static Create
factory methods are common enough (especially in the PS engine) that they might as well be the same syntax as new PowerShell()
. I don't feel particularly strongly about it or anything, just weighing in.
Bringing this into 2.0.0... This removes all the Pipeline references so that we can easily transition to PowerShellStandard.