Ejemplo n.º 1
0
        protected virtual async Task <IDebugAdapterClient> InitializeClient(Action <DebugAdapterClientOptions>?clientOptionsAction = null)
        {
            _client = DebugAdapterClient.Create(
                options => {
                var(reader, writer) = SetupServer();
                options
                .WithInput(reader)
                .WithOutput(writer)
                .WithLoggerFactory(TestOptions.ClientLoggerFactory)
                .ConfigureLogging(
                    x => {
                    x.SetMinimumLevel(LogLevel.Trace);
                }
                    )
                .WithInputScheduler(options.InputScheduler)
                .WithOutputScheduler(options.OutputScheduler)
                .WithDefaultScheduler(options.DefaultScheduler)
                .Services
                .AddTransient(typeof(IPipelineBehavior <,>), typeof(SettlePipeline <,>))
                .AddSingleton(Events as IRequestSettler);
                clientOptionsAction?.Invoke(options);
            }
                );

            Disposable.Add(_client);

            await _client.Initialize(CancellationToken).ConfigureAwait(false);

            return(_client);
        }
        public async Task InitializeAsync()
        {
            string testLogPath =
                Path.Combine(
                    AppDomain.CurrentDomain.BaseDirectory,
                    "logs",
                    this.GetType().Name,
                    Guid.NewGuid().ToString().Substring(0, 8) + ".log");

            System.Console.WriteLine("        Output log at path: {0}", testLogPath);

            Tuple <int, int> portNumbers =
                await this.LaunchService(
                    testLogPath,
                    waitForDebugger : false);

            //waitForDebugger: true);

            this.protocolClient         =
                this.debugAdapterClient =
                    new DebugAdapterClient(
                        new TcpSocketClientChannel(
                            portNumbers.Item2));

            await this.debugAdapterClient.Start();

            // HACK: Insert a short delay to give the MessageDispatcher time to
            // start up.  This will have to be fixed soon with a larger refactoring
            // to improve the client/server model.  Tracking this here:
            // https://github.com/PowerShell/PowerShellEditorServices/issues/245
            await Task.Delay(1750);
        }
        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));
        }
        public async Task InitializeAsync()
        {
            var factory = new LoggerFactory();

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

            var initialized = new TaskCompletionSource <bool>();

            PsesDebugAdapterClient = DebugAdapterClient.Create(options =>
            {
                options
                .WithInput(_psesProcess.OutputStream)
                .WithOutput(_psesProcess.InputStream)
                // The OnStarted delegate gets run when we receive the _Initialized_ event from the server:
                // https://microsoft.github.io/debug-adapter-protocol/specification#Events_Initialized
                .OnStarted((client, token) => {
                    Started.SetResult(true);
                    return(Task.CompletedTask);
                })
                // The OnInitialized delegate gets run when we first receive the _Initialize_ response:
                // https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Initialize
                .OnInitialized((client, request, response, token) => {
                    initialized.SetResult(true);
                    return(Task.CompletedTask);
                });
            });

            // PSES follows the following flow:
            // Receive a Initialize request
            // Run Initialize handler and send response back
            // Receive a Launch/Attach request
            // Run Launch/Attach handler and send response back
            // PSES sends the initialized event at the end of the Launch/Attach handler

            // The way that the Omnisharp client works is that this Initialize method doesn't return until
            // after OnStarted is run... which only happens when Initialized is received from the server.
            // so if we would await this task, it would deadlock.
            // To get around this, we run the Initialize() without await but use a `TaskCompletionSource<bool>`
            // that gets completed when we receive the response to Initialize
            // This tells us that we are ready to send messages to PSES... but are not stuck waiting for
            // Initialized.
            PsesDebugAdapterClient.Initialize(CancellationToken.None).ConfigureAwait(false);
            await initialized.Task.ConfigureAwait(false);
        }
