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

Remove ps72 #2199

Closed
wants to merge 8 commits into from
Closed
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
1 change: 0 additions & 1 deletion .pipelines/PowerShellEditorServices-Official.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ extends:
**/Nerdbank.Streams.dll;
**/Newtonsoft.Json.dll;
**/OmniSharp.Extensions*.dll;
**/Serilog*.dll;
**/System.Reactive.dll;
- task: ArchiveFiles@2
displayName: Zip signed artifacts
Expand Down
7 changes: 2 additions & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<ItemGroup>
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
<PackageVersion Include="Microsoft.Extensions.FileSystemGlobbing" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="Microsoft.PowerShell.5.ReferenceAssemblies" Version="1.1.0" />
<PackageVersion Include="Microsoft.PowerShell.SDK" Version="7.4.6" />
Expand All @@ -12,10 +13,6 @@
<PackageVersion Include="OmniSharp.Extensions.LanguageClient" Version="0.19.9" />
<PackageVersion Include="OmniSharp.Extensions.LanguageServer" Version="0.19.9" />
<PackageVersion Include="PowerShellStandard.Library" Version="5.1.1" />
<PackageVersion Include="Serilog" Version="4.0.0" />
<PackageVersion Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageVersion Include="Serilog.Sinks.Async" Version="2.0.0" />
<PackageVersion Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageVersion Include="System.IO.Pipes.AccessControl" Version="5.0.0" />
<PackageVersion Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
<PackageVersion Include="System.Security.Principal" Version="4.3.0" />
Expand Down
427 changes: 0 additions & 427 deletions NOTICE.txt

Large diffs are not rendered by default.

12 changes: 3 additions & 9 deletions PowerShellEditorServices.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ $script:BuildInfoPath = "src/PowerShellEditorServices.Hosting/BuildInfo.cs"

$script:NetFramework = @{
PS51 = 'net462'
PS72 = 'net6.0'
PS74 = 'net8.0'
Standard = 'netstandard2.0'
}

$script:HostCoreOutput = "src/PowerShellEditorServices.Hosting/bin/$Configuration/$($script:NetFramework.PS72)/publish"
$script:HostCoreOutput = "src/PowerShellEditorServices.Hosting/bin/$Configuration/$($script:NetFramework.PS74)/publish"
$script:HostDeskOutput = "src/PowerShellEditorServices.Hosting/bin/$Configuration/$($script:NetFramework.PS51)/publish"
$script:PsesOutput = "src/PowerShellEditorServices/bin/$Configuration/$($script:NetFramework.Standard)/publish"

Expand Down Expand Up @@ -128,7 +127,7 @@ task RestorePsesModules -If (-not (Test-Path "module/PSReadLine") -or -not (Test
Task Build FindDotNet, CreateBuildInfo, RestorePsesModules, {
Write-Build DarkGreen "Building PowerShellEditorServices"
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs ./src/PowerShellEditorServices/PowerShellEditorServices.csproj -f $script:NetFramework.Standard }
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs ./src/PowerShellEditorServices.Hosting/PowerShellEditorServices.Hosting.csproj -f $script:NetFramework.PS72 }
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs ./src/PowerShellEditorServices.Hosting/PowerShellEditorServices.Hosting.csproj -f $script:NetFramework.PS74 }

if (-not $script:IsNix) {
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs ./src/PowerShellEditorServices.Hosting/PowerShellEditorServices.Hosting.csproj -f $script:NetFramework.PS51 }
Expand Down Expand Up @@ -201,11 +200,6 @@ Task TestPS74 Build, SetupHelpForTests, {
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS74 }
}

Task TestPS72 Build, SetupHelpForTests, {
Set-Location ./test/PowerShellEditorServices.Test/
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS72 }
}

Task TestPS51 -If (-not $script:IsNix) Build, SetupHelpForTests, {
Set-Location ./test/PowerShellEditorServices.Test/
# TODO: See https://github.com/dotnet/sdk/issues/18353 for x64 test host
Expand Down Expand Up @@ -299,7 +293,7 @@ Task TestE2EPowerShellCLM -If (-not $script:IsNix) Build, SetupHelpForTests, {
}
}

Task Test TestPS72, TestPS74, TestE2EPwsh, TestPS51, TestE2EPowerShell
Task Test TestPS74, TestE2EPwsh, TestPS51, TestE2EPowerShell

