Some minor clean-up separated to make the next CL shorter
Change-Id: I6bbfe3903c19dd9fe792647c725b0488eddb52d4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363181
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/candidate_suggestion.dart b/pkg/analysis_server/lib/src/services/completion/dart/candidate_suggestion.dart
index ca064bb..eb75b76 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/candidate_suggestion.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/candidate_suggestion.dart
@@ -25,8 +25,13 @@
CandidateSuggestion({required this.score}) : assert(score >= 0);
- /// Return the text to be inserted by the completion suggestion.
+ /// The text to be inserted by the completion suggestion.
String get completion;
+
+ @override
+ String toString() {
+ return completion;
+ }
}
/// The information about a candidate suggestion based on a class.
@@ -257,7 +262,12 @@
ImportableSuggestion({required this.importData, required super.score});
- String get completionPrefix => prefix == null ? '' : '$prefix.';
+ /// The text to add before the name of the element when it is being imported
+ /// using an import prefix.
+ String get completionPrefix {
+ var prefixName = prefix;
+ return prefixName == null ? '' : '$prefixName.';
+ }
/// The URI of the library from which the suggested element would be imported.
String? get libraryUriStr => importData?.libraryUriStr;
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/in_scope_completion_pass.dart b/pkg/analysis_server/lib/src/services/completion/dart/in_scope_completion_pass.dart
index 8ca7c94..075b4f0 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/in_scope_completion_pass.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/in_scope_completion_pass.dart
@@ -89,18 +89,18 @@
required this.suggestUris,
});
- /// Return the feature set that applies to the library for which completions
- /// are being computed.
+ /// The feature set that applies to the library for which completions are
+ /// being computed.
FeatureSet get featureSet => state.libraryElement.featureSet;
- /// Return the offset at which completion was requested.
+ /// The offset at which completion was requested.
int get offset => state.selection.offset;
- /// Returns the visibility tracker used by this pass.
+ /// The visibility tracker used by this pass.
VisibilityTracker? get visibilityTracker =>
_declarationHelper?.visibilityTracker;
- /// Return the node that should be used as the context in which completion is
+ /// The node that should be used as the context in which completion is
/// occurring.
///
/// This is normally the covering node, but if the covering node begins with
@@ -144,7 +144,7 @@
return child;
}
- /// Compute the candidate suggestions associated with this pass.
+ /// Computes the candidate suggestions associated with this pass.
void computeSuggestions() {
// TODO(brianwilkerson): The cursor could be inside a non-documentation
// comment inside the completion node. We need to check for this case and
@@ -153,7 +153,7 @@
completionNode.accept(this);
}
- /// Return the helper used to suggest declarations that are in scope.
+ /// Returns the helper used to suggest declarations that are in scope.
DeclarationHelper declarationHelper({
bool mustBeAssignable = false,
bool mustBeConstant = false,
@@ -2916,12 +2916,13 @@
return null;
}
- /// Add the suggestions that are appropriate at the beginning of an annotation.
+ /// Adds the suggestions that are appropriate at the beginning of an
+ /// annotation.
void _forAnnotation(AstNode node) {
declarationHelper(mustBeConstant: true).addLexicalDeclarations(node);
}
- /// Add the suggestions that are appropriate when the selection is at the
+ /// Adds the suggestions that are appropriate when the selection is at the
/// beginning of a member of a class, enum, extension, extension type, or
/// mixin.
void _forClassLikeMember(AstNode node) {
@@ -2939,7 +2940,7 @@
}
}
- /// Add the suggestions that are appropriate when the selection is at the
+ /// Adds the suggestions that are appropriate when the selection is at the
/// beginning of a class member.
void _forClassMember(ClassDeclaration node) {
keywordHelper.addClassMemberKeywords();
@@ -2949,7 +2950,7 @@
);
}
- /// Add the suggestions that are appropriate when the selection is at the
+ /// Adds the suggestions that are appropriate when the selection is at the
/// beginning of an element in a collection [literal], with the given
/// [elements].
void _forCollectionElement(
@@ -2963,7 +2964,7 @@
.addLexicalDeclarations(precedingElement ?? literal);
}
- /// Add the suggestions that are appropriate when completing in the given
+ /// Adds the suggestions that are appropriate when completing in the given
/// [combinator] and the [existingNames] are in the list.
void _forCombinator(
Combinator combinator, NodeList<SimpleIdentifier> existingNames) {
@@ -2988,14 +2989,14 @@
.addFromLibrary(library, excludedNames);
}
- /// Add the suggestions that are appropriate when the selection is at the
+ /// Adds the suggestions that are appropriate when the selection is at the
/// beginning of a top-level declaration.
void _forCompilationUnitDeclaration(CompilationUnit unit) {
keywordHelper.addCompilationUnitDeclarationKeywords();
declarationHelper(mustBeType: true).addLexicalDeclarations(unit);
}
- /// Add the suggestions that are appropriate when the selection is at the
+ /// Adds the suggestions that are appropriate when the selection is at the
/// beginning of a member at the top-level of a compilation unit.
void _forCompilationUnitMember(CompilationUnit unit,
({AstNode? before, AstNode? after}) surroundingMembers) {
@@ -3010,7 +3011,7 @@
}
}
- /// Add the suggestions that are appropriate when the user is completing
+ /// Adds the suggestions that are appropriate when the user is completing
/// immediately before the given [member].
void _forCompilationUnitMemberBefore(AstNode member) {
if (member.parent case CompilationUnit unit) {
@@ -3018,7 +3019,7 @@
}
}
- /// Add the suggestions that are appropriate when the selection is at the
+ /// Adds the suggestions that are appropriate when the selection is at the
/// beginning of a constant expression. The [node] provides context to
/// determine which keywords to include.
void _forConstantExpression(AstNode node) {
@@ -3029,7 +3030,7 @@
.addLexicalDeclarations(node);
}
- /// Add the suggestions that are appropriate when the selection is at the
+ /// Adds the suggestions that are appropriate when the selection is at the
/// beginning of a constructor's initializer.
void _forConstructorInitializer(ConstructorDeclaration constructor,
ConstructorFieldInitializer? initializer) {
@@ -3042,21 +3043,21 @@
declarationHelper().addFieldsForInitializers(constructor, field);
}
- /// Add the suggestions that are appropriate when the selection is at the
+ /// Adds the suggestions that are appropriate when the selection is at the
/// beginning of a directive. The [before] directive is the directive before
/// the one being added.
void _forDirective(CompilationUnit unit, Directive? before) {
keywordHelper.addDirectiveKeywords(unit, before);
}
- /// Add the suggestions that are appropriate when the selection is at the
+ /// Adds the suggestions that are appropriate when the selection is at the
/// beginning of an enum member.
void _forEnumMember(EnumDeclaration node) {
keywordHelper.addEnumMemberKeywords();
declarationHelper(mustBeType: true).addLexicalDeclarations(node);
}
- /// Add the suggestions that are appropriate when the selection is at the
+ /// Adds the suggestions that are appropriate when the selection is at the
/// beginning of an expression. The [node] provides context to determine which
/// keywords to include.
void _forExpression(AstNode node,
@@ -3074,21 +3075,21 @@
.addLexicalDeclarations(node);
}
- /// Add the suggestions that are appropriate when the selection is at the
+ /// Adds the suggestions that are appropriate when the selection is at the
/// beginning of an extension member.
void _forExtensionMember(ExtensionDeclaration node) {
keywordHelper.addExtensionMemberKeywords(isStatic: false);
declarationHelper(mustBeType: true).addLexicalDeclarations(node);
}
- /// Add the suggestions that are appropriate when the selection is at the
+ /// Adds the suggestions that are appropriate when the selection is at the
/// beginning of an extension type member.
void _forExtensionTypeMember(ExtensionTypeDeclaration node) {
keywordHelper.addExtensionTypeMemberKeywords(isStatic: false);
declarationHelper(mustBeType: true).addLexicalDeclarations(node);
}
- /// Return `true` if the preceding member is incomplete and no other
+ /// Returns `true` if the preceding member is incomplete and no other
/// suggestions should be offered.
///
/// If the completion offset is within the first token of the given [member],
@@ -3118,7 +3119,7 @@
return false;
}
- /// Return `true` if the preceding statement is incomplete and no other
+ /// Returns `true` if the preceding statement is incomplete and no other
/// suggestions should be offered.
///
/// If the completion offset is within the first token of the given
@@ -3368,7 +3369,7 @@
// _addTypesInScope();
}
- /// Return `true` if the [precedingMember] is incomplete.
+ /// Returns `true` if the [precedingMember] is incomplete.
///
/// If it's incomplete, assume that the user is attempting to complete it and
/// offer appropriate suggestions.
@@ -3419,7 +3420,7 @@
return false;
}
- /// Return `true` if the given [expression] is the result of recovery and
+ /// Returns `true` if the given [expression] is the result of recovery and
/// suggestions have already been produced.
///
/// The parser recovers from a parenthesized list in an argument list by
@@ -3447,7 +3448,7 @@
return false;
}
- /// Return `true` if the given [declaration] is the result of recovery and
+ /// Returns `true` if the given [declaration] is the result of recovery and
/// suggestions have already been produced.
///
/// The parser recovers from a simple identifier by assuming that it's a
@@ -3477,7 +3478,10 @@
return false;
}
- /// If allowed, suggest overrides in the context of the given [element].
+ /// Suggests overrides in the context of the given [element].
+ ///
+ /// If the budget has been exceeded, then the results are marked as incomplete
+ /// and no suggestions are added.
void _suggestOverridesFor({
required InterfaceElement? element,
bool skipAt = false,
@@ -3545,8 +3549,9 @@
}
}
- /// Check for typing `@override` inside a class body, before `}`.
- /// There is no node, recover using tokens.
+ /// Checks for typing `@override` inside a class body, before `}`.
+ ///
+ /// There is no node, so this recover using tokens.
bool _tryAnnotationAtEndOfClassBody(Declaration node) {
var displaced = state.request.target.entity;
if (displaced is Token && displaced.type == TokenType.CLOSE_CURLY_BRACKET) {
@@ -3562,7 +3567,7 @@
return false;
}
- /// If [identifier] at `@` is a start of `@override`, suggest overrides.
+ /// Suggests an override if the [identifier] at `@` is a start of `@override`.
void _tryOverrideAnnotation(Token identifier, Declaration node) {
var lexeme = identifier.lexeme;
if (lexeme.isNotEmpty && 'override'.startsWith(lexeme)) {
@@ -3597,8 +3602,8 @@
}
}
- /// If the completion offset is at or before the offset of the [node], then
- /// visit the parent of the node.
+ /// Visits the parent of the node if the completion offset is at or before the
+ /// offset of the [node].
void _visitParentIfAtOrBeforeNode(AstNode node) {
if (offset <= node.offset) {
node.parent?.accept(this);
@@ -3636,7 +3641,7 @@
return true;
}
- /// Return `true` if the [child] is an element in a list of children of this
+ /// Returns `true` if the [child] is an element in a list of children of this
/// node.
bool isChildInList(AstNode child) {
return switch (this) {
@@ -3735,7 +3740,7 @@
}
extension on ClassMember {
- /// Return the member before `this`, or `null` if this is the first member in
+ /// Returns the member before `this`, or `null` if this is the first member in
/// the body.
ClassMember? get precedingMember {
final parent = this.parent;
@@ -3847,7 +3852,7 @@
}
extension on CompilationUnit {
- /// Return a record whose fields are the members in this compilation unit
+ /// Returns a record whose fields are the members in this compilation unit
/// that are lexically immediately before and after the given [member].
({AstNode? before, AstNode? after}) membersBeforeAndAfterMember(
AstNode? member) {
@@ -3865,7 +3870,7 @@
return (before: before, after: after);
}
- /// Return a record whose fields are the members in this compilation unit
+ /// Returns a record whose fields are the members in this compilation unit
/// that are lexically immediately before and after the given [offset].
({AstNode? before, AstNode? after}) membersBeforeAndAfterOffset(int offset) {
var members = sortedDirectivesAndDeclarations;
@@ -4002,8 +4007,8 @@
}
extension on Statement {
- /// Return the statement before `this`, or `null` if this is the first statement in
- /// the block.
+ /// Returns the statement before `this`, or `null` if this is the first
+ /// statement in the block.
Statement? get precedingStatement {
final parent = this.parent;
if (parent is! Block) {
@@ -4019,7 +4024,7 @@
}
extension on SyntacticEntity? {
- /// Return `true` if the receiver covers the [offset].
+ /// Returns `true` if the receiver covers the [offset].
bool coversOffset(int offset) {
var self = this;
return self != null && self.offset <= offset && self.end >= offset;