Skip to content

Commit 769cfb3

Browse files
bwilkersonCommit Queue
authored and
Commit Queue
committed
Use the budget to control whether overrides are suggested
I believe that this is the right thing to do from a UX perspective, but this change could potentially cause flakiness in tests. There's support in the LSP path for setting a bigger budget, but not for legacy based tests (at least not yet). Change-Id: I76353fd3e4cb4cf8fb7a55c27a3353415143dc06 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/360740 Reviewed-by: Keerti Parthasarathy <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent c6a82eb commit 769cfb3

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class DartCompletionManager {
159159
if (selection == null) {
160160
throw AbortCompletion();
161161
}
162-
var state = CompletionState(request, selection);
162+
var state = CompletionState(request, selection, budget);
163163
var pass = InScopeCompletionPass(
164164
state: state,
165165
collector: collector,

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,41 @@ class CompletionState {
1414
/// The completion request being processed.
1515
final DartCompletionRequest request;
1616

17-
/// The selection at the time completion was requested. The selection is
18-
/// required to have a length of zero.
17+
/// The selection at the time completion was requested.
18+
///
19+
/// The selection is required to have a length of zero.
1920
final Selection selection;
2021

22+
/// The budget controlling how much time can be spent computing completion
23+
/// suggestions.
24+
final CompletionBudget budget;
25+
2126
/// Initialize a newly created completion state.
22-
CompletionState(this.request, this.selection) : assert(selection.length == 0);
27+
CompletionState(this.request, this.selection, this.budget)
28+
: assert(selection.length == 0);
2329

24-
/// Returns the type of value required by the context in which completion was
30+
/// The type of value required by the context in which completion was
2531
/// requested.
2632
DartType? get contextType => request.contextType;
2733

28-
/// Return the [ClassMember] that encloses the completion location, or `null`
29-
/// if the completion location isn't in a class member.
34+
/// The [ClassMember] that encloses the completion location, or `null` if the
35+
/// completion location isn't in a class member.
3036
ClassMember? get enclosingMember {
3137
return selection.coveringNode.thisOrAncestorOfType<ClassMember>();
3238
}
3339

34-
/// Return `true` if the completion location is inside an instance member, and
35-
/// hence there is a binding for `this`.
40+
/// Whether the completion location is inside an instance member, and hence
41+
/// whether there is a binding for `this`.
3642
bool get inInstanceScope {
3743
var member = enclosingMember;
3844
return member != null && !member.isStatic;
3945
}
4046

41-
/// Returns the element of the library containing the completion location.
47+
/// The element of the library containing the completion location.
4248
LibraryElement get libraryElement => request.libraryElement;
4349

44-
/// Return the type of `this` at the completion location, or `null`
45-
/// if the completion location doesn't allow `this` to be used.
50+
/// The type of `this` at the completion location, or `null` if the completion
51+
/// location doesn't allow `this` to be used.
4652
DartType? get thisType {
4753
AstNode? node = selection.coveringNode;
4854
while (node != null) {
@@ -70,16 +76,16 @@ class CompletionState {
7076
return null;
7177
}
7278

73-
/// Return `true` if the given `feature` is enabled in the library containing
74-
/// the selection.
79+
/// Whether the given `feature` is enabled in the library containing the
80+
/// selection.
7581
bool isFeatureEnabled(Feature feature) {
7682
return libraryElement.featureSet.isEnabled(feature);
7783
}
7884
}
7985

8086
// TODO(brianwilkerson): Move to 'package:analysis_server/src/utilities/extensions/ast.dart'
8187
extension on ClassMember {
82-
/// Return `true` if this member is a static member.
88+
/// Whether this member is a static member.
8389
bool get isStatic {
8490
var self = this;
8591
if (self is MethodDeclaration) {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3468,8 +3468,10 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
34683468
required InterfaceElement? element,
34693469
bool skipAt = false,
34703470
}) {
3471-
// TODO(brianwilkerson): Check whether there's sufficient remaining time
3472-
// before computing suggestions for overrides.
3471+
if (state.budget.isEmpty) {
3472+
// Don't suggest overrides if the time budget has already been spent.
3473+
return;
3474+
}
34733475
if (suggestOverrides && element != null) {
34743476
overrideHelper.computeOverridesFor(
34753477
interfaceElement: element,

0 commit comments

Comments
 (0)