/// <summary>
        ///     The main asynchronous program entry-point.
        /// </summary>
        /// <returns>
        ///     A <see cref="Task"/> representing program operation.
        /// </returns>
        static async Task AsyncMain()
        {
            Log.Information("Initialising language server...");

            LanguageServer languageServer = new LanguageServer(
                input: Console.OpenStandardInput(2048),
                output: Console.OpenStandardOutput(2048),
                loggerFactory: new MSLogging.LoggerFactory().AddSerilog(Log.Logger.ForContext <LanguageServer>())
                );

            languageServer.AddHandler(
                new ConfigurationHandler()
                );
            languageServer.AddHandler(
                new DummyHandler(languageServer)
                );

            Log.Information("Starting language server...");
            var initTask = languageServer.Initialize();

            languageServer.Shutdown += shutdownRequested =>
            {
                Log.Information("Language server shutdown (ShutDownRequested={ShutDownRequested}).", shutdownRequested);
            };

            Log.Information("Language server initialised; waiting for shutdown.");

            await initTask;

            Log.Information("Waiting for shutdown...");

            await languageServer.WasShutDown;
        }
        /// <summary>
        ///     Run a language server over the specified streams.
        /// </summary>
        /// <param name="input">
        ///     The input stream.
        /// </param>
        /// <param name="output">
        ///     The output stream.
        /// </param>
        /// <returns>
        ///     A <see cref="Task"/> representing the operation.
        /// </returns>
        static async Task RunLanguageServer(Stream input, Stream output)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            Log.Information("Initialising language server...");

            LanguageServer languageServer = new LanguageServer(input, output,
                                                               loggerFactory: new MSLogging.LoggerFactory().AddSerilog(Log.Logger.ForContext <LanguageServer>())
                                                               );

            languageServer.AddHandler(
                new ConfigurationHandler()
                );
            languageServer.AddHandler(
                new HoverHandler()
                );
            languageServer.AddHandler(
                new DummyHandler(languageServer)
                );

            languageServer.OnInitialize(parameters =>
            {
                JToken options = parameters.InitializationOptions as JToken;
                Log.Information("Server received initialisation options: {Options}", options?.ToString(Newtonsoft.Json.Formatting.None));

                return(Task.CompletedTask);
            });

            Log.Information("Starting language server...");
            languageServer.Shutdown += shutdownRequested =>
            {
                Log.Information("Language server shutdown (ShutDownRequested={ShutDownRequested}).", shutdownRequested);
            };
            languageServer.Exit += exitCode =>
            {
                Log.Information("Language server exit (ExitCode={ExitCode}).", exitCode);
            };

            await languageServer.Initialize();

            Log.Information("Language server has shut down.");
        }
        static async Task MainAsync(string[] args)
        {
            /*while (!System.Diagnostics.Debugger.IsAttached)
             * {
             *  await Task.Delay(100);
             * }*/


            var server = new LanguageServer(
                Console.OpenStandardInput(),
                Console.OpenStandardOutput(),
                new LoggerFactory());
            var manager = new GherkinManager();

            server.OnInitialize(request =>
            {
                manager.HandleStartup(UrlSanitizer.SanitizeUrl(request.RootUri.OriginalString));
                return(Task.CompletedTask);
            });

            server.AddHandler(new GherkinDocumentHandler(server, manager));
            //server.AddHandler(new CsharpDocumentHandler(server, manager));
            await server.Initialize();

            await server.WaitForExit;
        }
Beispiel #4
0
 public static LanguageServer AddHandlers(this LanguageServer langaugeServer, IEnumerable <IJsonRpcHandler> handlers)
 {
     foreach (var handler in handlers)
     {
         langaugeServer.AddHandler(handler);
     }
     return(langaugeServer);
 }
Beispiel #5
0
        static async Task MainAsync(string[] args)
        {
            //while (!System.Diagnostics.Debugger.IsAttached)
            //{
            //    await Task.Delay(100);
            //}

            var server = new LanguageServer(Console.OpenStandardInput(), Console.OpenStandardOutput(), new LoggerFactory());

            server.AddHandler(new TextDocumentHandler(server));

            await server.Initialize();

            await server.WasShutDown;
        }
Beispiel #6
0
        /// <summary>
        ///     Configure language server components.
        /// </summary>
        /// <param name="builder">
        ///     The container builder to configure.
        /// </param>
        protected override void Load(ContainerBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.RegisterInstance(Configuration).AsSelf();

            builder
            .Register(componentContext => new LanguageServer(
                          input: Console.OpenStandardInput(),
                          output: Console.OpenStandardOutput(),
                          loggerFactory: componentContext.Resolve <MSLogging.ILoggerFactory>()
                          ))
            .AsSelf()
            .As <ILanguageServer>()
            .SingleInstance()
            .OnActivated(activated =>
            {
                LanguageServer languageServer = activated.Instance;

                // Register configuration handler (which is not a Handler).
                var configurationHandler = activated.Context.Resolve <ConfigurationHandler>();
                languageServer.AddHandler(configurationHandler);

                void configureServerLogLevel()
                {
                    if (configurationHandler.Configuration.Logging.Level < LogEventLevel.Verbose)
                    {
                        languageServer.MinimumLogLevel = MSLogging.LogLevel.Warning;
                    }
                }

                languageServer.OnInitialize(initializationParameters =>
                {
                    configurationHandler.Configuration.UpdateFrom(initializationParameters);
                    configureServerLogLevel();

                    // Handle subsequent logging configuration changes.
                    configurationHandler.ConfigurationChanged += (sender, args) => configureServerLogLevel();

                    return(Task.CompletedTask);
                });

                // Register all other handlers.
                var handlers = activated.Context.Resolve <IEnumerable <Handler> >();
                foreach (Handler handler in handlers)
                {
                    languageServer.AddHandler(handler);
                }
            });

            builder.RegisterType <LspDiagnosticsPublisher>()
            .As <IPublishDiagnostics>()
            .InstancePerDependency();

            builder.RegisterType <ConfigurationHandler>()
            .AsSelf()
            .SingleInstance();

            builder.RegisterType <Documents.Workspace>()
            .AsSelf()
            .SingleInstance()
            .OnActivated(activated =>
            {
                Documents.Workspace workspace = activated.Instance;
                workspace.RestoreTaskMetadataCache();
            });

            builder
            .RegisterTypes(
                typeof(ConfigurationHandler),
                typeof(DocumentSyncHandler),
                typeof(DocumentSymbolHandler),
                typeof(DefinitionHandler),
                typeof(HoverHandler)
                )
            .AsSelf()
            .As <Handler>()
            .SingleInstance();

            builder.RegisterType <CompletionHandler>()
            .AsSelf().As <Handler>()
            .SingleInstance()
            .OnActivated(activated =>
            {
                CompletionHandler completionHandler = activated.Instance;

                completionHandler.Providers.AddRange(
                    activated.Context.Resolve <IEnumerable <ICompletionProvider> >()
                    );
            });

            Type completionProviderType = typeof(CompletionProvider);

            builder.RegisterAssemblyTypes(ThisAssembly)
            .Where(
                type => type.IsSubclassOf(completionProviderType) && !type.IsAbstract
                )
            .AsSelf()
            .As <CompletionProvider>()
            .As <ICompletionProvider>()
            .SingleInstance();
        }