Skip to content

Commit fbaff7c

Browse files
authored
Merge pull request #1588 from rjmholt/pt-fix-ci
Fix integration testing for pipeline consumer branch
2 parents 0c85a01 + fcc4cd8 commit fbaff7c

30 files changed

+549
-470
lines changed

.vsts-ci/azure-pipelines-ci.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ variables:
88
- name: DOTNET_CLI_TELEMETRY_OPTOUT
99
value: 'true'
1010

11-
trigger:
12-
branches:
13-
include:
14-
- master
15-
16-
pr:
17-
- master
18-
1911
jobs:
2012
- job: PS51_Win2016
2113
displayName: PowerShell 5.1 - Windows Server 2016

integrated.sln

Lines changed: 0 additions & 153 deletions
This file was deleted.

src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ public static EditorServicesLoader Create(
120120
{
121121
AppDomain.CurrentDomain.AssemblyLoad += (object sender, AssemblyLoadEventArgs args) =>
122122
{
123+
if (args.LoadedAssembly.IsDynamic)
124+
{
125+
return;
126+
}
127+
123128
logger.Log(
124129
PsesLogLevel.Diagnostic,
125130
$"Loaded '{args.LoadedAssembly.GetName()}' from '{args.LoadedAssembly.Location}'");

src/PowerShellEditorServices/Server/PsesDebugServer.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.IO;
6+
using System.Threading;
67
using System.Threading.Tasks;
78
using Microsoft.Extensions.DependencyInjection;
89
using Microsoft.Extensions.Logging;
@@ -28,7 +29,9 @@ internal class PsesDebugServer : IDisposable
2829

2930
private DebugAdapterServer _debugAdapterServer;
3031

31-
private PowerShellDebugContext _debugContext;
32+
private PsesInternalHost _psesHost;
33+
34+
private bool _startedPses;
3235

3336
protected readonly ILoggerFactory _loggerFactory;
3437

@@ -61,8 +64,8 @@ public async Task StartAsync()
6164
{
6265
// We need to let the PowerShell Context Service know that we are in a debug session
6366
// so that it doesn't send the powerShell/startDebugger message.
64-
_debugContext = ServiceProvider.GetService<PsesInternalHost>().DebugContext;
65-
_debugContext.IsDebugServerActive = true;
67+
_psesHost = ServiceProvider.GetService<PsesInternalHost>();
68+
_psesHost.DebugContext.IsDebugServerActive = true;
6669

6770
options
6871
.WithInput(_inputStream)
@@ -88,8 +91,11 @@ public async Task StartAsync()
8891
// The OnInitialize delegate gets run when we first receive the _Initialize_ request:
8992
// https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Initialize
9093
.OnInitialize(async (server, request, cancellationToken) => {
94+
// We need to make sure the host has been started
95+
_startedPses = !(await _psesHost.TryStartAsync(new HostStartOptions(), CancellationToken.None).ConfigureAwait(false));
96+
9197
// Ensure the debugger mode is set correctly - this is required for remote debugging to work
92-
_debugContext.EnableDebugMode();
98+
_psesHost.DebugContext.EnableDebugMode();
9399

94100
var breakpointService = server.GetService<BreakpointService>();
95101
// Clear any existing breakpoints before proceeding
@@ -115,7 +121,7 @@ public void Dispose()
115121
// Note that the lifetime of the DebugContext is longer than the debug server;
116122
// It represents the debugger on the PowerShell process we're in,
117123
// while a new debug server is spun up for every debugging session
118-
_debugContext.IsDebugServerActive = false;
124+
_psesHost.DebugContext.IsDebugServerActive = false;
119125
_debugAdapterServer.Dispose();
120126
_inputStream.Dispose();
121127
_outputStream.Dispose();
@@ -126,6 +132,13 @@ public void Dispose()
126132
public async Task WaitForShutdown()
127133
{
128134
await _serverStopped.Task.ConfigureAwait(false);
135+
136+
// If we started the host, we need to ensure any errors are marshalled back to us like this
137+
if (_startedPses)
138+
{
139+
_psesHost.TriggerShutdown();
140+
await _psesHost.Shutdown.ConfigureAwait(false);
141+
}
129142
}
130143

131144
#region Events

src/PowerShellEditorServices/Server/PsesLanguageServer.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Microsoft.PowerShell.EditorServices.Hosting;
1111
using Microsoft.PowerShell.EditorServices.Services;
1212
using Microsoft.PowerShell.EditorServices.Services.Extension;
13+
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
1314
using Microsoft.PowerShell.EditorServices.Services.Template;
1415
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
1516
using OmniSharp.Extensions.LanguageServer.Server;
@@ -32,6 +33,8 @@ internal class PsesLanguageServer
3233
private readonly HostStartupInfo _hostDetails;
3334
private readonly TaskCompletionSource<bool> _serverStart;
3435

36+
private PsesInternalHost _psesHost;
37+
3538
/// <summary>
3639
/// Create a new language server instance.
3740
/// </summary>
@@ -75,8 +78,12 @@ public async Task StartAsync()
7578
options
7679
.WithInput(_inputStream)
7780
.WithOutput(_outputStream)
78-
.WithServices(serviceCollection => serviceCollection
79-
.AddPsesLanguageServices(_hostDetails)) // NOTE: This adds a lot of services!
81+
.WithServices(serviceCollection =>
82+
{
83+
84+
// NOTE: This adds a lot of services!
85+
serviceCollection.AddPsesLanguageServices(_hostDetails);
86+
})
8087
.ConfigureLogging(builder => builder
8188
.AddSerilog(Log.Logger) // TODO: Set dispose to true?
8289
.AddLanguageProtocolLogging()
@@ -116,6 +123,8 @@ public async Task StartAsync()
116123

117124
IServiceProvider serviceProvider = languageServer.Services;
118125

126+
_psesHost = serviceProvider.GetService<PsesInternalHost>();
127+
119128
var workspaceService = serviceProvider.GetService<WorkspaceService>();
120129

121130
// Grab the workspace path from the parameters
@@ -150,6 +159,10 @@ public async Task WaitForShutdown()
150159
Log.Logger.Debug("Shutting down OmniSharp Language Server");
151160
await _serverStart.Task.ConfigureAwait(false);
152161
await LanguageServer.WaitForExit.ConfigureAwait(false);
162+
163+
// Doing this means we're able to route through any exceptions experienced on the pipeline thread
164+
_psesHost.TriggerShutdown();
165+
await _psesHost.Shutdown.ConfigureAwait(false);
153166
}
154167
}
155168
}

src/PowerShellEditorServices/Services/DebugAdapter/Handlers/ConfigurationDoneHandler.cs

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,16 @@ private static PSCommand BuildPSCommandFromArguments(string command, IReadOnlyLi
158158

159159
// We are forced to use a hack here so that we can reuse PowerShell's parameter binding
160160
var sb = new StringBuilder()
161-
.Append("& '")
162-
.Append(command.Replace("'", "''"))
163-
.Append("'");
161+
.Append("& ")
162+
.Append(StringEscaping.SingleQuoteAndEscape(command));
164163

165164
foreach (string arg in arguments)
166165
{
167166
sb.Append(' ');
168167

169-
if (ArgumentNeedsEscaping(arg))
168+
if (StringEscaping.PowerShellArgumentNeedsEscaping(arg))
170169
{
171-
sb.Append('\'').Append(arg.Replace("'", "''")).Append('\'');
170+
sb.Append(StringEscaping.SingleQuoteAndEscape(arg));
172171
}
173172
else
174173
{
@@ -178,25 +177,5 @@ private static PSCommand BuildPSCommandFromArguments(string command, IReadOnlyLi
178177

179178
return new PSCommand().AddScript(sb.ToString());
180179
}
181-
182-
private static bool ArgumentNeedsEscaping(string argument)
183-
{
184-
foreach (char c in argument)
185-
{
186-
switch (c)
187-
{
188-
case '\'':
189-
case '"':
190-
case '|':
191-
case '&':
192-
case ';':
193-
case ':':
194-
case char w when char.IsWhiteSpace(w):
195-
return true;
196-
}
197-
}
198-
199-
return false;
200-
}
201180
}
202181
}

src/PowerShellEditorServices/Services/PowerShell/Debugging/PowerShellDebugContext.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,12 @@ public void StepOver()
107107
public void SetDebugResuming(DebuggerResumeAction debuggerResumeAction)
108108
{
109109
_psesHost.SetExit();
110-
LastStopEventArgs.ResumeAction = debuggerResumeAction;
110+
111+
if (LastStopEventArgs is not null)
112+
{
113+
LastStopEventArgs.ResumeAction = debuggerResumeAction;
114+
}
115+
111116
// We need to tell whatever is happening right now in the debug prompt to wrap up so we can continue
112117
_psesHost.CancelCurrentTask();
113118
}

0 commit comments

Comments
 (0)