handleEditGetFixes method

  1. @override
Future<EditGetFixesResult> handleEditGetFixes(
  1. EditGetFixesParams parameters
)
override

Handle an 'edit.getFixes' request.

Throw a RequestFailure if the request could not be handled.

Implementation

@override
Future<plugin.EditGetFixesResult> handleEditGetFixes(
    plugin.EditGetFixesParams parameters) async {
  try {
    final driver = driverForPath(parameters.file) as AnalysisDriver;
    final analysisResult = await driver.getResult2(parameters.file);

    if (analysisResult is! ResolvedUnitResult) {
      return plugin.EditGetFixesResult([]);
    }

    final fixes = PTChecker(options: _options).start(
            driver, analysisResult.path, analysisResult.unit, analysisResult)
        .where((fix) =>
            fix.error.location.file == parameters.file &&
            fix.error.location.offset <= parameters.offset &&
            parameters.offset <=
                fix.error.location.offset + fix.error.location.length &&
            fix.fixes.isNotEmpty)
        .toList();

    return plugin.EditGetFixesResult(fixes);
  } on Exception catch (e, stackTrace) {
    channel.sendNotification(
      plugin.PluginErrorParams(false, e.toString(), stackTrace.toString())
          .toNotification(),
    );

    return plugin.EditGetFixesResult([]);
  }
}