Ejemplo n.º 5
0
        public static async Task LaunchScript(this DebugAdapterClient debugAdapterClient, string filePath, TaskCompletionSource <object> started)
        {
            LaunchResponse launchResponse = await debugAdapterClient.RequestLaunch(new PsesLaunchRequestArguments
            {
                NoDebug = false,
                Script  = filePath,
                Cwd     = "",
                CreateTemporaryIntegratedConsole = false,
            }).ConfigureAwait(false);

            if (launchResponse == null)
            {
                throw new Exception("Launch response was null.");
            }

            // This will check to see if we received the Initialized event from the server.
            await Task.Run(
                async() => await started.Task.ConfigureAwait(false),
                new CancellationTokenSource(2000).Token).ConfigureAwait(false);
        }
        public async Task InitializeAsync()
        {
            string testLogPath =
                Path.Combine(
#if CoreCLR
                    AppContext.BaseDirectory,
#else
                    AppDomain.CurrentDomain.BaseDirectory,
#endif
                    "logs",
                    this.GetType().Name,
                    Guid.NewGuid().ToString().Substring(0, 8));

            this.logger =
                new FileLogger(
                    testLogPath + "-client.log",
                    LogLevel.Verbose);

            testLogPath += "-server.log";
            System.Console.WriteLine("        Output log at path: {0}", testLogPath);

            Tuple <int, int> portNumbers =
                await this.LaunchService(
                    testLogPath,
                    waitForDebugger : false);

            //waitForDebugger: true);

            this.debugAdapterClient =
                new DebugAdapterClient(
                    await TcpSocketClientChannel.Connect(
                        portNumbers.Item2,
                        MessageProtocolType.DebugAdapter,
                        this.logger),
                    this.logger);

            this.messageSender   = this.debugAdapterClient;
            this.messageHandlers = this.debugAdapterClient;

            await this.debugAdapterClient.Start();
        }
Ejemplo n.º 7
0
        public Task InitializeAsync()
        {
            string testLogPath =
                Path.Combine(
                    AppDomain.CurrentDomain.BaseDirectory,
                    "logs",
                    this.GetType().Name,
                    Guid.NewGuid().ToString().Substring(0, 8) + ".log");

            System.Console.WriteLine("        Output log at path: {0}", testLogPath);

            this.protocolClient         =
                this.debugAdapterClient =
                    new DebugAdapterClient(
                        new StdioClientChannel(
                            "Microsoft.PowerShell.EditorServices.Host.exe",
                            "/debugAdapter",
                            "/logPath:\"" + testLogPath + "\"",
                            "/logLevel:Verbose"));

            return(this.debugAdapterClient.Start());
        }
        public async Task InitializeAsync()
        {
            string testLogPath =
                Path.Combine(
                    AppContext.BaseDirectory,
                    "logs",
                    this.GetType().Name,
                    Guid.NewGuid().ToString().Substring(0, 8));

            this.logger = Logging.CreateLogger()
                          .LogLevel(LogLevel.Verbose)
                          .AddLogFile(testLogPath + "-client.log")
                          .Build();

            testLogPath += "-server.log";
            System.Console.WriteLine("        Output log at path: {0}", testLogPath);

            Tuple <string, string> pipeNames =
                await this.LaunchService(
                    testLogPath,
                    waitForDebugger : false);

            //waitForDebugger: true);

            this.debugAdapterClient =
                new DebugAdapterClient(
                    await NamedPipeClientChannel.ConnectAsync(
                        pipeNames.Item2,
                        MessageProtocolType.DebugAdapter,
                        this.logger),
                    this.logger);

            this.messageSender   = this.debugAdapterClient;
            this.messageHandlers = this.debugAdapterClient;

            await this.debugAdapterClient.StartAsync();
        }
 public DebugAdapterProtocolMessageTests(DAPTestsFixture data)
 {
     _dapTestsFixture       = data;
     PsesDebugAdapterClient = data.PsesDebugAdapterClient;
 }
            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)));
                }
            }