Skip to content

Commit

Permalink
Version 3.3.0-57.0.dev
Browse files Browse the repository at this point in the history
Merge 5e255e0 into dev
  • Loading branch information
Dart CI committed Oct 24, 2023
2 parents 360370f + 5e255e0 commit 57661d5
Show file tree
Hide file tree
Showing 29 changed files with 690 additions and 119 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ vars = {
"boringssl_gen_rev": "a468ba9fec3f59edf46a7db98caaca893e1e4d96",
"boringssl_rev": "74646566e93de7551bfdfc5f49de7462f13d1d05",
"browser-compat-data_tag": "ac8cae697014da1ff7124fba33b0b4245cc6cd1b", # v1.0.22
"devtools_rev": "11ec4ae1036408018143b58d80d6feadbee56a6c",
"devtools_rev": "d2f59cf9cb072f64baa7268a0a97cf422f44edbf",
"icu_rev": "81d656878ec611cb0b42d52c82e9dae93920d9ba",
"jinja2_rev": "2222b31554f03e62600cd7e383376a7c187967a1",
"libcxx_rev": "44079a4cc04cdeffb9cfe8067bfb3c276fb2bab0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ import 'package:analysis_server/src/lsp/handlers/handlers.dart';
import 'package:analysis_server/src/lsp/mapping.dart';
import 'package:analysis_server/src/lsp/registration/feature_registration.dart';
import 'package:analysis_server/src/services/refactoring/legacy/move_file.dart';
import 'package:meta/meta.dart';

typedef StaticOptions = FileOperationRegistrationOptions?;

class WillRenameFilesHandler
extends SharedMessageHandler<RenameFilesParams, WorkspaceEdit?> {
/// A [Future] used by tests to allow inserting a delay during computation
/// to allow forcing inconsistent analysis.
@visibleForTesting
static Future<void>? delayDuringComputeForTests;

WillRenameFilesHandler(super.server);

@override
Method get handlesMessage => Method.workspace_willRenameFiles;

Expand Down Expand Up @@ -67,6 +74,10 @@ class WillRenameFilesHandler
}

final change = await refactoring.createChange();
if (delayDuringComputeForTests != null) {
await delayDuringComputeForTests;
}

if (token.isCancellationRequested) {
return cancelled();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ class BulkFixProcessor {
CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS_METHOD: [
DataDriven.new,
],
WarningCode.DEPRECATED_EXPORT_USE: [
DataDriven.new,
],
HintCode.DEPRECATED_MEMBER_USE: [
DataDriven.new,
],
Expand Down Expand Up @@ -384,6 +387,9 @@ class BulkFixProcessor {
}
}
}
// Files in bin can have imports to the package itself, these should be
// cleaned up.
packages.remove(rootFolder.shortName);

// Compute changes to pubspec.
var result = await _runPubspecValidatorAndFixGenerator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,17 @@ abstract class ResolvedCorrectionProducer
return null;
}

/// Return the extension type for the given [element].
Future<ExtensionTypeDeclaration?> getExtensionTypeDeclaration(
ExtensionTypeElement element) async {
var result = await sessionHelper.getElementDeclaration(element);
var node = result?.node;
if (node is ExtensionTypeDeclaration) {
return node;
}
return null;
}

