コード例 #1
0
        public static async Task <ILanguageClient> StartServerWithClientConnectionAsync(Action <LanguageClientOptions> onClientOptions, IResourceTypeProvider?resourceTypeProvider = null, IFileResolver?fileResolver = null)
        {
            resourceTypeProvider ??= TestResourceTypeProvider.Create();
            fileResolver ??= new InMemoryFileResolver(new Dictionary <Uri, string>());

            var clientPipe = new Pipe();
            var serverPipe = new Pipe();

            var server = new Server(
                serverPipe.Reader,
                clientPipe.Writer,
                new Server.CreationOptions
            {
                ResourceTypeProvider = resourceTypeProvider,
                FileResolver         = fileResolver,
            });
            var _ = server.RunAsync(CancellationToken.None); // do not wait on this async method, or you'll be waiting a long time!

            var client = LanguageClient.PreInit(options =>
            {
                options
                .WithInput(clientPipe.Reader)
                .WithOutput(serverPipe.Writer);

                onClientOptions(options);
            });
            await client.Initialize(CancellationToken.None);

            return(client);
        }
コード例 #2
0
        public static async Task <LanguageServerHelper> StartServerWithClientConnectionAsync(TestContext testContext, Action <LanguageClientOptions> onClientOptions, Server.CreationOptions?creationOptions = null)
        {
            var clientPipe = new Pipe();
            var serverPipe = new Pipe();

            creationOptions ??= new Server.CreationOptions();
            creationOptions = creationOptions with
            {
                SnippetsProvider       = creationOptions.SnippetsProvider ?? SnippetsProvider,
                FileResolver           = creationOptions.FileResolver ?? new InMemoryFileResolver(new Dictionary <Uri, string>()),
                ModuleRestoreScheduler = creationOptions.ModuleRestoreScheduler ?? BicepTestConstants.ModuleRestoreScheduler
            };

            var server = new Server(serverPipe.Reader, clientPipe.Writer, creationOptions);
            var _      = server.RunAsync(CancellationToken.None); // do not wait on this async method, or you'll be waiting a long time!

            var client = LanguageClient.PreInit(options =>
            {
                options
                .WithInput(clientPipe.Reader)
                .WithOutput(serverPipe.Writer)
                .OnInitialize((client, request, cancellationToken) => { testContext.WriteLine("Language client initializing."); return(Task.CompletedTask); })
                .OnInitialized((client, request, response, cancellationToken) => { testContext.WriteLine("Language client initialized."); return(Task.CompletedTask); })
                .OnStarted((client, cancellationToken) => { testContext.WriteLine("Language client started."); return(Task.CompletedTask); })
                .OnLogTrace(@params => testContext.WriteLine($"TRACE: {@params.Message} VERBOSE: {@params.Verbose}"))
                .OnLogMessage(@params => testContext.WriteLine($"{@params.Type}: {@params.Message}"));

                onClientOptions(options);
            });
            await client.Initialize(CancellationToken.None);

            testContext.WriteLine("LanguageClient initialize finished.");

            return(new(server, client));
        }
コード例 #3
0
        /// <summary>
        /// Create a <see cref="LanguageClient" /> connected to the test's <see cref="PipeServerProcess" />.
        /// </summary>
        /// <returns>
        /// The <see cref="LanguageClient" />.
        /// </returns>
        protected async Task<(ILanguageClient client, ILanguageServer server)> Initialize(
            Action<LanguageClientOptions> clientOptionsAction,
            Action<LanguageServerOptions> serverOptionsAction
        )
        {
            var clientPipe = new Pipe();
            var serverPipe = new Pipe();
            _client = LanguageClient.PreInit(
                options => {
                    options.WithServices(services => services.AddSingleton(LoggerFactory));
                    options.WithInput(serverPipe.Reader).WithOutput(clientPipe.Writer);
                    options.WithRootPath(WorkspaceRoot);
                    clientOptionsAction(options);
                }
            );
            Disposal.Add(_client);

            _server = Server.LanguageServer.PreInit(
                options => {
                    options.WithServices(services => services.AddSingleton(LoggerFactory));
                    options.WithInput(clientPipe.Reader).WithOutput(serverPipe.Writer);
                    serverOptionsAction(options);
                }
            );
            Disposal.Add(_server);

            await Task.WhenAll(
                _client.Initialize(CancellationToken),
                _server.Initialize(CancellationToken)
            );

            return ( _client, _server );
        }
