Skip to content

Fix testing for pipeline consumer branch #1588

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
merged 17 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .vsts-ci/azure-pipelines-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ variables:
- name: DOTNET_CLI_TELEMETRY_OPTOUT
value: 'true'

trigger:
branches:
include:
- master

pr:
- master

jobs:
- job: PS51_Win2016
displayName: PowerShell 5.1 - Windows Server 2016
Expand Down
153 changes: 0 additions & 153 deletions integrated.sln

This file was deleted.

5 changes: 5 additions & 0 deletions src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ public static EditorServicesLoader Create(
{
AppDomain.CurrentDomain.AssemblyLoad += (object sender, AssemblyLoadEventArgs args) =>
{
if (args.LoadedAssembly.IsDynamic)
{
return;
}

logger.Log(
PsesLogLevel.Diagnostic,
$"Loaded '{args.LoadedAssembly.GetName()}' from '{args.LoadedAssembly.Location}'");
Expand Down
23 changes: 18 additions & 5 deletions src/PowerShellEditorServices/Server/PsesDebugServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
Expand All @@ -28,7 +29,9 @@ internal class PsesDebugServer : IDisposable

private DebugAdapterServer _debugAdapterServer;

private PowerShellDebugContext _debugContext;
private PsesInternalHost _psesHost;

private bool _startedPses;

protected readonly ILoggerFactory _loggerFactory;

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

options
.WithInput(_inputStream)
Expand All @@ -88,8 +91,11 @@ public async Task StartAsync()
// The OnInitialize delegate gets run when we first receive the _Initialize_ request:
// https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Initialize
.OnInitialize(async (server, request, cancellationToken) => {
// We need to make sure the host has been started
_startedPses = !(await _psesHost.TryStartAsync(new HostStartOptions(), CancellationToken.None).ConfigureAwait(false));

// Ensure the debugger mode is set correctly - this is required for remote debugging to work
_debugContext.EnableDebugMode();
_psesHost.DebugContext.EnableDebugMode();

var breakpointService = server.GetService<BreakpointService>();
// Clear any existing breakpoints before proceeding
Expand All @@ -115,7 +121,7 @@ public void Dispose()
// Note that the lifetime of the DebugContext is longer than the debug server;
// It represents the debugger on the PowerShell process we're in,
// while a new debug server is spun up for every debugging session
_debugContext.IsDebugServerActive = false;
_psesHost.DebugContext.IsDebugServerActive = false;
_debugAdapterServer.Dispose();
_inputStream.Dispose();
_outputStream.Dispose();
Expand All @@ -126,6 +132,13 @@ public void Dispose()
public async Task WaitForShutdown()
{
await _serverStopped.Task.ConfigureAwait(false);

// If we started the host, we need to ensure any errors are marshalled back to us like this
if (_startedPses)
{
_psesHost.TriggerShutdown();
await _psesHost.Shutdown.ConfigureAwait(false);
}
}

#region Events
Expand Down
17 changes: 15 additions & 2 deletions src/PowerShellEditorServices/Server/PsesLanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.PowerShell.EditorServices.Hosting;
using Microsoft.PowerShell.EditorServices.Services;
using Microsoft.PowerShell.EditorServices.Services.Extension;
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
using Microsoft.PowerShell.EditorServices.Services.Template;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
using OmniSharp.Extensions.LanguageServer.Server;
Expand All @@ -32,6 +33,8 @@ internal class PsesLanguageServer
private readonly HostStartupInfo _hostDetails;
private readonly TaskCompletionSource<bool> _serverStart;

private PsesInternalHost _psesHost;

/// <summary>
/// Create a new language server instance.
/// </summary>
Expand Down Expand Up @@ -75,8 +78,12 @@ public async Task StartAsync()
options
.WithInput(_inputStream)
.WithOutput(_outputStream)
.WithServices(serviceCollection => serviceCollection
.AddPsesLanguageServices(_hostDetails)) // NOTE: This adds a lot of services!
.WithServices(serviceCollection =>
{

// NOTE: This adds a lot of services!
serviceCollection.AddPsesLanguageServices(_hostDetails);
})
.ConfigureLogging(builder => builder
.AddSerilog(Log.Logger) // TODO: Set dispose to true?
.AddLanguageProtocolLogging()
Expand Down Expand Up @@ -116,6 +123,8 @@ public async Task StartAsync()

IServiceProvider serviceProvider = languageServer.Services;

_psesHost = serviceProvider.GetService<PsesInternalHost>();

var workspaceService = serviceProvider.GetService<WorkspaceService>();

// Grab the workspace path from the parameters
Expand Down Expand Up @@ -150,6 +159,10 @@ public async Task WaitForShutdown()
Log.Logger.Debug("Shutting down OmniSharp Language Server");
await _serverStart.Task.ConfigureAwait(false);
await LanguageServer.WaitForExit.ConfigureAwait(false);

// Doing this means we're able to route through any exceptions experienced on the pipeline thread
_psesHost.TriggerShutdown();
await _psesHost.Shutdown.ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,16 @@ private static PSCommand BuildPSCommandFromArguments(string command, IReadOnlyLi

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

foreach (string arg in arguments)
{
sb.Append(' ');

if (ArgumentNeedsEscaping(arg))
if (StringEscaping.PowerShellArgumentNeedsEscaping(arg))
{
sb.Append('\'').Append(arg.Replace("'", "''")).Append('\'');
sb.Append(StringEscaping.SingleQuoteAndEscape(arg));
}
else
{
Expand All @@ -178,25 +177,5 @@ private static PSCommand BuildPSCommandFromArguments(string command, IReadOnlyLi

return new PSCommand().AddScript(sb.ToString());
}

private static bool ArgumentNeedsEscaping(string argument)
{
foreach (char c in argument)
{
switch (c)
{
case '\'':
case '"':
case '|':
case '&':
case ';':
case ':':
case char w when char.IsWhiteSpace(w):
return true;
}
}

return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ public void StepOver()
public void SetDebugResuming(DebuggerResumeAction debuggerResumeAction)
{
_psesHost.SetExit();
LastStopEventArgs.ResumeAction = debuggerResumeAction;

if (LastStopEventArgs is not null)
{
LastStopEventArgs.ResumeAction = debuggerResumeAction;
}

// We need to tell whatever is happening right now in the debug prompt to wrap up so we can continue
_psesHost.CancelCurrentTask();
}
Expand Down
Loading