Skip to content

Commit c22dc20

Browse files
bwilkersoncommit-bot@chromium.org
authored andcommitted
Use the const-ness of an element when completing in a const context using available declarations
Change-Id: Ia950ad81ed571cbcf1f0060da0cba26406206ad1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151031 Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent b907f99 commit c22dc20

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ class DartCompletionManager implements CompletionContributor {
266266
void _addIncludedSuggestionRelevanceTags(DartCompletionRequestImpl request) {
267267
var target = request.target;
268268

269+
if (request.inConstantContext && request.useNewRelevance) {
270+
includedSuggestionRelevanceTags.add(IncludedSuggestionRelevanceTag(
271+
'isConst', RelevanceBoost.constInConstantContext));
272+
}
273+
269274
void addTypeTag(DartType type) {
270275
if (type is InterfaceType) {
271276
var element = type.element;

pkg/analyzer/lib/src/services/available_declarations.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,9 @@ class _File {
13331333
if (Identifier.isPrivateName(name.name)) {
13341334
return null;
13351335
}
1336+
if (isConst) {
1337+
relevanceTags = [...?relevanceTags, 'isConst'];
1338+
}
13361339

13371340
var locationOffset = name.offset;
13381341
var lineLocation = lineInfo.getLocation(locationOffset);

pkg/analyzer/test/src/services/available_declarations_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ class C {
12101210
DeclarationKind.FIELD,
12111211
isConst: true,
12121212
isStatic: true,
1213-
relevanceTags: ['dart:core::int'],
1213+
relevanceTags: ['dart:core::int', 'isConst'],
12141214
returnType: 'int',
12151215
);
12161216
_assertDeclaration(
@@ -2419,7 +2419,7 @@ final double e = 2.7;
24192419
'd',
24202420
DeclarationKind.VARIABLE,
24212421
isConst: true,
2422-
relevanceTags: ['dart:core::int'],
2422+
relevanceTags: ['dart:core::int', 'isConst'],
24232423
returnType: '',
24242424
);
24252425
_assertDeclaration(

pkg/analyzer_plugin/lib/utilities/completion/relevance.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,8 @@ abstract class RelevanceBoost {
102102
/// The relevance boost used when suggesting an enum constant from an
103103
/// available declaration set.
104104
static const int availableEnumConstant = 100;
105+
106+
/// The relevance boost used when suggesting a constant value / constructor
107+
/// from an available declaration set in a constant context.
108+
static const int constInConstantContext = 200;
105109
}

0 commit comments

Comments
 (0)