コード例 #4
0
        protected virtual ILanguageClient CreateClient(Action <LanguageClientOptions>?clientOptionsAction = null)
        {
            _client = LanguageClient.PreInit(
                options => {
                var(reader, writer) = SetupServer();
                options
                .WithInput(reader)
                .WithOutput(writer)
                .WithLoggerFactory(TestOptions.ClientLoggerFactory)
                .WithAssemblies(TestOptions.Assemblies)
                .WithAssemblies(typeof(LanguageProtocolTestBase).Assembly, GetType().Assembly)
                .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);

            return(_client);
        }
コード例 #5
0
        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()
                })
            });
        }
コード例 #6
0
        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
        }
    }
}
")
            });
        }
コード例 #7
0
        protected internal virtual (ILanguageClient client, ILanguageServer server) Create(
            Action <LanguageClientOptions> clientOptionsAction,
            Action <LanguageServerOptions> serverOptionsAction
            )
        {
            var clientPipe = new Pipe(TestOptions.DefaultPipeOptions);
            var serverPipe = new Pipe(TestOptions.DefaultPipeOptions);

            _client = LanguageClient.PreInit(
                options => {
                options
                .WithLoggerFactory(TestOptions.ClientLoggerFactory)
                .WithAssemblies(TestOptions.Assemblies)
                .ConfigureLogging(x => x.SetMinimumLevel(LogLevel.Trace))
                .WithAssemblies(typeof(LanguageProtocolTestBase).Assembly, GetType().Assembly)
                .WithInputScheduler(options.InputScheduler)
                .WithOutputScheduler(options.OutputScheduler)
                .WithDefaultScheduler(options.DefaultScheduler)
                .Services
                .AddTransient(typeof(IPipelineBehavior <,>), typeof(SettlePipeline <,>))
                .AddSingleton(ClientEvents as IRequestSettler);
                ConfigureClientInputOutput(serverPipe.Reader, clientPipe.Writer, options);
                clientOptionsAction(options);
            }
                );

            _server = RealLanguageServer.PreInit(
                options => {
                options
                .WithLoggerFactory(TestOptions.ServerLoggerFactory)
                .WithAssemblies(TestOptions.Assemblies)
                .ConfigureLogging(x => x.SetMinimumLevel(LogLevel.Trace))
                .WithAssemblies(typeof(LanguageProtocolTestBase).Assembly, GetType().Assembly)
                .WithInputScheduler(options.InputScheduler)
                .WithOutputScheduler(options.OutputScheduler)
                .WithDefaultScheduler(options.DefaultScheduler)
                .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(_client, _server);
        }
コード例 #8
0
        protected virtual async Task <(ILanguageClient client, ILanguageServer server)> Initialize(
            Action <LanguageClientOptions> clientOptionsAction,
            Action <LanguageServerOptions> serverOptionsAction)
        {
            var clientPipe = new Pipe(TestOptions.DefaultPipeOptions);
            var serverPipe = new Pipe(TestOptions.DefaultPipeOptions);

            _client = LanguageClient.PreInit(options => {
                options
                .WithLoggerFactory(TestOptions.ClientLoggerFactory)
                .ConfigureLogging(x => {
                    x.Services.RemoveAll(typeof(ILoggerFactory));
                    x.Services.AddSingleton(TestOptions.ClientLoggerFactory);
                })
                .Services
                .AddTransient(typeof(IPipelineBehavior <,>), typeof(SettlePipeline <,>))
                .AddSingleton(ServerEvents as IRequestSettler);
                ConfigureClientInputOutput(serverPipe.Reader, clientPipe.Writer, options);
                clientOptionsAction(options);
            });

            _server = RealLanguageServer.PreInit(options => {
                options
                .WithLoggerFactory(TestOptions.ServerLoggerFactory)
                .ConfigureLogging(x => {
                    x.Services.RemoveAll(typeof(ILoggerFactory));
                    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 ObservableEx.ForkJoin(
                       Observable.FromAsync(_client.Initialize),
                       Observable.FromAsync(_server.Initialize),
                       (a, b) => (_client, _server)
                       ).ToTask(CancellationToken));
        }
コード例 #9
0
ファイル: InputOutputTests.cs プロジェクト: miqm/bicep
        private async Task <ILanguageClient> InitializeLanguageClient(Stream inputStream, Stream outputStream, MultipleMessageListener <PublishDiagnosticsParams> publishDiagnosticsListener, CancellationToken cancellationToken)
        {
            var client = LanguageClient.PreInit(options =>
            {
                options
                .WithInput(inputStream)
                .WithOutput(outputStream)
                .OnInitialize((client, request, cancellationToken) => { TestContext.WriteLine("Language client initializing."); return(Task.CompletedTask); })
                .OnInitialized((client, request, response, cancellationToken) => { TestContext.WriteLine("Language client initialized."); return(Task.CompletedTask); })
                .OnStarted((client, cancellationToken) => { TestContext.WriteLine("Language client started."); return(Task.CompletedTask); })
                .OnLogTrace(@params => TestContext.WriteLine($"TRACE: {@params.Message} VERBOSE: {@params.Verbose}"))
                .OnLogMessage(@params => TestContext.WriteLine($"{@params.Type}: {@params.Message}"))
                .OnPublishDiagnostics(x => publishDiagnosticsListener.AddMessage(x));
            });

            await client.Initialize(cancellationToken);

            return(client);
        }
コード例 #10
0
        public static async Task <ILanguageClient> StartServerWithClientConnection(Action <LanguageClientOptions> onClientOptions)
        {
            var clientPipe = new Pipe();
            var serverPipe = new Pipe();

            var server = new Server(serverPipe.Reader, clientPipe.Writer);
            var _      = server.Run(CancellationToken.None); // do not wait on this async method, or you'll be waiting a long time!

            var client = LanguageClient.PreInit(options =>
            {
                options
                .WithInput(clientPipe.Reader)
                .WithOutput(serverPipe.Writer);

                onClientOptions(options);
            });
            await client.Initialize(CancellationToken.None);

            return(client);
        }
コード例 #11
0
        public static async Task <ILanguageClient> StartServerWithClientConnectionAsync(Action <LanguageClientOptions> onClientOptions, Func <IResourceTypeProvider>?typeProviderBuilder = null)
        {
            typeProviderBuilder ??= TestResourceTypeProvider.Create;
            var clientPipe = new Pipe();
            var serverPipe = new Pipe();

            var server = new Server(serverPipe.Reader, clientPipe.Writer, typeProviderBuilder);
            var _      = server.RunAsync(CancellationToken.None); // do not wait on this async method, or you'll be waiting a long time!

            var client = LanguageClient.PreInit(options =>
            {
                options
                .WithInput(clientPipe.Reader)
                .WithOutput(serverPipe.Writer);

                onClientOptions(options);
            });
            await client.Initialize(CancellationToken.None);

            return(client);
        }
コード例 #12
0
        public static async Task <ILanguageClient> StartServerWithClientConnectionAsync(TestContext testContext, Action <LanguageClientOptions> onClientOptions, IResourceTypeProvider?resourceTypeProvider = null, IFileResolver?fileResolver = null)
        {
            resourceTypeProvider ??= TestTypeHelper.CreateEmptyProvider();
            fileResolver ??= new InMemoryFileResolver(new Dictionary <Uri, string>());

            var clientPipe = new Pipe();
            var serverPipe = new Pipe();

            var server = new Server(
                serverPipe.Reader,
                clientPipe.Writer,
                new Server.CreationOptions
            {
                ResourceTypeProvider = resourceTypeProvider,
                FileResolver         = fileResolver,
                SnippetsProvider     = SnippetsProvider
            });
            var _ = server.RunAsync(CancellationToken.None); // do not wait on this async method, or you'll be waiting a long time!

            var client = LanguageClient.PreInit(options =>
            {
                options
                .WithInput(clientPipe.Reader)
                .WithOutput(serverPipe.Writer)
                .OnInitialize((client, request, cancellationToken) => { testContext.WriteLine("Language client initializing."); return(Task.CompletedTask); })
                .OnInitialized((client, request, response, cancellationToken) => { testContext.WriteLine("Language client initialized."); return(Task.CompletedTask); })
                .OnStarted((client, cancellationToken) => { testContext.WriteLine("Language client started."); return(Task.CompletedTask); })
                .OnLogTrace(@params => testContext.WriteLine($"TRACE: {@params.Message} VERBOSE: {@params.Verbose}"))
                .OnLogMessage(@params => testContext.WriteLine($"{@params.Type}: {@params.Message}"));

                onClientOptions(options);
            });
            await client.Initialize(CancellationToken.None);

            testContext.WriteLine("LanguageClient initialize finished.");

            return(client);
        }
コード例 #13
0
        protected virtual async Task <ILanguageClient> InitializeClient(Action <LanguageClientOptions> clientOptionsAction = null)
        {
            _client = LanguageClient.PreInit(options => {
                var(reader, writer) = SetupServer();
                options
                .WithInput(reader)
                .WithOutput(writer)
                .ConfigureLogging(x => {
                    x.SetMinimumLevel(LogLevel.Trace);
                    x.Services.AddSingleton(TestOptions.ClientLoggerFactory);
                })
                .Services
                .AddTransient(typeof(IPipelineBehavior <,>), typeof(SettlePipeline <,>))
                .AddSingleton(ServerEvents as IRequestSettler);
                clientOptionsAction?.Invoke(options);
            });

            Disposable.Add(_client);

            await _client.Initialize(CancellationToken);

            return(_client);
        }