generateCompletionResponse method

Future<GeneratorResult<CompletionGetSuggestionsResult?>> generateCompletionResponse(
  1. CompletionRequest request
)

Create a 'completion.getSuggestions' response for the file with the given path. If any of the contributors throws an exception, also create a non-fatal 'plugin.error' notification.

Implementation

Future<GeneratorResult<CompletionGetSuggestionsResult?>>
    generateCompletionResponse(CompletionRequest request) async {
  var notifications = <Notification>[];
  var collector = CompletionCollectorImpl();
  try {
    for (var contributor in contributors) {
      request.checkAborted();
      try {
        await contributor.computeSuggestions(request, collector);
      } catch (exception, stackTrace) {
        notifications.add(PluginErrorParams(
                false, exception.toString(), stackTrace.toString())
            .toNotification());
      }
    }
  } on AbortCompletion {
    return GeneratorResult(null, notifications);
  }
  collector.offset ??= request.offset;
  collector.length ??= 0;

  var result = CompletionGetSuggestionsResult(
      collector.offset!, collector.length!, collector.suggestions);
  return GeneratorResult(result, notifications);
}