-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,12 @@ | |
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Management.Automation; | ||
using System.Management.Automation.Runspaces; | ||
|
||
namespace Microsoft.PowerShell.EditorServices.Session | ||
{ | ||
using System.Management.Automation; | ||
|
||
internal class PowerShell3Operations : IVersionSpecificOperations | ||
{ | ||
public void ConfigureDebugger(Runspace runspace) | ||
|
@@ -32,27 +33,11 @@ public IEnumerable<TResult> ExecuteCommandInDebugger<TResult>( | |
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 commentThe reason will be displayed to describe this comment to others. Learn more. I'd use the type name rather than 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. I think static 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. I left it as is this time since it's the pattern we currently use everywhere. |
||
{ | ||
foreach (var command in psCommand.Commands) | ||
{ | ||
nestedPipeline.Commands.Add(command); | ||
} | ||
|
||
var results = nestedPipeline.Invoke(); | ||
|
||
if (typeof(TResult) != typeof(PSObject)) | ||
{ | ||
executionResult = | ||
results | ||
.Select(pso => pso.BaseObject) | ||
.Cast<TResult>(); | ||
} | ||
else | ||
{ | ||
executionResult = results.Cast<TResult>(); | ||
} | ||
pwsh.Runspace = currentRunspace; | ||
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. I seem to recall seeing somewhere that setting 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. What special does it do? :) 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. 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 commentThe reason will be displayed to describe this comment to others. Learn more. I believe your thinking of 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. Ok perfect! |
||
pwsh.Commands = psCommand; | ||
executionResult = pwsh.Invoke<TResult>(); | ||
} | ||
|
||
// Write the output to the host if necessary | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -823,44 +823,11 @@ await this.ExecuteCommand<object>( | |
|
||
internal static TResult ExecuteScriptAndGetItem<TResult>(string scriptToExecute, Runspace runspace, TResult defaultValue = default(TResult)) | ||
{ | ||
Pipeline pipeline = null; | ||
|
||
try | ||
using (var pwsh = PowerShell.Create()) | ||
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. Same comment on 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. I left it as is this time since it's the pattern we currently use everywhere. |
||
{ | ||
if (runspace.RunspaceAvailability == RunspaceAvailability.AvailableForNestedCommand) | ||
{ | ||
pipeline = runspace.CreateNestedPipeline(scriptToExecute, false); | ||
} | ||
else | ||
{ | ||
pipeline = runspace.CreatePipeline(scriptToExecute, false); | ||
} | ||
|
||
Collection<PSObject> results = pipeline.Invoke(); | ||
|
||
if (results.Count == 0 || results.FirstOrDefault() == null) | ||
{ | ||
return defaultValue; | ||
} | ||
|
||
if (typeof(TResult) != typeof(PSObject)) | ||
{ | ||
return results | ||
.Select(pso => pso.BaseObject) | ||
.OfType<TResult>() | ||
.FirstOrDefault(); | ||
} | ||
else | ||
{ | ||
return | ||
results | ||
.OfType<TResult>() | ||
.FirstOrDefault(); | ||
} | ||
} | ||
finally | ||
{ | ||
pipeline.Dispose(); | ||
pwsh.Runspace = runspace; | ||
Collection<TResult> results = pwsh.AddScript(scriptToExecute).Invoke<TResult>(); | ||
return results.DefaultIfEmpty(defaultValue).First(); | ||
} | ||
} | ||
|
||
|
@@ -1526,6 +1493,12 @@ private async Task<SessionDetails> GetSessionDetailsInRunspace() | |
} | ||
} | ||
|
||
private SessionDetails GetSessionDetailsInNestedPipeline() | ||
{ | ||
|
||
return GetSessionDetailsInRunspace(this.CurrentRunspace.Runspace); | ||
} | ||
|
||
private SessionDetails GetSessionDetailsInRunspace(Runspace runspace) | ||
{ | ||
SessionDetails sessionDetails = | ||
|
@@ -1561,24 +1534,6 @@ private SessionDetails GetSessionDetailsInDebugger() | |
}); | ||
} | ||
|
||
private SessionDetails GetSessionDetailsInNestedPipeline() | ||
{ | ||
using (var pipeline = this.CurrentRunspace.Runspace.CreateNestedPipeline()) | ||
{ | ||
return this.GetSessionDetails( | ||
command => | ||
{ | ||
pipeline.Commands.Clear(); | ||
pipeline.Commands.Add(command.Commands[0]); | ||
|
||
return | ||
pipeline | ||
.Invoke() | ||
.FirstOrDefault(); | ||
}); | ||
} | ||
} | ||
|
||
private void SetProfileVariableInCurrentRunspace(ProfilePaths profilePaths) | ||
{ | ||
// Create the $profile variable | ||
|
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... :(