-
Notifications
You must be signed in to change notification settings - Fork 236
WIP Cherry pick for legacy #883
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
Merged
TylerLeonhardt
merged 8 commits into
PowerShell:legacy/1.x
from
TylerLeonhardt:test-cherry-picks
Mar 20, 2019
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bfd1602
Catch NotSupportedException which can be thrown by FilleStream ctor (…
rkeithhill a8960a5
Speed up travis builds by skipping the .net core initialisation (#868)
bergmeister 3023a8b
Added `AsNewFile` switch to Out-CurrentFile (#869)
dfinke c5aae6b
Return the start line number for Describe block (#873)
rkeithhill daf8c05
Temporarily disable deemphasized stack frames to fix VSCode issue 175…
rkeithhill 1a7441c
[ignore] merge conflicts due to Async suffixes
TylerLeonhardt 731759e
Add attach to local runspace. (#875)
adamdriscoll e9c4ec3
remove Async suffixes
TylerLeonhardt 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
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
25 changes: 25 additions & 0 deletions
25
src/PowerShellEditorServices.Protocol/LanguageServer/GetRunspaceRequest.cs
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol; | ||
|
||
namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer | ||
{ | ||
public class GetRunspaceRequest | ||
{ | ||
public static readonly | ||
RequestType<string, GetRunspaceResponse[], object, object> Type = | ||
RequestType<string, GetRunspaceResponse[], object, object>.Create("powerShell/getRunspace"); | ||
} | ||
|
||
public class GetRunspaceResponse | ||
{ | ||
public int Id { get; set; } | ||
|
||
public string Name { get; set; } | ||
|
||
public string Availability { get; set; } | ||
} | ||
} |
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 |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
using System.Linq; | ||
using System.Management.Automation; | ||
using System.Management.Automation.Language; | ||
using System.Management.Automation.Runspaces; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Threading; | ||
|
@@ -162,6 +163,8 @@ public void Start() | |
this.messageHandlers.SetRequestHandler(GetPSHostProcessesRequest.Type, this.HandleGetPSHostProcessesRequest); | ||
this.messageHandlers.SetRequestHandler(CommentHelpRequest.Type, this.HandleCommentHelpRequest); | ||
|
||
this.messageHandlers.SetRequestHandler(GetRunspaceRequest.Type, this.HandleGetRunspaceRequestAsync); | ||
|
||
// Initialize the extension service | ||
// TODO: This should be made awaited once Initialize is async! | ||
this.editorSession.ExtensionService.Initialize( | ||
|
@@ -1231,6 +1234,54 @@ protected async Task HandleCommentHelpRequest( | |
await requestContext.SendResult(result); | ||
} | ||
|
||
protected async Task HandleGetRunspaceRequestAsync( | ||
string processId, | ||
RequestContext<GetRunspaceResponse[]> requestContext) | ||
{ | ||
var runspaceResponses = new List<GetRunspaceResponse>(); | ||
|
||
if (this.editorSession.PowerShellContext.LocalPowerShellVersion.Version.Major >= 5) | ||
{ | ||
if (processId == null) { | ||
processId = "current"; | ||
} | ||
|
||
var isNotCurrentProcess = processId != null && processId != "current"; | ||
|
||
var psCommand = new PSCommand(); | ||
|
||
if (isNotCurrentProcess) { | ||
psCommand.AddCommand("Enter-PSHostProcess").AddParameter("Id", processId).AddStatement(); | ||
} | ||
|
||
psCommand.AddCommand("Get-Runspace"); | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
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 happened to the 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. That's in #881 |
||
IEnumerable<Runspace> runspaces = await editorSession.PowerShellContext.ExecuteCommand<Runspace>(psCommand, sb); | ||
if (runspaces != null) | ||
{ | ||
foreach (var p in runspaces) | ||
{ | ||
runspaceResponses.Add( | ||
new GetRunspaceResponse | ||
{ | ||
Id = p.Id, | ||
Name = p.Name, | ||
Availability = p.RunspaceAvailability.ToString() | ||
}); | ||
} | ||
} | ||
|
||
if (isNotCurrentProcess) { | ||
var exitCommand = new PSCommand(); | ||
exitCommand.AddCommand("Exit-PSHostProcess"); | ||
await editorSession.PowerShellContext.ExecuteCommand(exitCommand); | ||
} | ||
} | ||
|
||
await requestContext.SendResult(runspaceResponses.ToArray()); | ||
} | ||
|
||
private bool IsQueryMatch(string query, string symbolName) | ||
{ | ||
return symbolName.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0; | ||
|
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
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.
A few parens here would make this a bit easier to visually parse.
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.
Also fixed in #881