From 871d7580af52a4db4168e62c42f74ae3b3688aef Mon Sep 17 00:00:00 2001 From: Paulo Aboim Pinto Date: Thu, 7 Apr 2022 02:00:26 +0200 Subject: [PATCH] Force shutdown when received from the client, #1 --- .../Avalonia.AXAML.LanguageServer/Program.cs | 37 ++++++++++--------- src/extension.ts | 11 +++++- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/Avalonia.AXAML.LanguageServer/Avalonia.AXAML.LanguageServer/Program.cs b/Avalonia.AXAML.LanguageServer/Avalonia.AXAML.LanguageServer/Program.cs index 0a6457a..61f7baf 100644 --- a/Avalonia.AXAML.LanguageServer/Avalonia.AXAML.LanguageServer/Program.cs +++ b/Avalonia.AXAML.LanguageServer/Avalonia.AXAML.LanguageServer/Program.cs @@ -24,23 +24,26 @@ namespace Avalonia.axamlLanguageServer Log.Logger.Information("Starting log..."); - var server = await OmniSharp.Extensions.LanguageServer.Server.LanguageServer - .From( - options => - options - .WithInput(Console.OpenStandardInput()) - .WithOutput(Console.OpenStandardOutput()) - .ConfigureLogging( - x => x - .AddSerilog(Log.Logger) - .AddLanguageProtocolLogging() - .SetMinimumLevel(LogLevel.Debug) - ) - .WithServices(ConfigureServices) - .WithHandler() - .WithHandler() - .WithHandler()) - .ConfigureAwait(false); + var server = await LanguageServer.From( + options => options + .WithInput(Console.OpenStandardInput()) + .WithOutput(Console.OpenStandardOutput()) + .ConfigureLogging( + x => x + .AddSerilog(Log.Logger) + .AddLanguageProtocolLogging() + .SetMinimumLevel(LogLevel.Debug) + ) + .WithServices(ConfigureServices) + .WithHandler() + .WithHandler() + .WithHandler() + ).ConfigureAwait(false); + + server.Shutdown.Subscribe(x => { + Log.Logger.Information("--> Shutdown..."); + Environment.Exit(0); + }); await server .WaitForExit diff --git a/src/extension.ts b/src/extension.ts index 012682c..405a65b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -4,8 +4,8 @@ import { workspace } from 'vscode'; import { LanguageClient, - LanguageClientOptions, ServerOptions, + LanguageClientOptions, TransportKind, } from "vscode-languageclient/node"; @@ -62,4 +62,11 @@ export function activate(context: vscode.ExtensionContext) { } -export function deactivate() {} +export function deactivate() : Thenable | undefined +{ + if (!client) { + return undefined; + } + + return client.stop(); +}