Task TestFull Test, TestE2EDaily, TestE2EPwshCLM, TestE2EPowerShellCLM

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ protected override void BeginProcessing()
protected override void EndProcessing()
{
_logger.Log(PsesLogLevel.Diagnostic, "Beginning EndProcessing block");

try
{
// First try to remove PSReadLine to decomplicate startup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ namespace Microsoft.PowerShell.EditorServices.Hosting
/// User-facing log level for editor services configuration.
/// </summary>
/// <remarks>
/// The underlying values of this enum attempt to align to both
/// <see cref="Microsoft.Extensions.Logging.LogLevel" /> and
/// <see cref="Serilog.Events.LogEventLevel" />.
/// The underlying values of this enum attempt to align to
/// <see cref="Microsoft.Extensions.Logging.LogLevel" />
/// </remarks>
public enum PsesLogLevel
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public EditorServicesRunner(
_config = config;
_sessionFileWriter = sessionFileWriter;
// NOTE: This factory helps to isolate `Microsoft.Extensions.Logging/DependencyInjection`.
_serverFactory = EditorServicesServerFactory.Create(_config.LogPath, (int)_config.LogLevel, logger);
_serverFactory = new(logger);
_alreadySubscribedDebug = false;
_loggersToUnsubscribe = loggersToUnsubscribe;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), PowerShellEditorServices.Common.props))\PowerShellEditorServices.Common.props" />

<PropertyGroup>
<TargetFrameworks>net6.0;net462</TargetFrameworks>
<TargetFrameworks>net8.0;net462</TargetFrameworks>
<AssemblyName>Microsoft.PowerShell.EditorServices.Hosting</AssemblyName>
</PropertyGroup>

Expand Down
91 changes: 14 additions & 77 deletions src/PowerShellEditorServices/Hosting/EditorServicesServerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,30 @@
// Licensed under the MIT License.

using System;
using System.Diagnostics;
using System.IO;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.PowerShell.EditorServices.Logging;
using Microsoft.PowerShell.EditorServices.Server;
using Serilog;
using Serilog.Events;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
using Microsoft.PowerShell.EditorServices.Services.Extension;

#if DEBUG
using Serilog.Debugging;
#endif
// The HostLogger type isn't directly referenced from this assembly, however it uses a common IObservable interface and this alias helps make it more clear the purpose. We can use Microsoft.Extensions.Logging from this point because the ALC should be loaded, but we need to only expose the IObservable to the Hosting assembly so it doesn't try to load MEL before the ALC is ready.
using HostLogger = System.IObservable<(int logLevel, string message)>;