LinterContext getLinterContext(path.Context pathContext) {
return LinterContextImpl(
[], // unused
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,16 @@ class CreateMethod extends ResolvedCorrectionProducer {
targetNode = await getMixinDeclaration(targetClassElement);
} else if (targetClassElement is ClassElement) {
targetNode = await getClassDeclaration(targetClassElement);
} else if (targetClassElement is ExtensionTypeElement) {
targetNode = await getExtensionTypeDeclaration(targetClassElement);
}
if (targetNode == null) {
return;
}
// maybe static
if (target is Identifier) {
staticModifier = target.staticElement?.kind == ElementKind.CLASS;
staticModifier = target.staticElement?.kind == ElementKind.CLASS ||
target.staticElement?.kind == ElementKind.EXTENSION_TYPE;
}
// use different utils
var targetPath = targetClassElement.source.fullName;
Expand Down
38 changes: 21 additions & 17 deletions pkg/analysis_server/test/lsp/completion_dart_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3941,25 +3941,29 @@ void f() {
await openFile(mainFileUri, code.code);
await initialAnalysis;

// User a Completer to control when the completion handler starts computing.
// Use a Completer to control when the completion handler starts computing.
final completer = Completer<void>();
CompletionHandler.delayAfterResolveForTests = completer.future;

// Start the completion request but don't await it yet.
final completionRequest =
getCompletionList(mainFileUri, code.position.position);
// Modify the document to ensure the snippet requests will fail to build
// edits and then allow the handler to continue.
await replaceFile(222, mainFileUri, '');
completer.complete();

// Wait for the results.
final result = await completionRequest;

// Ensure we flagged that we did not return everything but we still got
// results.
expect(result.isIncomplete, isTrue);
expect(result.items, isNotEmpty);
try {
// Start the completion request but don't await it yet.
final completionRequest =
getCompletionList(mainFileUri, code.position.position);
// Modify the document to ensure the snippet requests will fail to build
// edits and then allow the handler to continue.
await replaceFile(222, mainFileUri, '');
completer.complete();

// Wait for the results.
final result = await completionRequest;

// Ensure we flagged that we did not return everything but we still got
// results.
expect(result.isIncomplete, isTrue);
expect(result.items, isNotEmpty);
} finally {
// Ensure we never leave an incomplete future if anything above throws.
CompletionHandler.delayAfterResolveForTests = null;
}
}

Future<void>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
// 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/lsp_protocol/protocol.dart';
import 'package:analysis_server/src/lsp/handlers/handler_will_rename_files.dart';
import 'package:analysis_server/src/protocol_server.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
Expand Down Expand Up @@ -43,17 +46,28 @@ class WillRenameFilesTest extends LspOverLegacyTest {
Future<void> test_inconsistentAnalysis() async {
final testFileNewPath = join(testPackageLibPath, 'test_new.dart');

await addOverlay(testFilePath, 'original');
// Don't await, need to send modification.
final editFuture = onWillRename([
FileRename(
oldUri: toUri(testFilePath).toString(),
newUri: toUri(testFileNewPath).toString(),
),
]);
await updateOverlay(testFilePath, SourceEdit(0, 0, 'inserted'));

expect(editFuture, throwsA(isResponseError(ErrorCodes.ContentModified)));
// Use a Completer to control when the refactor finishes computing so that
// we can ensure the overlay modification had time to be applied and trigger
// creation of new sessions.
final completer = Completer<void>();
WillRenameFilesHandler.delayDuringComputeForTests = completer.future;
try {
await addOverlay(testFilePath, 'original');
// Don't await, need to send modification.
final editFuture = onWillRename([
FileRename(
oldUri: toUri(testFilePath).toString(),
newUri: toUri(testFileNewPath).toString(),
),
]);
await updateOverlay(testFilePath, SourceEdit(0, 0, 'inserted'));
await pumpEventQueue(times: 50000).then(completer.complete);

expect(editFuture, throwsA(isResponseError(ErrorCodes.ContentModified)));
} finally {
// Ensure we never leave an incomplete future if anything above throws.
WillRenameFilesHandler.delayDuringComputeForTests = null;
}
}

/// Test moving multiple items at once. Both files reference each other
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,24 @@ void f() {
''');
}

Future<void> test_createQualified_fromExtensionType() async {
await resolveTestCode('''
extension type A(String s) {
}
void f() {
A.myUndefinedMethod();
}
''');
await assertHasFix('''
extension type A(String s) {
static void myUndefinedMethod() {}
}
void f() {
A.myUndefinedMethod();
}
''');
}

Future<void> test_createQualified_fromInstance() async {
await resolveTestCode('''
class A {
Expand All @@ -281,6 +299,24 @@ void f(A a) {
''');
}

Future<void> test_createQualified_instance_fromExtensionType() async {
await resolveTestCode('''
extension type A(String s) {
}
void f(A a) {
a.myUndefinedMethod();
}
''');
await assertHasFix('''
extension type A(String s) {
void myUndefinedMethod() {}
}
void f(A a) {
a.myUndefinedMethod();
}
''');
}

Future<void> test_createQualified_targetIsFunctionType() async {
await resolveTestCode('''
typedef A();
Expand Down
Loading

0 comments on commit 57661d5

Please sign in to comment.