createAnalysisDriver method
Create an analysis driver that can analyze the files within the given
contextRoot
.
Implementation
@override
AnalysisDriverGeneric createAnalysisDriver(plugin.ContextRoot contextRoot) {
final rootPath = contextRoot.root;
final locator =
ContextLocator(resourceProvider: resourceProvider).locateRoots(
includedPaths: [rootPath],
excludedPaths: contextRoot.exclude,
optionsFile: contextRoot.optionsFile,
);
if (locator.isEmpty) {
final error = StateError('Unexpected empty context');
channel.sendNotification(plugin.PluginErrorParams(
true,
error.message,
error.stackTrace.toString(),
).toNotification());
throw error;
}
final builder = ContextBuilder(resourceProvider: resourceProvider);
final context = builder.createContext(contextRoot: locator.first)
as DriverBasedAnalysisContext;
final dartDriver = context.driver;
runZonedGuarded(
() {
dartDriver.results.listen((analysisResult) {
_processResult(dartDriver, analysisResult);
});
},
(e, stackTrace) {
channel.sendNotification(
plugin.PluginErrorParams(false, e.toString(), stackTrace.toString())
.toNotification(),
);
},
);
return dartDriver;
}