handleAnalysisSetContextRoots method

Future<AnalysisSetContextRootsResult> handleAnalysisSetContextRoots(
  1. AnalysisSetContextRootsParams parameters
)
inherited

Handle an 'analysis.setContextRoots' request.

Throw a RequestFailure if the request could not be handled.

Implementation

Future<AnalysisSetContextRootsResult> handleAnalysisSetContextRoots(
    AnalysisSetContextRootsParams parameters) async {
  final currentContextCollection = _contextCollection;
  if (currentContextCollection != null) {
    _contextCollection = null;
    await beforeContextCollectionDispose(
      contextCollection: currentContextCollection,
    );
    await currentContextCollection.dispose();
  }

  final includedPaths = parameters.roots.map((e) => e.root).toList();
  final contextCollection = AnalysisContextCollectionImpl(
    resourceProvider: resourceProvider,
    includedPaths: includedPaths,
    byteStore: _byteStore,
    sdkPath: _sdkPath,
    fileContentCache: FileContentCache(resourceProvider),
  );
  _contextCollection = contextCollection;
  await afterNewContextCollection(
    contextCollection: contextCollection,
  );
  return AnalysisSetContextRootsResult();
}