blob: e27025531877bdc032f7ee4f078a19a22b07e1f6 [file] [log] [blame]
// Copyright (c) 2019, 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 '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 WorkspaceFoldersHandler
extends MessageHandler<DidChangeWorkspaceFoldersParams, void> {
// Whether to update analysis roots based on the open workspace folders.
bool updateAnalysisRoots;
WorkspaceFoldersHandler(LspAnalysisServer server, this.updateAnalysisRoots)
: super(server);
@override
Method get handlesMessage => Method.workspace_didChangeWorkspaceFolders;
@override
LspJsonHandler<DidChangeWorkspaceFoldersParams> get jsonHandler =>
DidChangeWorkspaceFoldersParams.jsonHandler;
@override
Future<ErrorOr<void>> handle(
DidChangeWorkspaceFoldersParams params, CancellationToken token) async {
// Don't do anything if our analysis roots are not based on open workspaces.
if (!updateAnalysisRoots) {
return success(null);
}
final added =
params.event.added.map((wf) => Uri.parse(wf.uri).toFilePath()).toList();
final removed = params.event.removed
.map((wf) => Uri.parse(wf.uri).toFilePath())
.toList();
await server.updateWorkspaceFolders(added, removed);
return success(null);
}
}