From 79dbd37d79eda266b0957189d6fb7c43b42d382f Mon Sep 17 00:00:00 2001 From: Tyler James Leonhardt Date: Wed, 23 Jan 2019 08:44:35 -0800 Subject: [PATCH 01/10] [Ignore] Prep 1.11 release with Changelog (#860) * Prep 1.11 release with Changelog * spaces --- CHANGELOG.md | 30 +++++++++++++++++++ PowerShellEditorServices.Common.props | 2 +- appveyor.yml | 2 +- .../PowerShellEditorServices.psd1 | 2 +- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c7a5de1a..b8224b258 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,35 @@ # PowerShell Editor Services Release History +## v1.11.0 +### Wednesday, January 23, 2019 + +- [PowerShellEditorServices #851](https://github.com/PowerShell/PowerShellEditorServices/pull/851) - + Fix #827 Pester TestName w/expandable str returns nothing (Thanks @rkeithhill!) +- [PowerShellEditorServices #850](https://github.com/PowerShell/PowerShellEditorServices/pull/850) - + Fix VSCODE 1683 - HelpCommentReqHdlr crash on GetFile (Thanks @rkeithhill!) +- [PowerShellEditorServices #825](https://github.com/PowerShell/PowerShellEditorServices/pull/825) - + (GH-824)(GH-812) Improve code folding speed (Thanks @glennsarti!) +- [PowerShellEditorServices #829](https://github.com/PowerShell/PowerShellEditorServices/pull/829) - + Update various NuGet packages (Thanks @bergmeister!) +- [PowerShellEditorServices #846](https://github.com/PowerShell/PowerShellEditorServices/pull/846) - + Workaround "attach to process" hang +- [PowerShellEditorServices #848](https://github.com/PowerShell/PowerShellEditorServices/pull/848) - + switch an instance of GetFile to TryGetFile to fix #1689 +- [PowerShellEditorServices #828](https://github.com/PowerShell/PowerShellEditorServices/pull/828) - + Compile against net452 because net451 is not supported any more (Thanks @bergmeister!) +- [PowerShellEditorServices #844](https://github.com/PowerShell/PowerShellEditorServices/pull/844) - + Fix an empty verbose message when importing an editor command (Thanks @alexandair!) +- [PowerShellEditorServices #843](https://github.com/PowerShell/PowerShellEditorServices/pull/843) - + Simplify the parameter descriptions and fix typos (Thanks @alexandair!) +- [PowerShellEditorServices #839](https://github.com/PowerShell/PowerShellEditorServices/pull/839) - + Fix FileNotFoundEx crash when Fold happens on untitled: scheme doc (Thanks @rkeithhill!) +- [PowerShellEditorServices #838](https://github.com/PowerShell/PowerShellEditorServices/pull/838) - + Fix NullRefEx bug when accessing scriptFile.ReferencedFiles (Thanks @rkeithhill!) +- [PowerShellEditorServices #842](https://github.com/PowerShell/PowerShellEditorServices/pull/842) - + Fix typos (Thanks @alexandair!) +- [PowerShellEditorServices #837](https://github.com/PowerShell/PowerShellEditorServices/pull/837) - + (maint) Add traits for folding tests (Thanks @glennsarti!) + ## v1.10.2 ### Tuesday, December 18, 2018 diff --git a/PowerShellEditorServices.Common.props b/PowerShellEditorServices.Common.props index baaba85ea..11c79f2d4 100644 --- a/PowerShellEditorServices.Common.props +++ b/PowerShellEditorServices.Common.props @@ -1,6 +1,6 @@ - 1.10.3 + 1.11.0 Microsoft © Microsoft Corporation. All rights reserved. PowerShell;editor;development;language;debugging diff --git a/appveyor.yml b/appveyor.yml index 4e1d1ba15..a9b79b3b6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: '1.10.3{build}' +version: '1.11.0{build}' image: Visual Studio 2017 clone_depth: 10 skip_tags: true diff --git a/module/PowerShellEditorServices/PowerShellEditorServices.psd1 b/module/PowerShellEditorServices/PowerShellEditorServices.psd1 index 236d68520..0ca94bd7e 100644 --- a/module/PowerShellEditorServices/PowerShellEditorServices.psd1 +++ b/module/PowerShellEditorServices/PowerShellEditorServices.psd1 @@ -12,7 +12,7 @@ RootModule = 'PowerShellEditorServices.psm1' # Version number of this module. -ModuleVersion = '1.10.3' +ModuleVersion = '1.11.0' # ID used to uniquely identify this module GUID = '9ca15887-53a2-479a-9cda-48d26bcb6c47' From d6bd5b1335425d32527ed7e4cb05336051d154f9 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 30 Jan 2019 09:43:53 -0800 Subject: [PATCH 02/10] Handle arbitrary exceptions when recursing workspace (#862) --- .../Workspace/Workspace.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/PowerShellEditorServices/Workspace/Workspace.cs b/src/PowerShellEditorServices/Workspace/Workspace.cs index 6b31b094f..6f9cb8beb 100644 --- a/src/PowerShellEditorServices/Workspace/Workspace.cs +++ b/src/PowerShellEditorServices/Workspace/Workspace.cs @@ -345,6 +345,14 @@ private void RecursivelyEnumerateFiles(string folderPath, ref List found continue; } + catch (Exception e) + { + this.logger.WriteHandledException( + $"Could not enumerate files in the path '{folderPath}' due to an exception", + e); + + continue; + } foundFiles.AddRange(psFiles); } @@ -386,6 +394,15 @@ private void RecursivelyEnumerateFiles(string folderPath, ref List found return; } + catch (Exception e) + { + this.logger.WriteHandledException( + $"Could not enumerate directories in the path '{folderPath}' due to an exception", + e); + + return; + } + foreach (string subDir in subDirs) { From bfd160222f0005f704923c4c28553722831968d5 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Mon, 4 Feb 2019 10:50:22 -0700 Subject: [PATCH 03/10] Catch NotSupportedException which can be thrown by FilleStream ctor (#866) The 7 exceptions that are caught now are doc'd in: https://docs.microsoft.com/en-us/dotnet/api/system.io.filestream.-ctor?view=netframework-4.7.2#System_IO_FileStream__ctor_System_String_System_IO_FileMode_System_IO_FileAccess_ --- src/PowerShellEditorServices/Workspace/Workspace.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/PowerShellEditorServices/Workspace/Workspace.cs b/src/PowerShellEditorServices/Workspace/Workspace.cs index 6f9cb8beb..d81f9f5e7 100644 --- a/src/PowerShellEditorServices/Workspace/Workspace.cs +++ b/src/PowerShellEditorServices/Workspace/Workspace.cs @@ -148,11 +148,12 @@ public bool TryGetFile(string filePath, out ScriptFile scriptFile) return true; } catch (Exception e) when ( - e is IOException || - e is SecurityException || + e is NotSupportedException || e is FileNotFoundException || e is DirectoryNotFoundException || e is PathTooLongException || + e is IOException || + e is SecurityException || e is UnauthorizedAccessException) { this.logger.WriteHandledException($"Failed to get file for {nameof(filePath)}: '{filePath}'", e); From a8960a5934275fbf266560e35c49fb4b74e72db5 Mon Sep 17 00:00:00 2001 From: "Christoph Bergmeister [MVP]" Date: Mon, 11 Feb 2019 17:53:51 +0000 Subject: [PATCH 04/10] Speed up travis builds by skipping the .net core initialisation (#868) --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 8209d54c8..b8ee9869c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,10 @@ language: cpp git: depth: 1000 + +env: + # Avoid expensive initialization of dotnet cli, see: https://donovanbrown.com/post/Stop-wasting-time-during-NET-Core-builds + DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 os: - linux From 3023a8b7bb4d049ac7c8eebdc98427fe10c3921c Mon Sep 17 00:00:00 2001 From: Doug Finke Date: Mon, 18 Feb 2019 19:36:05 -0500 Subject: [PATCH 05/10] Added `AsNewFile` switch to Out-CurrentFile (#869) * Added `AsNewFile` switch, plus, if a file is not open, it creates a new one * Update module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 Co-Authored-By: dfinke --- .../Commands/Public/Out-CurrentFile.ps1 | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 b/module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 index 5d0b5cf5c..75c4a192d 100644 --- a/module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 +++ b/module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 @@ -9,14 +9,32 @@ function Out-CurrentFile { #> [CmdletBinding()] param( - [Parameter(ValueFromPipeline, Mandatory=$true)] + [Switch]$AsNewFile, + + [Parameter(ValueFromPipeline, Mandatory = $true)] $InputObject ) Begin { $objectsToWrite = @() } Process { $objectsToWrite += $InputObject } End { + + # If requested, create a new file + if ($AsNewFile) { + $psEditor.Workspace.NewFile() + } + $outputString = "@`"`r`n{0}`r`n`"@" -f ($objectsToWrite|out-string).Trim() + + try { + # If there is no file open + $psEditor.GetEditorContext() + } + catch { + # create a new one + $psEditor.Workspace.NewFile() + } + $psEditor.GetEditorContext().CurrentFile.InsertText($outputString) } } From c5aae6b846d5fec6e198cc6417ac4575412b2354 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Mon, 4 Mar 2019 22:15:40 -0700 Subject: [PATCH 06/10] Return the start line number for Describe block (#873) * Return the start line number for Describe block Supports PR 1776 in vscode-powershell * Null check pesterSymbol.ScriptRegion * Update comment to cause new build to kick off * Whitespace change to kick off a new build --- .../CodeLens/PesterCodeLensProvider.cs | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/PowerShellEditorServices.Host/CodeLens/PesterCodeLensProvider.cs b/src/PowerShellEditorServices.Host/CodeLens/PesterCodeLensProvider.cs index 619ca0a49..e814918ab 100644 --- a/src/PowerShellEditorServices.Host/CodeLens/PesterCodeLensProvider.cs +++ b/src/PowerShellEditorServices.Host/CodeLens/PesterCodeLensProvider.cs @@ -41,9 +41,7 @@ public PesterCodeLensProvider(EditorSession editorSession) /// The Pester symbol to get CodeLenses for. /// The script file the Pester symbol comes from. /// All CodeLenses for the given Pester symbol. - private CodeLens[] GetPesterLens( - PesterSymbolReference pesterSymbol, - ScriptFile scriptFile) + private CodeLens[] GetPesterLens(PesterSymbolReference pesterSymbol, ScriptFile scriptFile) { var codeLensResults = new CodeLens[] { @@ -54,7 +52,11 @@ private CodeLens[] GetPesterLens( new ClientCommand( "PowerShell.RunPesterTests", "Run tests", - new object[] { scriptFile.ClientFilePath, false /* No debug */, pesterSymbol.TestName })), + new object[] { + scriptFile.ClientFilePath, + false /* No debug */, + pesterSymbol.TestName, + pesterSymbol.ScriptRegion?.StartLineNumber })), new CodeLens( this, @@ -63,7 +65,11 @@ private CodeLens[] GetPesterLens( new ClientCommand( "PowerShell.RunPesterTests", "Debug tests", - new object[] { scriptFile.ClientFilePath, true /* Run in debugger */, pesterSymbol.TestName })), + new object[] { + scriptFile.ClientFilePath, + true /* Run in the debugger */, + pesterSymbol.TestName, + pesterSymbol.ScriptRegion?.StartLineNumber })), }; return codeLensResults; @@ -99,9 +105,7 @@ public CodeLens[] ProvideCodeLenses(ScriptFile scriptFile) /// The code lens to resolve. /// /// The given CodeLens, wrapped in a task. - public Task ResolveCodeLensAsync( - CodeLens codeLens, - CancellationToken cancellationToken) + public Task ResolveCodeLensAsync(CodeLens codeLens, CancellationToken cancellationToken) { // This provider has no specific behavior for // resolving CodeLenses. From daf8c05a5dc54856466b9defd498a0cc97e18544 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Fri, 8 Mar 2019 07:29:59 -0700 Subject: [PATCH 07/10] Temporarily disable deemphasized stack frames to fix VSCode issue 1750 (#876) --- .../Debugging/StackFrameDetails.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/PowerShellEditorServices/Debugging/StackFrameDetails.cs b/src/PowerShellEditorServices/Debugging/StackFrameDetails.cs index 4f68f02ad..e217457fc 100644 --- a/src/PowerShellEditorServices/Debugging/StackFrameDetails.cs +++ b/src/PowerShellEditorServices/Debugging/StackFrameDetails.cs @@ -107,12 +107,14 @@ static internal StackFrameDetails Create( string scriptPath = (callStackFrameObject.Properties["ScriptName"].Value as string) ?? NoFileScriptPath; int startLineNumber = (int)(callStackFrameObject.Properties["ScriptLineNumber"].Value ?? 0); - if (workspaceRootPath != null && - invocationInfo != null && - !scriptPath.StartsWith(workspaceRootPath, StringComparison.OrdinalIgnoreCase)) - { - isExternal = true; - } + // TODO: RKH 2019-03-07 Temporarily disable "external" code until I have a chance to add + // settings to control this feature. + //if (workspaceRootPath != null && + // invocationInfo != null && + // !scriptPath.StartsWith(workspaceRootPath, StringComparison.OrdinalIgnoreCase)) + //{ + // isExternal = true; + //} return new StackFrameDetails { From 1a7441c344a7ef023d4728d5b5e8888feccbd292 Mon Sep 17 00:00:00 2001 From: Tyler James Leonhardt Date: Sun, 10 Mar 2019 11:12:23 -0700 Subject: [PATCH 08/10] [ignore] merge conflicts due to Async suffixes --- .../DebugAdapter/AttachRequest.cs | 2 + .../Server/DebugAdapter.cs | 65 ++++++++++++------- 2 files changed, 45 insertions(+), 22 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/AttachRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/AttachRequest.cs index e9734e002..24f117699 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/AttachRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/AttachRequest.cs @@ -21,5 +21,7 @@ public class AttachRequestArguments public string ProcessId { get; set; } public int RunspaceId { get; set; } + + public string CustomPipeName { get; set; } } } diff --git a/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs b/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs index a43f5a7d3..61a8afee3 100644 --- a/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs +++ b/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs @@ -23,6 +23,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.Server { public class DebugAdapter { + private static readonly Version _minVersionForCustomPipeName = new Version(6, 2); + private EditorSession _editorSession; private bool _noDebug; @@ -344,11 +346,17 @@ protected async Task HandleAttachRequest( RegisterEventHandlers(); + bool processIdIsSet = !string.IsNullOrEmpty(attachParams.ProcessId) && attachParams.ProcessId != "undefined"; + bool customPipeNameIsSet = !string.IsNullOrEmpty(attachParams.CustomPipeName) && attachParams.CustomPipeName != "undefined"; + + PowerShellVersionDetails runspaceVersion = + _editorSession.PowerShellContext.CurrentRunspace.PowerShellVersion; + // If there are no host processes to attach to or the user cancels selection, we get a null for the process id. // This is not an error, just a request to stop the original "attach to" request. // Testing against "undefined" is a HACK because I don't know how to make "Cancel" on quick pick loading // to cancel on the VSCode side without sending an attachRequest with processId set to "undefined". - if (string.IsNullOrEmpty(attachParams.ProcessId) || (attachParams.ProcessId == "undefined")) + if (!processIdIsSet && !customPipeNameIsSet) { Logger.Write( LogLevel.Normal, @@ -364,9 +372,6 @@ await requestContext.SendError( if (attachParams.ComputerName != null) { - PowerShellVersionDetails runspaceVersion = - _editorSession.PowerShellContext.CurrentRunspace.PowerShellVersion; - if (runspaceVersion.Version.Major < 4) { await requestContext.SendError( @@ -397,16 +402,12 @@ await requestContext.SendError( _isRemoteAttach = true; } - if (int.TryParse(attachParams.ProcessId, out int processId) && (processId > 0)) + if (processIdIsSet && int.TryParse(attachParams.ProcessId, out int processId) && (processId > 0)) { - PowerShellVersionDetails runspaceVersion = - _editorSession.PowerShellContext.CurrentRunspace.PowerShellVersion; - if (runspaceVersion.Version.Major < 5) { await requestContext.SendError( $"Attaching to a process is only available with PowerShell 5 and higher (current session is {runspaceVersion.Version})."); - return; } @@ -421,20 +422,27 @@ await requestContext.SendError( return; } + } + else if (customPipeNameIsSet) + { + if (runspaceVersion.Version < _minVersionForCustomPipeName) + { + await requestContext.SendError( + $"Attaching to a process with CustomPipeName is only available with PowerShell 6.2 and higher (current session is {runspaceVersion.Version})."); + return; + } - // Clear any existing breakpoints before proceeding - await ClearSessionBreakpoints(); - - // Execute the Debug-Runspace command but don't await it because it - // will block the debug adapter initialization process. The - // InitializedEvent will be sent as soon as the RunspaceChanged - // event gets fired with the attached runspace. - int runspaceId = attachParams.RunspaceId > 0 ? attachParams.RunspaceId : 1; - _waitingForAttach = true; - Task nonAwaitedTask = - _editorSession.PowerShellContext - .ExecuteScriptString($"\nDebug-Runspace -Id {runspaceId}") - .ContinueWith(OnExecutionCompleted); + await _editorSession.PowerShellContext.ExecuteScriptString( + $"Enter-PSHostProcess -CustomPipeName {attachParams.CustomPipeName}", + errorMessages); + + if (errorMessages.Length > 0) + { + await requestContext.SendError( + $"Could not attach to process with CustomPipeName: '{attachParams.CustomPipeName}'"); + + return; + } } else { @@ -448,6 +456,19 @@ await requestContext.SendError( return; } + // Clear any existing breakpoints before proceeding + await ClearSessionBreakpoints().ConfigureAwait(continueOnCapturedContext: false); + + // Execute the Debug-Runspace command but don't await it because it + // will block the debug adapter initialization process. The + // InitializedEvent will be sent as soon as the RunspaceChanged + // event gets fired with the attached runspace. + int runspaceId = attachParams.RunspaceId > 0 ? attachParams.RunspaceId : 1; + _waitingForAttach = true; + Task nonAwaitedTask = _editorSession.PowerShellContext + .ExecuteScriptString($"\nDebug-Runspace -Id {runspaceId}") + .ContinueWith(OnExecutionCompleted); + await requestContext.SendResult(null); } From 731759e3878216ff61c9a08ce78391bdc533f04a Mon Sep 17 00:00:00 2001 From: Adam Driscoll Date: Wed, 13 Mar 2019 14:11:30 -0600 Subject: [PATCH 09/10] Add attach to local runspace. (#875) * Add attach to local runspace. * Remove comment. * Use single runspaceId property. * Remove unnecessary processId check. * Factored if. * Update src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs It's neat that we can just commit a suggestion. Co-Authored-By: adamdriscoll * Use runspace rather than dynamic. * Accept process ID for GetRunspaceRequest. * Clean up. --- .../DebugAdapter/AttachRequest.cs | 2 +- .../LanguageServer/GetRunspaceRequest.cs | 25 +++++++++ .../Server/DebugAdapter.cs | 17 ++++++- .../Server/LanguageServer.cs | 51 +++++++++++++++++++ 4 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 src/PowerShellEditorServices.Protocol/LanguageServer/GetRunspaceRequest.cs diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/AttachRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/AttachRequest.cs index 24f117699..185a1aac0 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/AttachRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/AttachRequest.cs @@ -20,7 +20,7 @@ public class AttachRequestArguments public string ProcessId { get; set; } - public int RunspaceId { get; set; } + public string RunspaceId { get; set; } public string CustomPipeName { get; set; } } diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/GetRunspaceRequest.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/GetRunspaceRequest.cs new file mode 100644 index 000000000..e151aa7f0 --- /dev/null +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/GetRunspaceRequest.cs @@ -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 Type = + RequestType.Create("powerShell/getRunspace"); + } + + public class GetRunspaceResponse + { + public int Id { get; set; } + + public string Name { get; set; } + + public string Availability { get; set; } + } +} diff --git a/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs b/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs index 61a8afee3..c3d42ea95 100644 --- a/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs +++ b/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs @@ -444,7 +444,7 @@ await requestContext.SendError( return; } } - else + else if (attachParams.ProcessId != "current") { Logger.Write( LogLevel.Error, @@ -463,7 +463,20 @@ await requestContext.SendError( // will block the debug adapter initialization process. The // InitializedEvent will be sent as soon as the RunspaceChanged // event gets fired with the attached runspace. - int runspaceId = attachParams.RunspaceId > 0 ? attachParams.RunspaceId : 1; + + var runspaceId = 1; + if (!int.TryParse(attachParams.RunspaceId, out runspaceId) || runspaceId <= 0) + { + Logger.Write( + LogLevel.Error, + $"Attach request failed, '{attachParams.RunspaceId}' is an invalid value for the processId."); + + await requestContext.SendErrorAsync( + "A positive integer must be specified for the RunspaceId field."); + + return; + } + _waitingForAttach = true; Task nonAwaitedTask = _editorSession.PowerShellContext .ExecuteScriptString($"\nDebug-Runspace -Id {runspaceId}") diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index 0432fa2ee..887ec3754 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -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 requestContext) + { + var runspaceResponses = new List(); + + 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(); + IEnumerable runspaces = await editorSession.PowerShellContext.ExecuteCommandAsync(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.ExecuteCommandAsync(exitCommand); + } + } + + await requestContext.SendResultAsync(runspaceResponses.ToArray()); + } + private bool IsQueryMatch(string query, string symbolName) { return symbolName.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0; From e9c4ec37e1e29f63cd42fd989f53b0954c83548e Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Thu, 14 Mar 2019 10:05:58 -0700 Subject: [PATCH 10/10] remove Async suffixes --- .../Server/DebugAdapter.cs | 2 +- .../Server/LanguageServer.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs b/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs index c3d42ea95..c3e203829 100644 --- a/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs +++ b/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs @@ -471,7 +471,7 @@ await requestContext.SendError( LogLevel.Error, $"Attach request failed, '{attachParams.RunspaceId}' is an invalid value for the processId."); - await requestContext.SendErrorAsync( + await requestContext.SendError( "A positive integer must be specified for the RunspaceId field."); return; diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index 887ec3754..de4fc99eb 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -1257,7 +1257,7 @@ protected async Task HandleGetRunspaceRequestAsync( psCommand.AddCommand("Get-Runspace"); StringBuilder sb = new StringBuilder(); - IEnumerable runspaces = await editorSession.PowerShellContext.ExecuteCommandAsync(psCommand, sb); + IEnumerable runspaces = await editorSession.PowerShellContext.ExecuteCommand(psCommand, sb); if (runspaces != null) { foreach (var p in runspaces) @@ -1275,11 +1275,11 @@ protected async Task HandleGetRunspaceRequestAsync( if (isNotCurrentProcess) { var exitCommand = new PSCommand(); exitCommand.AddCommand("Exit-PSHostProcess"); - await editorSession.PowerShellContext.ExecuteCommandAsync(exitCommand); + await editorSession.PowerShellContext.ExecuteCommand(exitCommand); } } - await requestContext.SendResultAsync(runspaceResponses.ToArray()); + await requestContext.SendResult(runspaceResponses.ToArray()); } private bool IsQueryMatch(string query, string symbolName)