Remove CompletionDomainHandler

Change-Id: I242358ec168fd047576117f2cbfe6e380e9c86c8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242480
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Brian Wilkerson 2022-04-26 16:02:17 +00:00 committed by Commit Bot
parent efdffab8b7
commit b922aa00f2
9 changed files with 60 additions and 84 deletions

View file

@ -15,7 +15,6 @@ import 'package:analysis_server/src/analysis_server_abstract.dart';
import 'package:analysis_server/src/channel/channel.dart';
import 'package:analysis_server/src/computer/computer_highlights.dart';
import 'package:analysis_server/src/context_manager.dart';
import 'package:analysis_server/src/domain_completion.dart';
import 'package:analysis_server/src/domain_server.dart';
import 'package:analysis_server/src/domains/analysis/occurrences.dart';
import 'package:analysis_server/src/domains/analysis/occurrences_dart.dart';
@ -36,6 +35,11 @@ import 'package:analysis_server/src/handler/legacy/analytics_enable.dart';
import 'package:analysis_server/src/handler/legacy/analytics_is_enabled.dart';
import 'package:analysis_server/src/handler/legacy/analytics_send_event.dart';
import 'package:analysis_server/src/handler/legacy/analytics_send_timing.dart';
import 'package:analysis_server/src/handler/legacy/completion_get_suggestion_details.dart';
import 'package:analysis_server/src/handler/legacy/completion_get_suggestion_details2.dart';
import 'package:analysis_server/src/handler/legacy/completion_get_suggestions.dart';
import 'package:analysis_server/src/handler/legacy/completion_get_suggestions2.dart';
import 'package:analysis_server/src/handler/legacy/completion_set_subscriptions.dart';
import 'package:analysis_server/src/handler/legacy/diagnostic_get_diagnostics.dart';
import 'package:analysis_server/src/handler/legacy/diagnostic_get_server_port.dart';
import 'package:analysis_server/src/handler/legacy/edit_bulk_fixes.dart';
@ -142,6 +146,14 @@ class AnalysisServer extends AbstractAnalysisServer {
ANALYTICS_REQUEST_SEND_EVENT: AnalyticsSendEventHandler.new,
ANALYTICS_REQUEST_SEND_TIMING: AnalyticsSendTimingHandler.new,
//
COMPLETION_REQUEST_GET_SUGGESTION_DETAILS:
CompletionGetSuggestionDetailsHandler.new,
COMPLETION_REQUEST_GET_SUGGESTION_DETAILS2:
CompletionGetSuggestionDetails2Handler.new,
COMPLETION_REQUEST_GET_SUGGESTIONS: CompletionGetSuggestionsHandler.new,
COMPLETION_REQUEST_GET_SUGGESTIONS2: CompletionGetSuggestions2Handler.new,
COMPLETION_REQUEST_SET_SUBSCRIPTIONS: CompletionSetSubscriptionsHandler.new,
//
DIAGNOSTIC_REQUEST_GET_DIAGNOSTICS: DiagnosticGetDiagnosticsHandler.new,
DIAGNOSTIC_REQUEST_GET_SERVER_PORT: DiagnosticGetServerPortHandler.new,
//
@ -354,7 +366,6 @@ class AnalysisServer extends AbstractAnalysisServer {
.listen(handleRequest, onDone: done, onError: error);
handlers = <server.RequestHandler>[
ServerDomainHandler(this),
CompletionDomainHandler(this),
];
refactoringWorkspace = RefactoringWorkspace(driverMap.values, searchEngine);
_newRefactoringManager();

View file

@ -1,71 +0,0 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'package:analysis_server/protocol/protocol.dart';
import 'package:analysis_server/protocol/protocol_constants.dart';
import 'package:analysis_server/src/domain_abstract.dart';
import 'package:analysis_server/src/handler/legacy/completion_get_suggestion_details.dart';
import 'package:analysis_server/src/handler/legacy/completion_get_suggestion_details2.dart';
import 'package:analysis_server/src/handler/legacy/completion_get_suggestions.dart';
import 'package:analysis_server/src/handler/legacy/completion_get_suggestions2.dart';
import 'package:analysis_server/src/handler/legacy/completion_set_subscriptions.dart';
import 'package:analyzer/exception/exception.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/utilities/cancellation.dart';
/// Instances of the class [CompletionDomainHandler] implement a
/// [RequestHandler] that handles requests in the completion domain.
class CompletionDomainHandler extends AbstractRequestHandler {
/// Initialize a new request handler for the given [server].
CompletionDomainHandler(super.server);
@override
Response? handleRequest(
Request request, CancellationToken cancellationToken) {
if (!server.options.featureSet.completion) {
return Response.invalidParameter(
request,
'request',
'The completion feature is not enabled',
);
}
return runZonedGuarded<Response?>(() {
var requestName = request.method;
if (requestName == COMPLETION_REQUEST_GET_SUGGESTION_DETAILS) {
CompletionGetSuggestionDetailsHandler(
server, request, cancellationToken)
.handle();
return Response.DELAYED_RESPONSE;
} else if (requestName == COMPLETION_REQUEST_GET_SUGGESTION_DETAILS2) {
CompletionGetSuggestionDetails2Handler(
server, request, cancellationToken)
.handle();
return Response.DELAYED_RESPONSE;
} else if (requestName == COMPLETION_REQUEST_GET_SUGGESTIONS) {
CompletionGetSuggestionsHandler(server, request, cancellationToken)
.handle();
return Response.DELAYED_RESPONSE;
} else if (requestName == COMPLETION_REQUEST_GET_SUGGESTIONS2) {
CompletionGetSuggestions2Handler(server, request, cancellationToken)
.handle();
return Response.DELAYED_RESPONSE;
} else if (requestName == COMPLETION_REQUEST_SET_SUBSCRIPTIONS) {
CompletionSetSubscriptionsHandler(server, request, cancellationToken)
.handle();
return Response.DELAYED_RESPONSE;
}
return null;
}, (exception, stackTrace) {
AnalysisEngine.instance.instrumentationService.logException(
CaughtException.withMessage(
'Failed to handle completion domain request: ${request.method}',
exception,
stackTrace));
});
}
}

View file

@ -11,7 +11,7 @@ import 'package:analyzer/dart/analysis/session.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
/// The handler for the `completion.getSuggestionDetails` request.
class CompletionGetSuggestionDetailsHandler extends LegacyHandler {
class CompletionGetSuggestionDetailsHandler extends CompletionHandler {
/// The identifiers of the latest `getSuggestionDetails` request.
/// We use it to abort previous requests.
int _latestGetSuggestionDetailsId = 0;
@ -23,6 +23,10 @@ class CompletionGetSuggestionDetailsHandler extends LegacyHandler {
@override
Future<void> handle() async {
if (completionIsDisabled) {
return;
}
var params = CompletionGetSuggestionDetailsParams.fromRequest(request);
var file = params.file;

View file

@ -12,7 +12,7 @@ import 'package:analyzer/dart/analysis/session.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
/// The handler for the `completion.getSuggestionDetails2` request.
class CompletionGetSuggestionDetails2Handler extends LegacyHandler {
class CompletionGetSuggestionDetails2Handler extends CompletionHandler {
/// The identifiers of the latest `getSuggestionDetails2` request.
/// We use it to abort previous requests.
int _latestGetSuggestionDetailsId = 0;
@ -24,6 +24,10 @@ class CompletionGetSuggestionDetails2Handler extends LegacyHandler {
@override
Future<void> handle() async {
if (completionIsDisabled) {
return;
}
var params = CompletionGetSuggestionDetails2Params.fromRequest(request);
var file = params.file;

View file

@ -24,6 +24,10 @@ class CompletionGetSuggestionsHandler extends CompletionGetSuggestions2Handler {
@override
Future<void> handle() async {
if (completionIsDisabled) {
return;
}
var budget = CompletionBudget(server.completionState.budgetDuration);
// extract and validate params

View file

@ -27,7 +27,7 @@ import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
import 'package:collection/collection.dart';
/// The handler for the `completion.getSuggestions2` request.
class CompletionGetSuggestions2Handler extends LegacyHandler
class CompletionGetSuggestions2Handler extends CompletionHandler
with RequestHandlerMixin<AnalysisServer> {
/// Initialize a newly created handler to be able to service requests for the
/// [server].
@ -107,6 +107,10 @@ class CompletionGetSuggestions2Handler extends LegacyHandler
@override
Future<void> handle() async {
if (completionIsDisabled) {
return;
}
var params = CompletionGetSuggestions2Params.fromRequest(request);
var file = params.file;
var offset = params.offset;

View file

@ -9,7 +9,7 @@ import 'package:analysis_server/src/domains/completion/available_suggestions.dar
import 'package:analysis_server/src/handler/legacy/legacy_handler.dart';
/// The handler for the `completion.setSubscriptions` request.
class CompletionSetSubscriptionsHandler extends LegacyHandler {
class CompletionSetSubscriptionsHandler extends CompletionHandler {
/// Initialize a newly created handler to be able to service requests for the
/// [server].
CompletionSetSubscriptionsHandler(
@ -17,6 +17,10 @@ class CompletionSetSubscriptionsHandler extends LegacyHandler {
@override
Future<void> handle() async {
if (completionIsDisabled) {
return;
}
var params = CompletionSetSubscriptionsParams.fromRequest(request);
var subscriptions = server.completionState.subscriptions;

View file

@ -13,6 +13,28 @@ import 'package:analyzer/error/error.dart';
import 'package:analyzer/src/dart/error/syntactic_errors.g.dart';
import 'package:analyzer/src/utilities/cancellation.dart';
/// A request handler for the completion domain.
abstract class CompletionHandler extends LegacyHandler {
/// Initialize a newly created handler to be able to service requests for the
/// [server].
CompletionHandler(super.server, super.request, super.cancellationToken);
/// Return `true` if completion is disabled and the handler should return. If
/// `true` is returned then a response will already have been returned, so
/// subclasses should not return a second response.
bool get completionIsDisabled {
if (!server.options.featureSet.completion) {
sendResponse(Response.invalidParameter(
request,
'request',
'The completion feature is not enabled',
));
return true;
}
return false;
}
}
/// A request handler for the legacy protocol.
abstract class LegacyHandler {
/// The analysis server that is using this handler to process a request.

View file

@ -10,7 +10,6 @@ import 'package:analysis_server/protocol/protocol_constants.dart'
import 'package:analysis_server/protocol/protocol_generated.dart';
import 'package:analysis_server/src/analysis_server.dart';
import 'package:analysis_server/src/analysis_server_abstract.dart';
import 'package:analysis_server/src/domain_completion.dart';
import 'package:analysis_server/src/lsp/lsp_analysis_server.dart'
show LspAnalysisServer;
import 'package:analysis_server/src/plugin/plugin_manager.dart';
@ -356,13 +355,8 @@ class CompletionPage extends AbstractCompletionPage {
CompletionPage(super.site, this.server);
CompletionDomainHandler get completionDomain => server.handlers
.firstWhere((handler) => handler is CompletionDomainHandler)
as CompletionDomainHandler;
@override
path.Context get pathContext =>
completionDomain.server.resourceProvider.pathContext;
path.Context get pathContext => server.resourceProvider.pathContext;
@override
List<CompletionPerformance> get performanceItems =>