★ wanayoo — archive 1999 https://github.com/PowerShell/PowerShellEditorServices/pull/881Nouvelle recherche | Portail wanayoo
Skip to content
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

NamedPipeConnectionInfo <= Enter-PSHostProcess #881

Conversation

@TylerLeonhardt
Copy link
Member

@TylerLeonhardt TylerLeonhardt commented Mar 18, 2019

cc @adamdriscoll

Before, we relied on Enter-PSHostProcess... I noticed that this wasn't working and instead the GeRunspace function would return results from the current runspace instead.

This switches to using NamedPipeConnectionInfo API way of invoking something on a remote runspace.

@TylerLeonhardt
Copy link
Member Author

@TylerLeonhardt TylerLeonhardt commented Mar 18, 2019

@SeeminglyScience let me know if you see anything wrong with this in the scope of the threading model... I think it will be fine since it's a totally separate runspace...

else
{
var psCommand = new PSCommand().AddCommand("Get-Runspace");
StringBuilder sb = new StringBuilder();

This comment has been minimized.

@rkeithhill

rkeithhill Mar 18, 2019
Collaborator

Use var here - channeling my inner @rjmholt. :-)

This comment has been minimized.

@TylerLeonhardt

TylerLeonhardt Mar 18, 2019
Author Member

got me!

{
foreach (var p in runspaces)
// Create a remote runspace that we will invoke Get-Runspace in
using(var rs = RunspaceFactory.CreateRunspace(new NamedPipeConnectionInfo(pid)))

This comment has been minimized.

@rkeithhill

rkeithhill Mar 18, 2019
Collaborator

Will this work with all supported versions of PowerShell?

This comment has been minimized.

@TylerLeonhardt

TylerLeonhardt Mar 18, 2019 •
Author Member

Good catch... this use to be a runtime check using Enter-PSHostProcess but now it's an assembly load check...

This will work in PowerShell 5.1+ so it's not a problem in this PR.

But when I backport I need to ifdef this properly...

var
This was referenced Mar 18, 2019
Copy link
Collaborator

@SeeminglyScience SeeminglyScience left a comment

LGTM :)

Just some optional nits

rs.Open();
ps.Runspace = rs;
// returns deserialized Runspaces. For simpler code, we use PSObject and rely on dynamic later.
runspaces = ps.AddCommand("Get-Runspace").Invoke<PSObject>();

This comment has been minimized.

@SeeminglyScience

SeeminglyScience Mar 19, 2019
Collaborator

Suggested change
runspaces = ps.AddCommand("Get-Runspace").Invoke<PSObject>();
runspaces = ps.AddCommand("Microsoft.PowerShell.Utility\\Get-Runspace").Invoke<PSObject>();
}
}
else
{
var psCommand = new PSCommand().AddCommand("Get-Runspace");

This comment has been minimized.

@SeeminglyScience

SeeminglyScience Mar 19, 2019
Collaborator

Suggested change
var psCommand = new PSCommand().AddCommand("Get-Runspace");
var psCommand = new PSCommand().AddCommand("Microsoft.PowerShell.Utility\\Get-Runspace");
{
foreach (var p in runspaces)
// Create a remote runspace that we will invoke Get-Runspace in

This comment has been minimized.

@SeeminglyScience

SeeminglyScience Mar 19, 2019
Collaborator

Suggested change
// Create a remote runspace that we will invoke Get-Runspace in
// Create a remote runspace that we will invoke Get-Runspace in.
});
rs.Open();
ps.Runspace = rs;
// returns deserialized Runspaces. For simpler code, we use PSObject and rely on dynamic later.

This comment has been minimized.

@SeeminglyScience

SeeminglyScience Mar 19, 2019
Collaborator

Suggested change
// returns deserialized Runspaces. For simpler code, we use PSObject and rely on dynamic later.
// Returns deserialized Runspaces. For simpler code, we use PSObject and rely on dynamic later.
IEnumerable<Runspace> runspaces = await editorSession.PowerShellContext.ExecuteCommandAsync<Runspace>(psCommand, sb);
if (runspaces != null)
// If the processId is a valid int, we need to run Get-Runspace within that process
// otherwise just use the current runspace

This comment has been minimized.

@SeeminglyScience

SeeminglyScience Mar 19, 2019
Collaborator

Suggested change
// otherwise just use the current runspace
// otherwise just use the current runspace.
await editorSession.PowerShellContext.ExecuteCommandAsync(exitCommand);
if (runspaces != null)
{
foreach (dynamic p in runspaces)

This comment has been minimized.

@SeeminglyScience

SeeminglyScience Mar 19, 2019 •
Collaborator

Consider using a more descriptive variable name like runspace or even pso.

Edit: didn't realize this was existing code, but maybe still worth fixing.

@TylerLeonhardt TylerLeonhardt merged commit f3d32cd into PowerShell:master Mar 20, 2019
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
license/cla All CLA requirements met.
Details
@TylerLeonhardt TylerLeonhardt deleted the TylerLeonhardt:dont-rely-on-enter-pshostprocess branch Mar 20, 2019
TylerLeonhardt added a commit to TylerLeonhardt/PowerShellEditorServices that referenced this pull request Mar 20, 2019
TylerLeonhardt added a commit that referenced this pull request Mar 21, 2019
* backport #881 in a different way

* simpler

* switch back to reflecting

* address feedback

* more feedback

* safe check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.