handleAnalysisSetContextRoots method

Future<AnalysisSetContextRootsResult> handleAnalysisSetContextRoots(
  1. AnalysisSetContextRootsParams parameters
)

Handle an 'analysis.setContextRoots' request.

Throw a RequestFailure if the request could not be handled.

Implementation

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

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