blob: 82b3f07cfb802c9b68abf67fc1fe06d09984d818 [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<void, void> {
final bool clientDidCallShutdown;
LspAnalysisServer server, {
this.clientDidCallShutdown = false,
}) : super(server);
Method get handlesMessage => Method.exit;
LspJsonHandler<void> get jsonHandler => NullJsonHandler;
Future<ErrorOr<void>> handle(void _, 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();