[analysis_server] Exclude obvious Enum value access from Inline Values
Fixes https://github.com/Dart-Code/Dart-Code/issues/5444
Change-Id: I92bf301236e97682269e2284f2602ceb5f83619f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415861
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/lib/src/lsp/handlers/handler_inline_value.dart b/pkg/analysis_server/lib/src/lsp/handlers/handler_inline_value.dart
index 4900b76..f3c43df 100644
--- a/pkg/analysis_server/lib/src/lsp/handlers/handler_inline_value.dart
+++ b/pkg/analysis_server/lib/src/lsp/handlers/handler_inline_value.dart
@@ -243,7 +243,13 @@
// Never produce values for the left side of a property access.
var isTarget = parent is PropertyAccess && node == parent.realTarget;
- if (!isTarget) {
+
+ // Never produce values for obvious enum getters (this includes `values`).
+ var isEnumGetter =
+ node.element is GetterElement &&
+ node.element?.enclosingElement2 is EnumElement2;
+
+ if (!isTarget && !isEnumGetter) {
collector.recordExpression(node.element, node.offset, node.length);
}
}
diff --git a/pkg/analysis_server/test/lsp/inline_value_test.dart b/pkg/analysis_server/test/lsp/inline_value_test.dart
index d61f50f..33ae233 100644
--- a/pkg/analysis_server/test/lsp/inline_value_test.dart
+++ b/pkg/analysis_server/test/lsp/inline_value_test.dart
@@ -114,6 +114,48 @@
);
}
+ Future<void> test_property_getter_enum_value_excluded() async {
+ experimentalInlineValuesProperties = true;
+
+ code = TestCode.parse(r'''
+enum MyEnum {
+ one,
+}
+
+void f(MyEnum x) {
+ print(/*[0*/x/*0]*/ == MyEnum.one); // MyEnum.one excluded
+ print(/*[1*/MyEnum.one.index/*1]*/);
+ ^
+}
+''');
+
+ await verify_values(
+ code,
+ ofTypes: {
+ 0: InlineValueVariableLookup,
+ 1: InlineValueEvaluatableExpression,
+ },
+ );
+ }
+
+ Future<void> test_property_getter_enum_values_excluded() async {
+ experimentalInlineValuesProperties = true;
+
+ code = TestCode.parse(r'''
+enum MyEnum {
+ one,
+}
+
+void f() {
+ print(MyEnum.values); // MyEnum.values excluded
+ print(/*[0*/MyEnum.values.length/*0]*/);
+ ^
+}
+''');
+
+ await verify_values(code, ofType: InlineValueEvaluatableExpression);
+ }
+
Future<void> test_property_method() async {
experimentalInlineValuesProperties = true;