/// <summary>
        ///     The asynchronous program entry-point.
        /// </summary>
        /// <returns>
        ///     The process exit code.
        /// </returns>
        static async Task <int> AsyncMain()
        {
            using (ActivityCorrelationManager.BeginActivityScope())
                using (Terminator terminator = new Terminator())
                    using (IContainer container = BuildContainer())
                    {
                        // Force initialisation of logging.
                        ILogger log = container.Resolve <ILogger>().ForContext(typeof(Program));

                        log.Debug("Creating language server...");

                        var server = container.Resolve <LSP.Server.LanguageServer>();

                        log.Debug("Waiting for client to initialise language server...");

                        Task initializeTask = server.Initialize();

                        // Special case for probing whether language server is startable given current runtime environment.
                        string[] commandLineArguments = Environment.GetCommandLineArgs();
                        if (commandLineArguments.Length == 2 && commandLineArguments[1] == "--probe")
                        {
                            // Give the language server a chance to start.
                            await Task.Yield();

                            // Show any exception encountered while starting the language server.
                            if (initializeTask.IsFaulted || initializeTask.IsCanceled)
                            {
                                await initializeTask;
                            }

                            Console.Error.WriteLine("PROBE: Yes, the language server can start.");

                            return(0);
                        }

                        await initializeTask;

                        log.Debug("Language server initialised by client.");

                        if (server.Client.ProcessId != null)
                        {
                            terminator.Initialize(
                                (int)server.Client.ProcessId.Value
                                );
                        }

                        await server.WasShutDown;

                        log.Debug("Language server is shutting down...");

                        await server.WaitForExit;

                        log.Debug("Server has shut down. Preparing to terminate server process...");

                        log.Debug("Server process is ready to terminate.");

                        return(0);
                    }
        }
Exemple #2
0
        /// <summary>
        ///     The asynchronous program entry-point.
        /// </summary>
        /// <returns>
        ///     The process exit code.
        /// </returns>
        static async Task <int> AsyncMain()
        {
            using (ActivityCorrelationManager.BeginActivityScope())
                using (Terminator terminator = new Terminator())
                    using (IContainer container = BuildContainer())
                    {
                        // Force initialisation of logging.
                        ILogger log = container.Resolve <ILogger>().ForContext(typeof(Program));

                        log.Debug("Creating language server...");

                        var server = container.Resolve <LSP.Server.LanguageServer>();

                        log.Debug("Waiting for client to initialise language server...");

                        Task initializeTask = server.Initialize();

                        // Special case for probing whether language server is startable given current runtime environment.
                        string[] commandLineArguments = Environment.GetCommandLineArgs();
                        if (commandLineArguments.Length == 2 && commandLineArguments[1] == "--probe")
                        {
                            // Give the language server a chance to start.
                            await Task.Yield();

                            // Show any exception encountered while starting the language server.
                            if (initializeTask.IsFaulted || initializeTask.IsCanceled)
                            {
                                await initializeTask;
                            }

                            Console.Error.WriteLine("PROBE: Yes, the language server can start.");

                            return(0);
                        }

                        await initializeTask;

                        log.Debug("Language server initialised by client.");

                        await server.WasShutDown;

                        log.Debug("Language server is shutting down...");

                        await server.WaitForExit;

                        log.Debug("Server has shut down. Preparing to terminate server process...");

                        // AF: Temporary fix for tintoy/msbuild-project-tools-vscode#36
                        //
                        //     The server hangs while waiting for LSP's ProcessScheduler thread to terminate so, after a timeout has elapsed, we forcibly terminate this process.
                        terminator.TerminateAfter(
                            TimeSpan.FromSeconds(3)
                            );

                        log.Debug("Server process is ready to terminate.");

                        return(0);
                    }
        }
Exemple #3
0
        /// <summary>
        ///     The asynchronous program entry-point.
        /// </summary>
        /// <returns>
        ///     A <see cref="Task"/> representing program execution.
        /// </returns>
        static async Task AsyncMain()
        {
            using (ActivityCorrelationManager.BeginActivityScope())
                using (Terminator terminator = new Terminator())
                    using (IContainer container = BuildContainer())
                    {
                        // Force initialisation of logging.
                        ILogger log = container.Resolve <ILogger>().ForContext(typeof(Program));

                        log.Debug("Creating language server...");

                        var server = container.Resolve <LSP.Server.LanguageServer>();

                        log.Debug("Waiting for client to initialise language server...");

                        await server.Initialize();

                        log.Debug("Language server initialised by client.");

                        await server.WasShutDown;

                        log.Debug("Language server is shutting down...");

                        await server.WaitForExit;

                        log.Debug("Server has shut down. Preparing to terminate server process...");

                        // AF: Temporary fix for tintoy/msbuild-project-tools-vscode#36
                        //
                        //     The server hangs while waiting for LSP's ProcessScheduler thread to terminate so, after a timeout has elapsed, we forcibly terminate this process.
                        terminator.TerminateAfter(
                            TimeSpan.FromSeconds(3)
                            );

                        log.Debug("Server process is ready to terminate.");
                    }
        }