Files
sdk/pkg/analysis_server/test/client/impl/completion_driver.dart
Paul Berry afcfbbeba8 Migrate developer experience packages to new constructor decl syntax.
(Part of https://github.com/dart-lang/sdk/issues/63288)

This change migrates the packages owned by the developer experience
team to use the new constructor declaration syntax, described in
https://github.com/dart-lang/language/blob/main/accepted/future-releases/primary-constructors/feature-specification.md#abbreviations-of-in-body-constructor-declarations.

This change was performed in an automated fashion, by (a) bumping the
packages' SDK constraints to `3.13.0-0`, (b) enabling the lints
`unnecessary_type_name_in_constructor` and
`unnecessary_const_in_enum_constructor`, (c) fixing the resulting lint
failures using `dart fix`, and then (d) reformatting the affected
files.

To ease code review, I've reverted unrelated formatting changes.

Since this change requires bumping SDK constaints to `3.13.0-0`, it
was only performed on packages that are *not* published on
pub. (Packages that *are* published on pub should remain on lower
language versions until at least after the stable version of 3.13 is
released, so that we don't block users on the stable channel from
receiving updates to those packages.)

Change-Id: Ibb4daebafd239da58251e838ea6a3f336a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505046
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
SLSA-Policy-Verified: SLSA Policy Verification Service <devtools-gerritcodereview-exitgate@google.com>
2026-05-27 14:52:58 -07:00

100 lines
3.4 KiB
Dart

// Copyright (c) 2020, 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/protocol/protocol_generated.dart'
hide AnalysisOptions;
import 'package:analyzer/src/test_utilities/test_code_format.dart';
import 'package:analyzer_plugin/protocol/protocol_common.dart';
import 'package:meta/meta.dart';
import 'package:test/test.dart';
import '../../analysis_server_base.dart';
import 'expect_mixin.dart';
class CompletionDriver with ExpectMixin {
final PubPackageAnalysisServerTest server;
Map<String, Completer<void>> receivedSuggestionsCompleters = {};
List<CompletionSuggestion> suggestions = [];
Map<String, List<CompletionSuggestion>> allSuggestions = {};
final Map<String, ExistingImports> fileToExistingImports = {};
final Map<String, List<AnalysisError>> filesErrors = {};
late String completionId;
late int completionOffset;
late int replacementOffset;
late int replacementLength;
new({required this.server}) {
server.serverChannel.notifications.listen(processNotification);
}
void addTestFile(String content) {
var code = TestCode.parse(content);
completionOffset = code.position.offset;
server.newFile(server.testFilePath, code.code);
}
void assertValidId(String id) {
expect(id, isNotNull);
expect(id.isNotEmpty, isTrue);
}
Future<void> createProject() async {
await server.setRoots(included: [server.workspaceRootPath], excluded: []);
}
Future<List<CompletionSuggestion>> getSuggestions() async {
var request = CompletionGetSuggestions2Params(
server.convertPath(server.testFilePath),
completionOffset,
1 << 16,
timeout: 60 * 1000,
).toRequest('0', clientUriConverter: null);
var response = await server.handleRequest(request);
if (response.error case var error?) {
fail('${request.method} failed: ${error.code}: ${error.message}');
}
var result = CompletionGetSuggestions2Result.fromResponse(
response,
clientUriConverter: null,
);
replacementOffset = result.replacementOffset;
replacementLength = result.replacementLength;
return result.suggestions;
}
@mustCallSuper
Future<void> processNotification(Notification notification) async {
if (notification.event == completionNotificationExistingImports) {
var params = CompletionExistingImportsParams.fromNotification(
notification,
clientUriConverter: null,
);
fileToExistingImports[params.file] = params.imports;
} else if (notification.event == analysisNotificationErrors) {
var decoded = AnalysisErrorsParams.fromNotification(
notification,
clientUriConverter: null,
);
filesErrors[decoded.file] = decoded.errors;
} else if (notification.event == analysisNotificationFlushResults) {
// Ignored.
} else if (notification.event == serverNotificationError) {
throw Exception('server error: ${notification.toJson()}');
} else if (notification.event == serverNotificationConnected) {
// Ignored.
} else {
print('Unhandled notification: ${notification.event}');
}
}
}