analyzeFile method
Future<void>
analyzeFile({
- required AnalysisContext analysisContext,
- required String path,
override
Analyzes the given file.
Implementation
@override
Future<void> analyzeFile({
required AnalysisContext analysisContext,
required String path,
}) async {
if (!path.endsWith('.dart')) {
_logger.fine('No dart file: [$path]');
return;
}
final root = analysisContext.contextRoot.root.path;
final analysisOptions = (_options[analysisContext.currentSession] ??=
_getAnalysisOptions(analysisContext));
final isAnalyzed = analysisContext.contextRoot.isAnalyzed(path);
final isExcluded = !isAnalyzed || analysisOptions.isExcluded(path);
if (isExcluded) {
_logger.finer('is not analyzed: $path '
'(analyzed: $isAnalyzed / isExcluded: $isExcluded)');
channel.sendNotification(
plugin.AnalysisErrorsParams(
path,
<plugin.AnalysisError>[],
).toNotification(),
);
return;
}
final analysisResult =
await analysisContext.currentSession.getResolvedUnit(path);
if (analysisResult is! ResolvedUnitResult) {
channel.sendNotification(
plugin.AnalysisErrorsParams(
path,
[],
).toNotification(),
);
return;
}
final errors = _check(
root, analysisOptions, path, analysisResult.unit, analysisResult);
channel.sendNotification(
plugin.AnalysisErrorsParams(
path,
errors.map((e) => e.error).toList(),
).toNotification(),
);
}