Skip to content

Commit

Permalink
Version 3.7.0-312.0.dev
Browse files Browse the repository at this point in the history
Merge 6254583 into dev
  • Loading branch information
Dart CI committed Jan 9, 2025
2 parents a429df7 + 6254583 commit dbe08d9
Show file tree
Hide file tree
Showing 42 changed files with 8,827 additions and 967 deletions.
40 changes: 36 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,43 @@ main() {
and with a `Flexible` widget.
- Offer an assist to "inline" an else-block's inner if-statement with the
else-block to read `else if`.
- Add an additional fix to import an unknown prefixed identifier by updating
the `show` combinator on an existing import.
- Add a fix to import an unknown prefixed identifier by adding an
import directive with the given prefix.
- Add a fix to import an unknown prefixed identifier by removing a `hide`
combinator.
- Add a fix to import an unknown identifier by adding an import directive with a
`show` combinator, and optionally a prefix.
- Code completion now suggests instance variables when completing inside the
initializer of a _late_ field.
- Assists and quick fixes that add a const keyword now consider the
`prefer_const_declarations` lint rule, prefering to add `const` to a variable
declaration rather than the initial value.
- Add a fix to add a missing `on` keyword in an extension declaration.
- Add a fix to wrap an ambiguous property access or method call in an extension
override.
(Thanks [@FMorschel](https://github.com/FMorschel) for the above enhancements!
- Add the experimental `specify_nonobvious_property_types` lint rule.
- Add the experimental `omit_obvious_property_types` lint rule.
- Remove the `package_api_docs` lint rule.
- Remove the `unsafe_html` lint rule.
- The 'sort members' command now considers the `sort_constructors_first` lint
rule.
- The 'extract method' refactoring now uses generic method syntax for
function-typed parameters.
- Add quick fixes for more than 30 diagnostics.
- Add the [`strict_top_level_inference`] lint rule.
- Add the [`unnecessary_underscores`][] lint rule.
- Add the experimental [`specify_nonobvious_property_types`][] lint rule.
- Add the experimental [`omit_obvious_property_types`][] lint rule.
- Add the experimental [`unsafe_variance`][] lint rule.
- Remove the [`package_api_docs`][] lint rule.
- Remove the [`unsafe_html`][] lint rule.

[`strict_top_level_inference`]: https://dart.dev/tools/linter-rules/strict_top_level_inference
[`unnecessary_underscores`]: https://dart.dev/lints/unnecessary_underscores
[`specify_nonobvious_property_types`]: https://dart.dev/tools/linter-rules/specify_nonobvious_property_types
[`omit_obvious_property_types`]: https://dart.dev/tools/linter-rules/omit_obvious_property_types
[`unsafe_variance`]: https://dart.dev/tools/linter-rules/unsafe_variance
[`package_api_docs`]: https://dart.dev/tools/linter-rules/package_api_docs
[`unsafe_html`]: https://dart.dev/tools/linter-rules/unsafe_html

#### Dart format

Expand Down
14 changes: 13 additions & 1 deletion pkg/analysis_server/lib/src/analysis_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,19 @@ abstract class AnalysisServer {
if (node is StringLiteral && node.parent is UriBasedDirective) {
return null;
}
var element = ElementLocator.locate(node);

Element? element;
switch (node) {
case ExportDirective():
element = node.element;
case ImportDirective():
element = node.element;
case PartOfDirective():
element = node.element;
default:
element = ElementLocator.locate2(node).asElement;
}

if (node is SimpleIdentifier && element is PrefixElement) {
element = getImportElement(node);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ class ImportsHandler
return success(null);
}

String? prefix;
String? prefixName;
if (node is NamedType) {
prefix = node.importPrefix?.name.lexeme;
prefixName = node.importPrefix?.name.lexeme;
} else if (node.thisOrAncestorOfType<PrefixedIdentifier>()
case PrefixedIdentifier identifier) {
prefix = identifier.prefix.name;
case PrefixedIdentifier(:var prefix) when prefix != node) {
prefixName = prefix.name;
} else if (node is SimpleIdentifier) {
if (node.parent case MethodInvocation(
target: SimpleIdentifier target?,
)) {
prefix = target.toString();
prefixName = target.toString();
}
}

Expand All @@ -88,7 +88,7 @@ class ImportsHandler
element = enclosingElement;
}

var locations = _getImportLocations(library, unit, element, prefix);
var locations = _getImportLocations(library, unit, element, prefixName);

return success(nullIfEmpty(locations));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2401,6 +2401,10 @@ LintCode.unintended_html_in_doc_comment:
status: needsFix
notes: |-
The fix is to encode the angle brackets.
LintCode.unnecessary_async:
status: needsFix
notes: |-
And probably also quick assist that works even if returns `Future`.
LintCode.unnecessary_await_in_return:
status: hasFix
LintCode.unnecessary_brace_in_string_interps:
Expand Down
58 changes: 44 additions & 14 deletions pkg/analysis_server/test/lsp/import_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void foo() {
}

Future<void> test_import_double() async {
newFile('/home/my_project/lib/other.dart', '''
newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
export 'dart:math';
''');
await _verifyGoToImports(
Expand All @@ -93,10 +93,10 @@ Rando^m? r;
}

Future<void> test_import_double_ambiguous() async {
newFile('/home/my_project/lib/a1.dart', '''
newFile(join(projectFolderPath, 'lib', 'a1.dart'), '''
class A {}
''');
newFile('/home/my_project/lib/a2.dart', '''
newFile(join(projectFolderPath, 'lib', 'a2.dart'), '''
class A {}
''');
await _verifyGoToImports(
Expand All @@ -111,10 +111,10 @@ class A {}
}

Future<void> test_import_double_hide() async {
newFile('/home/my_project/lib/a1.dart', '''
newFile(join(projectFolderPath, 'lib', 'a1.dart'), '''
class A {}
''');
newFile('/home/my_project/lib/a2.dart', '''
newFile(join(projectFolderPath, 'lib', 'a2.dart'), '''
class A {}
''');
await _verifyGoToImports(
Expand All @@ -128,7 +128,7 @@ import 'a1.dart' hide A;
}

Future<void> test_import_double_same_different_alias() async {
newFile('/home/my_project/lib/other.dart', '''
newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
export 'dart:math';
''');
await _verifyGoToImports(
Expand All @@ -142,7 +142,7 @@ other.Rando^m? r;
}

Future<void> test_import_double_same_different_alias_prefix() async {
newFile('/home/my_project/lib/other.dart', '''
newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
export 'dart:math';
''');
await _verifyGoToImports(
Expand All @@ -156,12 +156,12 @@ other.Ran^dom? r;
}

Future<void> test_import_double_show() async {
newFile('/home/my_project/lib/a1.dart', '''
newFile(join(projectFolderPath, 'lib', 'a1.dart'), '''
class A {}
class B {}
''');
newFile('/home/my_project/lib/a2.dart', '''
newFile(join(projectFolderPath, 'lib', 'a2.dart'), '''
class A {}
''');
await _verifyGoToImports(
Expand All @@ -175,10 +175,10 @@ import 'a1.dart' show B;
}

Future<void> test_import_double_unambiguous_aliased() async {
newFile('/home/my_project/lib/a1.dart', '''
newFile(join(projectFolderPath, 'lib', 'a1.dart'), '''
class A {}
''');
newFile('/home/my_project/lib/a2.dart', '''
newFile(join(projectFolderPath, 'lib', 'a2.dart'), '''
class A {}
''');
await _verifyGoToImports(
Expand Down Expand Up @@ -371,7 +371,7 @@ math.Rando^m? r;
}

Future<void> test_import_single_exported() async {
newFile('/home/my_project/lib/other.dart', '''
newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
export 'dart:math';
''');
await _verifyGoToImports(
Expand All @@ -397,7 +397,7 @@ class LocalClass {}
}

Future<void> test_nestedInvocations() async {
newFile('/home/my_project/lib/other.dart', '''
newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
class A {
const A();
A foo() => A();
Expand All @@ -414,7 +414,7 @@ var a = A().foo().ba^r();
}

Future<void> test_nestedInvocations_extension() async {
newFile('/home/my_project/lib/other.dart', '''
newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
extension E on int {
void bar() {}
}
Expand All @@ -428,6 +428,36 @@ var a = 1.abs().ba^r();
);
}

Future<void> test_staticDeclarations() async {
newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
class A {
static const a = 1;
}
''');
await _verifyGoToImports(
TestCode.parse('''
[!import 'other.dart';!]
var a = A^.a;
'''),
);
}

Future<void> test_staticDeclarations_prefixed() async {
newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
class A {
static const a = 1;
}
''');
await _verifyGoToImports(
TestCode.parse('''
[!import 'other.dart' as o;!]
var a = o.A^.a;
'''),
);
}

Future<void> _verifyGoToImports(
TestCode code, {
Uri? fileUri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/src/dart/ast/element_locator.dart';
import 'package:analyzer/src/utilities/extensions/element.dart';
import 'package:analyzer_plugin/protocol/protocol_common.dart' hide Element;
import 'package:test/test.dart';

Expand Down Expand Up @@ -41,11 +42,24 @@ class RenameRefactoringTest extends RefactoringTest {
/// Creates a new [RenameRefactoring] in [refactoring] for the [Element] of
/// the [SimpleIdentifier] at the given [search] pattern.
void createRenameRefactoringAtString(String search) {
var identifier = findNode.any(search);
var element = ElementLocator.locate(identifier);
if (identifier is SimpleIdentifier && element is PrefixElement) {
element = getImportElement(identifier);
var node = findNode.any(search);

Element? element;
switch (node) {
case ExportDirective():
element = node.element;
case ImportDirective():
element = node.element;
case PartOfDirective():
element = node.element;
default:
element = ElementLocator.locate2(node).asElement;
}

if (node is SimpleIdentifier && element is PrefixElement) {
element = getImportElement(node);
}

createRenameRefactoringForElement(element);
}

Expand Down
2 changes: 0 additions & 2 deletions pkg/analyzer/analyzer_use_new_elements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ lib/src/dart/analysis/search.dart
lib/src/dart/analysis/session.dart
lib/src/dart/analysis/session_helper.dart
lib/src/dart/ast/ast.dart
lib/src/dart/ast/element_locator.dart
lib/src/dart/ast/extensions.dart
lib/src/dart/ast/utilities.dart
lib/src/dart/constant/constant_verifier.dart
Expand Down Expand Up @@ -147,7 +146,6 @@ test/generated/elements_types_mixin.dart
test/generated/non_error_resolver_test.dart
test/generated/resolver_test_case.dart
test/generated/type_system_test.dart
test/id_tests/type_constraint_generation_test.dart
test/src/dart/analysis/index_test.dart
test/src/dart/analysis/result_printer.dart
test/src/dart/analysis/results/get_element_declaration_test.dart
Expand Down
Loading

0 comments on commit dbe08d9

Please sign in to comment.