protected virtual async Task <(IDebugAdapterClient client, IDebugAdapterServer server)> Initialize( Action <DebugAdapterClientOptions> clientOptionsAction, Action <DebugAdapterServerOptions> serverOptionsAction ) { var clientPipe = new Pipe(TestOptions.DefaultPipeOptions); var serverPipe = new Pipe(TestOptions.DefaultPipeOptions); _client = DebugAdapterClient.Create( options => { options .WithLoggerFactory(TestOptions.ClientLoggerFactory) .ConfigureLogging( x => { x.SetMinimumLevel(LogLevel.Trace); x.Services.AddSingleton(TestOptions.ClientLoggerFactory); } ) .Services .AddTransient(typeof(IPipelineBehavior <,>), typeof(SettlePipeline <,>)) .AddSingleton(ClientEvents as IRequestSettler); ConfigureClientInputOutput(serverPipe.Reader, clientPipe.Writer, options); clientOptionsAction(options); } ); _server = DebugAdapterServer.Create( options => { options .WithLoggerFactory(TestOptions.ServerLoggerFactory) .ConfigureLogging( x => { x.SetMinimumLevel(LogLevel.Trace); x.Services.AddSingleton(TestOptions.ServerLoggerFactory); } ) .Services .AddTransient(typeof(IPipelineBehavior <,>), typeof(SettlePipeline <,>)) .AddSingleton(ServerEvents as IRequestSettler); ConfigureServerInputOutput(clientPipe.Reader, serverPipe.Writer, options); serverOptionsAction(options); } ); Disposable.Add(_client); Disposable.Add(_server); return(await Observable.FromAsync(_client.Initialize).ForkJoin( Observable.FromAsync(_server.Initialize), (a, b) => (_client, _server) ).ToTask(CancellationToken)); }
/// <summary> /// Start the debug server listening. /// </summary> /// <returns>A task that completes when the server is ready.</returns> public async Task StartAsync() { _debugAdapterServer = await DebugAdapterServer.From(options => { // 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. _psesHost = ServiceProvider.GetService <PsesInternalHost>(); _psesHost.DebugContext.IsDebugServerActive = true; options .WithInput(_inputStream) .WithOutput(_outputStream) .WithServices(serviceCollection => serviceCollection .AddLogging() .AddOptions() .AddPsesDebugServices(ServiceProvider, this)) // TODO: Consider replacing all WithHandler with AddSingleton .WithHandler <LaunchAndAttachHandler>() .WithHandler <DisconnectHandler>() .WithHandler <BreakpointHandlers>() .WithHandler <ConfigurationDoneHandler>() .WithHandler <ThreadsHandler>() .WithHandler <StackTraceHandler>() .WithHandler <ScopesHandler>() .WithHandler <VariablesHandler>() .WithHandler <ContinueHandler>() .WithHandler <NextHandler>() .WithHandler <PauseHandler>() .WithHandler <StepInHandler>() .WithHandler <StepOutHandler>() .WithHandler <SourceHandler>() .WithHandler <SetVariableHandler>() .WithHandler <DebugEvaluateHandler>() // 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 _psesHost.DebugContext.EnableDebugMode(); BreakpointService breakpointService = server.GetService <BreakpointService>(); // Clear any existing breakpoints before proceeding await breakpointService.RemoveAllBreakpointsAsync().ConfigureAwait(false); }) // The OnInitialized delegate gets run right before the server responds to the _Initialize_ request: // https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Initialize .OnInitialized((server, request, response, cancellationToken) => { response.SupportsConditionalBreakpoints = true; response.SupportsConfigurationDoneRequest = true; response.SupportsFunctionBreakpoints = true; response.SupportsHitConditionalBreakpoints = true; response.SupportsLogPoints = true; response.SupportsSetVariable = true; return(Task.CompletedTask); }); }).ConfigureAwait(false); }
/// <summary> /// Start the debug server listening. /// </summary> /// <returns>A task that completes when the server is ready.</returns> public async Task StartAsync() { _debugAdapterServer = await DebugAdapterServer.From(options => { // 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. _powerShellContextService = ServiceProvider.GetService <PowerShellContextService>(); _powerShellContextService.IsDebugServerActive = true; // Needed to make sure PSReadLine's static properties are initialized in the pipeline thread. // This is only needed for Temp sessions who only have a debug server. if (_usePSReadLine && _useTempSession && Interlocked.Exchange(ref s_hasRunPsrlStaticCtor, 1) == 0) { var command = new PSCommand() .AddCommand(s_lazyInvokeReadLineConstructorCmdletInfo.Value); // This must be run synchronously to ensure debugging works _powerShellContextService .ExecuteCommandAsync <object>(command, sendOutputToHost: true, sendErrorToHost: true) .GetAwaiter() .GetResult(); } options .WithInput(_inputStream) .WithOutput(_outputStream) .WithServices(serviceCollection => serviceCollection .AddLogging() .AddOptions() .AddPsesDebugServices(ServiceProvider, this, _useTempSession)) // TODO: Consider replacing all WithHandler with AddSingleton .WithHandler <LaunchAndAttachHandler>() .WithHandler <DisconnectHandler>() .WithHandler <BreakpointHandlers>() .WithHandler <ConfigurationDoneHandler>() .WithHandler <ThreadsHandler>() .WithHandler <StackTraceHandler>() .WithHandler <ScopesHandler>() .WithHandler <VariablesHandler>() .WithHandler <DebuggerActionHandlers>() .WithHandler <SourceHandler>() .WithHandler <SetVariableHandler>() .WithHandler <DebugEvaluateHandler>() // 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) => { var breakpointService = server.GetService <BreakpointService>(); // Clear any existing breakpoints before proceeding await breakpointService.RemoveAllBreakpointsAsync().ConfigureAwait(false); }) // The OnInitialized delegate gets run right before the server responds to the _Initialize_ request: // https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Initialize .OnInitialized((server, request, response, cancellationToken) => { response.SupportsConditionalBreakpoints = true; response.SupportsConfigurationDoneRequest = true; response.SupportsFunctionBreakpoints = true; response.SupportsHitConditionalBreakpoints = true; response.SupportsLogPoints = true; response.SupportsSetVariable = true; return(Task.CompletedTask); }); }).ConfigureAwait(false); }
public ActionDelegateData() { { var baseOptions = new DebugAdapterServerOptions().WithPipe(new Pipe()); void BaseDelegate(DebugAdapterServerOptions o) { o.WithPipe(new Pipe()); } var serviceProvider = new ServiceCollection().BuildServiceProvider(); Add(new ActionDelegate("create (server): options", () => DebugAdapterServer.Create(baseOptions))); Add(new ActionDelegate("create (server): options, serviceProvider", () => DebugAdapterServer.Create(baseOptions, serviceProvider))); Add(new ActionDelegate("create (server): action", () => DebugAdapterServer.Create(BaseDelegate))); Add(new ActionDelegate("create (server): action, serviceProvider", () => DebugAdapterServer.Create(BaseDelegate, serviceProvider))); Add(new ActionDelegate("from (server): options", () => DebugAdapterServer.From(baseOptions))); Add(new ActionDelegate("from (server): options, cancellationToken", () => DebugAdapterServer.From(baseOptions, CancellationToken.None))); Add( new ActionDelegate( "from (server): options, serviceProvider, cancellationToken", () => DebugAdapterServer.From(baseOptions, serviceProvider, CancellationToken.None) ) ); Add(new ActionDelegate("from (server): options, serviceProvider", () => DebugAdapterServer.From(baseOptions, serviceProvider))); Add(new ActionDelegate("from (server): action", () => DebugAdapterServer.From(BaseDelegate))); Add(new ActionDelegate("from (server): action, cancellationToken", () => DebugAdapterServer.From(BaseDelegate, CancellationToken.None))); Add( new ActionDelegate( "from (server): action, serviceProvider, cancellationToken", () => DebugAdapterServer.From(BaseDelegate, serviceProvider, CancellationToken.None) ) ); Add(new ActionDelegate("from (server): action, serviceProvider", () => DebugAdapterServer.From(BaseDelegate, serviceProvider))); } { var baseOptions = new DebugAdapterClientOptions().WithPipe(new Pipe()); void BaseDelegate(DebugAdapterClientOptions o) { o.WithPipe(new Pipe()); } var serviceProvider = new ServiceCollection().BuildServiceProvider(); Add(new ActionDelegate("create (client): options", () => DebugAdapterClient.Create(baseOptions))); Add(new ActionDelegate("create (client): options, serviceProvider", () => DebugAdapterClient.Create(baseOptions, serviceProvider))); Add(new ActionDelegate("create (client): action", () => DebugAdapterClient.Create(BaseDelegate))); Add(new ActionDelegate("create (client): action, serviceProvider", () => DebugAdapterClient.Create(BaseDelegate, serviceProvider))); Add(new ActionDelegate("from (client): options", () => DebugAdapterClient.From(baseOptions))); Add(new ActionDelegate("from (client): options, cancellationToken", () => DebugAdapterClient.From(baseOptions, CancellationToken.None))); Add( new ActionDelegate( "from (client): options, serviceProvider, cancellationToken", () => DebugAdapterClient.From(baseOptions, serviceProvider, CancellationToken.None) ) ); Add(new ActionDelegate("from (client): options, serviceProvider", () => DebugAdapterClient.From(baseOptions, serviceProvider))); Add(new ActionDelegate("from (client): action", () => DebugAdapterClient.From(BaseDelegate))); Add(new ActionDelegate("from (client): action, cancellationToken", () => DebugAdapterClient.From(BaseDelegate, CancellationToken.None))); Add( new ActionDelegate( "from (client): action, serviceProvider, cancellationToken", () => DebugAdapterClient.From(BaseDelegate, serviceProvider, CancellationToken.None) ) ); Add(new ActionDelegate("from (client): action, serviceProvider", () => DebugAdapterClient.From(BaseDelegate, serviceProvider))); } }