[stable][DAS] Fixes completion for `!=` for dot shorthands
Issue description: Code completion for != wasn't using the correct
context so no dot shorthands were suggested.
What is the fix: Fixed a typo in the context type provider in the
analysis server. `BANG_EQ_EQ` -> `BANG_EQ`
Why cherry-pick: Users can now see code completions of shorthands
with `!=`.
Risk: Low, this is a small typo fix to the correct operator and
would only affect code completion.
Issue link(s): https://github.com/dart-lang/sdk/issues/62216
Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/467320
Change-Id: Ic3a7e0e31a2296aaef121ba6d752c6ef55c041d8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/467384
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8f7acbc..13e089f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,9 +9,12 @@
[dart-lang/sdk#62013])
- Fixes code completion for dot shorthands in enum constant arguments. (issue
[dart-lang/sdk#62168])
+- Fixes code completion for dot shorthands and the `!=` operator. (issue
+ [dart-lang/sdk#62216])
[dart-lang/sdk#62013]: https://github.com/dart-lang/sdk/issues/62013
[dart-lang/sdk#62168]: https://github.com/dart-lang/sdk/issues/62168
+[dart-lang/sdk#62216]: https://github.com/dart-lang/sdk/issues/62216
## 3.10.4
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/feature_computer.dart b/pkg/analysis_server/lib/src/services/completion/dart/feature_computer.dart
index 4f06b47..b047201 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/feature_computer.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/feature_computer.dart
@@ -627,7 +627,7 @@
DartType? visitBinaryExpression(BinaryExpression node) {
if (node.operator.end <= offset) {
if (node.operator.type == TokenType.EQ_EQ ||
- node.operator.type == TokenType.BANG_EQ_EQ) {
+ node.operator.type == TokenType.BANG_EQ) {
// TODO(kallentu): Fix the parser implementation where dot shorthand
// const constructor declarations recover with a wrapping function
// expression invocation and then remove this.
diff --git a/pkg/analysis_server/test/services/completion/dart/location/dot_shorthand_constructor_invocation_test.dart b/pkg/analysis_server/test/services/completion/dart/location/dot_shorthand_constructor_invocation_test.dart
index 3570eec..145f9e4 100644
--- a/pkg/analysis_server/test/services/completion/dart/location/dot_shorthand_constructor_invocation_test.dart
+++ b/pkg/analysis_server/test/services/completion/dart/location/dot_shorthand_constructor_invocation_test.dart
@@ -36,6 +36,44 @@
''');
}
+ Future<void> test_constructor_const_difference() async {
+ allowedIdentifiers = {'named', 'notConstant'};
+ await computeSuggestions('''
+class C {
+ const C.named();
+ C.notConstant();
+}
+void f() {
+ print(C() != const .^);
+}
+''');
+ assertResponse(r'''
+suggestions
+ named
+ kind: constructorInvocation
+''');
+ }
+
+ Future<void> test_constructor_const_difference_withPrefix() async {
+ allowedIdentifiers = {'named', 'notConstant'};
+ await computeSuggestions('''
+class C {
+ const C.named();
+ C.notConstant();
+}
+void f() {
+ print(C.named() != const .n^);
+}
+''');
+ assertResponse(r'''
+replacement
+ left: 1
+suggestions
+ named
+ kind: constructorInvocation
+''');
+ }
+
Future<void> test_constructor_const_equality() async {
allowedIdentifiers = {'named', 'notConstant'};
await computeSuggestions('''
diff --git a/pkg/analysis_server/test/src/services/completion/dart/feature_computer_test.dart b/pkg/analysis_server/test/src/services/completion/dart/feature_computer_test.dart
index 1355a25..075455f 100644
--- a/pkg/analysis_server/test/src/services/completion/dart/feature_computer_test.dart
+++ b/pkg/analysis_server/test/src/services/completion/dart/feature_computer_test.dart
@@ -505,6 +505,15 @@
''', 'String');
}
+ Future<void> test_dotShorthand_difference() async {
+ await assertContextType('''
+enum E { a }
+void f() {
+ if (E.a != .^) {}
+}
+''', 'E');
+ }
+
Future<void> test_dotShorthand_enumConstantCreation() async {
await assertContextType('''
enum E0 {
@@ -516,6 +525,15 @@
''', 'E0?');
}
+ Future<void> test_dotShorthand_equality() async {
+ await assertContextType('''
+enum E { a }
+void f() {
+ if (E.a == .^) {}
+}
+''', 'E');
+ }
+
Future<void> test_dotShorthand_guardedPattern_switchExpression() async {
await assertContextType('''
enum E { a }