namespace Microsoft.PowerShell.EditorServices.Hosting
{
/// <summary>
/// Factory class for hiding dependencies of Editor Services.
/// Factory for creating the LSP server and debug server instances.
/// </summary>
/// <remarks>
/// Dependency injection and logging are wrapped by factory methods on this class so that the
/// host assembly can construct the LSP and debug servers without directly depending on <see
/// cref="Microsoft.Extensions.Logging"/> and <see
/// cref="Microsoft.Extensions.DependencyInjection"/>.
/// </remarks>
internal sealed class EditorServicesServerFactory : IDisposable
{
private readonly HostLogger _hostLogger;

/// <summary>
/// Create a new Editor Services factory. This method will instantiate logging.
/// Creates a loggerfactory for this instance
/// </summary>
/// <remarks>
/// <para>
/// This can only be called once because it sets global state (the logger) and that call is
/// in <see cref="Hosting.EditorServicesRunner" />.
/// </para>
/// <para>
/// TODO: Why is this a static function wrapping a constructor instead of just a
/// constructor? In the end it returns an instance (albeit a "singleton").
/// </para>
/// </remarks>
/// <param name="logDirectoryPath">The path of the log file to use.</param>
/// <param name="minimumLogLevel">The minimum log level to use.</param>
/// <param name="hostLogger">The host logger?</param>
public static EditorServicesServerFactory Create(string logDirectoryPath, int minimumLogLevel, IObservable<(int logLevel, string message)> hostLogger)
{
// NOTE: Ignore the suggestion to use Environment.ProcessId as it doesn't work for
// .NET 4.6.2 (for Windows PowerShell), and this won't be caught in CI.
int currentPID = Process.GetCurrentProcess().Id;
string logPath = Path.Combine(logDirectoryPath, $"PowerShellEditorServices-{currentPID}.log");
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.Async(config => config.File(logPath))
.MinimumLevel.Is((LogEventLevel)minimumLogLevel)
.CreateLogger();

#if DEBUG
SelfLog.Enable(msg => Debug.WriteLine(msg));
#endif

LoggerFactory loggerFactory = new();
loggerFactory.AddSerilog();

// Hook up logging from the host so that its recorded in the log file
hostLogger.Subscribe(new HostLoggerAdapter(loggerFactory));

return new EditorServicesServerFactory(loggerFactory);
}

// TODO: Can we somehow refactor this member so the language and debug servers can be
// instantiated using their constructors instead of tying them to this factory with `Create`
// methods?
private readonly ILoggerFactory _loggerFactory;

private EditorServicesServerFactory(ILoggerFactory loggerFactory) => _loggerFactory = loggerFactory;
/// <param name="hostLogger">The hostLogger that will be provided to the language services for logging handoff</param>
internal EditorServicesServerFactory(HostLogger hostLogger) => _hostLogger = hostLogger;

/// <summary>
/// Create the LSP server.
Expand All @@ -92,7 +41,7 @@ public static EditorServicesServerFactory Create(string logDirectoryPath, int mi
public PsesLanguageServer CreateLanguageServer(
Stream inputStream,
Stream outputStream,
HostStartupInfo hostStartupInfo) => new(_loggerFactory, inputStream, outputStream, hostStartupInfo);
HostStartupInfo hostStartupInfo) => new(_hostLogger, inputStream, outputStream, hostStartupInfo);

/// <summary>
/// Create the debug server given a language server instance.
Expand All @@ -110,7 +59,7 @@ public PsesDebugServer CreateDebugServerWithLanguageServer(
PsesLanguageServer languageServer)
{
return new PsesDebugServer(
_loggerFactory,
_hostLogger,
inputStream,
outputStream,
languageServer.LanguageServer.Services);
Expand All @@ -132,7 +81,7 @@ public PsesDebugServer RecreateDebugServer(
PsesDebugServer debugServer)
{
return new PsesDebugServer(
_loggerFactory,
_hostLogger,
inputStream,
outputStream,
debugServer.ServiceProvider);
Expand All @@ -153,7 +102,6 @@ public PsesDebugServer CreateDebugServerForTempSession(
ServiceProvider serviceProvider = new ServiceCollection()
.AddLogging(builder => builder
.ClearProviders()
.AddSerilog()
.SetMinimumLevel(LogLevel.Trace)) // TODO: Why randomly set to trace?
.AddSingleton<ILanguageServerFacade>(_ => null)
// TODO: Why add these for a debug server?!
Expand All @@ -171,25 +119,14 @@ public PsesDebugServer CreateDebugServerForTempSession(
serviceProvider.GetService<ExtensionService>();

return new PsesDebugServer(
_loggerFactory,
_hostLogger,
inputStream,
outputStream,
serviceProvider,
isTemp: true);
}

/// <summary>
/// TODO: This class probably should not be <see cref="IDisposable"/> as the primary
/// intention of that interface is to provide cleanup of unmanaged resources, which the
/// logger certainly is not. Nor is this class used with a <see langword="using"/>. Instead,
/// this class should call <see cref="Log.CloseAndFlush()"/> in a finalizer. This
/// could potentially even be done with <see
/// cref="SerilogLoggerFactoryExtensions.AddSerilog"</> by passing <c>dispose=true</c>.
/// </summary>
public void Dispose()
{
Log.CloseAndFlush();
_loggerFactory.Dispose();
}
// TODO: Clean up host logger? Shouldn't matter since we start a new process after shutdown.
public void Dispose() { }
}
}
5 changes: 2 additions & 3 deletions src/PowerShellEditorServices/Hosting/HostStartupInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ public sealed class HostStartupInfo
/// The minimum log level of log events to be logged.
/// </summary>
/// <remarks>
/// This is cast to all of <see cref="Hosting.PsesLogLevel"/>, <see
/// cref="Microsoft.Extensions.Logging.LogLevel"/>, and <see
/// cref="Serilog.Events.LogEventLevel"/>, hence it is an <c>int</c>.
/// This primitive maps to <see cref="Hosting.PsesLogLevel"/> and <see
/// cref="Microsoft.Extensions.Logging.LogLevel"/>
/// </remarks>
public int LogLevel { get; }

Expand Down
13 changes: 3 additions & 10 deletions src/PowerShellEditorServices/Logging/HostLoggerAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,16 @@ namespace Microsoft.PowerShell.EditorServices.Logging
/// <summary>
/// Adapter class to allow logging events sent by the host to be recorded by PSES' logging infrastructure.
/// </summary>
internal class HostLoggerAdapter : IObserver<(int logLevel, string message)>
internal class HostLoggerAdapter(ILogger logger) : IObserver<(int logLevel, string message)>
{
private readonly ILogger _logger;
public void OnError(Exception error) => logger.LogError(error, "Error in host logger");

/// <summary>
/// Create a new host logger adapter.
/// </summary>
/// <param name="loggerFactory">Factory to create logger instances with.</param>
public HostLoggerAdapter(ILoggerFactory loggerFactory) => _logger = loggerFactory.CreateLogger("HostLogs");
public void OnNext((int logLevel, string message) value) => logger.Log((LogLevel)value.logLevel, value.message);

public void OnCompleted()
{
// Nothing to do; we simply don't send more log messages
}

public void OnError(Exception error) => _logger.LogError(error, "Error in host logger");

public void OnNext((int logLevel, string message) value) => _logger.Log((LogLevel)value.logLevel, value.message);
}
}
4 changes: 0 additions & 4 deletions src/PowerShellEditorServices/PowerShellEditorServices.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="PowerShellStandard.Library" />
<PackageReference Include="Serilog" />
<PackageReference Include="Serilog.Extensions.Logging" />
<PackageReference Include="Serilog.Sinks.Async" />
<PackageReference Include="Serilog.Sinks.File" />
<PackageReference Include="System.IO.Pipes.AccessControl" />
<PackageReference Include="System.Security.Principal" />
<PackageReference Include="System.Security.Principal.Windows" />
Expand Down
13 changes: 7 additions & 6 deletions src/PowerShellEditorServices/Server/PsesDebugServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.PowerShell.EditorServices.Handlers;
using Microsoft.PowerShell.EditorServices.Services;
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
using OmniSharp.Extensions.DebugAdapter.Server;
using OmniSharp.Extensions.LanguageServer.Server;

// See EditorServicesServerFactory.cs for the explanation of this alias.
using HostLogger = System.IObservable<(int logLevel, string message)>;

namespace Microsoft.PowerShell.EditorServices.Server
{
/// <summary>
Expand All @@ -26,16 +28,17 @@ internal class PsesDebugServer : IDisposable
private PsesInternalHost _psesHost;
private bool _startedPses;
private readonly bool _isTemp;
protected readonly ILoggerFactory _loggerFactory;
// FIXME: This was never actually used in the debug server. Since we never have a debug server without an LSP, we could probably remove this and either reuse the MEL from the LSP, or create a new one here. It is probably best to only use this for exceptions that we can't reasonably send via the DAP protocol, which should only be anything before the initialize request.
protected readonly HostLogger _hostLogger;

public PsesDebugServer(
ILoggerFactory factory,
HostLogger hostLogger,
Stream inputStream,
Stream outputStream,
IServiceProvider serviceProvider,
bool isTemp = false)
{
_loggerFactory = factory;
_hostLogger = hostLogger;
_inputStream = inputStream;
_outputStream = outputStream;
ServiceProvider = serviceProvider;
Expand Down Expand Up @@ -63,7 +66,6 @@ public async Task StartAsync()
.WithOutput(_outputStream)
.WithServices(serviceCollection =>
serviceCollection
.AddLogging()
.AddOptions()
.AddPsesDebugServices(ServiceProvider, this))
// TODO: Consider replacing all WithHandler with AddSingleton
Expand Down Expand Up @@ -130,7 +132,6 @@ public void Dispose()
_debugAdapterServer?.Dispose();
_inputStream.Dispose();
_outputStream.Dispose();
_loggerFactory.Dispose();
_serverStopped.SetResult(true);
// TODO: If the debugger has stopped, should we clear the breakpoints?
}
Expand Down
Loading