blob: ca28963dcb6152fa2b5492048c7785cd209d7b2e [file] [log] [blame]
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:io';
import 'package:analysis_server/lsp_protocol/protocol_generated.dart';
import 'package:analysis_server/lsp_protocol/protocol_special.dart';
import 'package:analysis_server/src/lsp/handlers/handlers.dart';
import 'package:analysis_server/src/lsp/lsp_analysis_server.dart';
class ExitMessageHandler extends MessageHandler<Null, Null> {
final bool clientDidCallShutdown;
ExitMessageHandler(
LspAnalysisServer server, {
this.clientDidCallShutdown = false,
}) : super(server);
@override
Method get handlesMessage => Method.exit;
@override
LspJsonHandler<Null> get jsonHandler => NullJsonHandler;
@override
Future<ErrorOr<Null>> handle(Null _, CancellationToken token) async {
// Set a flag that the server shutdown is being controlled here to ensure
// that the normal code that shuts down the server when the channel closes
// does not fire.
server.willExit = true;
await server.shutdown();
Future(() {
exit(clientDidCallShutdown ? 0 : 1);
});
return success(null);
}
}