public async Task InitializeAsync()
        {
            var factory = new LoggerFactory();

            _psesProcess = new PsesStdioProcess(factory, IsDebugAdapterTests);
            await _psesProcess.Start().ConfigureAwait(false);

            Console.WriteLine("PowerShell Editor Services Server started with PID {0}", ProcessId);
            // TIP: Add Breakpoint here and attach debugger using the PID from the above message
            Diagnostics     = new List <Diagnostic>();
            TelemetryEvents = new List <PsesTelemetryEvent>();
            DirectoryInfo testdir =
                Directory.CreateDirectory(Path.Combine(s_binDir, Path.GetRandomFileName()));

            PsesLanguageClient = LanguageClient.PreInit(options =>
            {
                options
                .WithInput(_psesProcess.OutputStream)
                .WithOutput(_psesProcess.InputStream)
                .WithRootUri(DocumentUri.FromFileSystemPath(testdir.FullName))
                .OnPublishDiagnostics(diagnosticParams => Diagnostics.AddRange(diagnosticParams.Diagnostics.Where(d => d != null)))
                .OnLogMessage(logMessageParams => Output?.WriteLine($"{logMessageParams.Type.ToString()}: {logMessageParams.Message}"))
                .OnTelemetryEvent(telemetryEventParams => TelemetryEvents.Add(
                                      new PsesTelemetryEvent
                {
                    EventName = (string)telemetryEventParams.ExtensionData["eventName"],
                    Data      = telemetryEventParams.ExtensionData["data"] as JObject
                }));

                // Enable all capabilities this this is for testing.
                // This will be a built in feature of the Omnisharp client at some point.
                var capabilityTypes = typeof(ICapability).Assembly.GetExportedTypes()
                                      .Where(z => typeof(ICapability).IsAssignableFrom(z) && z.IsClass && !z.IsAbstract);
                foreach (Type capabilityType in capabilityTypes)
                {
                    options.WithCapability(Activator.CreateInstance(capabilityType, Array.Empty <object>()) as ICapability);
                }
            });

            await PsesLanguageClient.Initialize(CancellationToken.None).ConfigureAwait(false);

            // Make sure Script Analysis is enabled because we'll need it in the tests.
            // This also makes sure the configuration is set to default values.
            PsesLanguageClient.Workspace.DidChangeConfiguration(
                new DidChangeConfigurationParams
            {
                Settings = JToken.FromObject(new LanguageServerSettingsWrapper
                {
                    Files      = new EditorFileSettings(),
                    Search     = new EditorSearchSettings(),
                    Powershell = new LanguageServerSettings()
                })
            });
        }
        public async override Task CustomInitializeAsync(
            ILoggerFactory factory,
            Stream inputStream,
            Stream outputStream)
        {
            Diagnostics = new List <Diagnostic>();
            DirectoryInfo testdir =
                Directory.CreateDirectory(Path.Combine(s_binDir, Path.GetRandomFileName()));

            PsesLanguageClient = LanguageClient.PreInit(options =>
            {
                options
                .WithInput(inputStream)
                .WithOutput(outputStream)
                .WithRootUri(DocumentUri.FromFileSystemPath(testdir.FullName))
                .OnPublishDiagnostics(diagnosticParams =>
                {
                    Diagnostics.AddRange(diagnosticParams.Diagnostics.Where(d => d != null));
                })
                .OnLogMessage(logMessageParams =>
                {
                    Output?.WriteLine($"{logMessageParams.Type.ToString()}: {logMessageParams.Message}");
                });

                // Enable all capabilities this this is for testing.
                // This will be a built in feature of the Omnisharp client at some point.
                var capabilityTypes = typeof(ICapability).Assembly.GetExportedTypes()
                                      .Where(z => typeof(ICapability).IsAssignableFrom(z))
                                      .Where(z => z.IsClass && !z.IsAbstract);
                foreach (Type capabilityType in capabilityTypes)
                {
                    options.WithCapability(Activator.CreateInstance(capabilityType, Array.Empty <object>()) as ICapability);
                }
            });

            await PsesLanguageClient.Initialize(CancellationToken.None);

            // Make sure Script Analysis is enabled because we'll need it in the tests.
            PsesLanguageClient.Workspace.DidChangeConfiguration(
                new DidChangeConfigurationParams
            {
                Settings = JObject.Parse(@"
{
    ""powershell"": {
        ""scriptAnalysis"": {
            ""enable"": true
        }
    }
}
")
            });
        }
        public override async Task DisposeAsync()
        {
            try
            {
                await PsesLanguageClient.Shutdown();

                await _psesProcess.Stop();

                PsesLanguageClient?.Dispose();
            }
            catch (ObjectDisposedException)
            {
                // Language client has a disposal bug in it
            }
        }