Skip to content

Commit

Permalink
[Code completion] Make a few more suggestions ExecutableSuggestion.
Browse files Browse the repository at this point in the history
Change-Id: I0f44a22c998a9d08891666e845b55ea7664ed607
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387760
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
  • Loading branch information
keertip authored and Commit Queue committed Oct 1, 2024
1 parent e9e7616 commit 19eab32
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ final class ClosureSuggestion extends CandidateSuggestion {
}

/// The information about a candidate suggestion based on a constructor.
final class ConstructorSuggestion extends ImportableSuggestion
final class ConstructorSuggestion extends ExecutableSuggestion
implements ElementBasedSuggestion {
@override
final ConstructorElement element;
Expand Down Expand Up @@ -180,7 +180,11 @@ final class ConstructorSuggestion extends ImportableSuggestion
required this.isRedirect,
required this.suggestUnnamedAsNew,
required super.matcherScore,
}) : assert((isTearOff ? 1 : 0) | (isRedirect ? 1 : 0) < 2);
}) : assert((isTearOff ? 1 : 0) | (isRedirect ? 1 : 0) < 2),
super(
kind: isTearOff || isRedirect
? CompletionSuggestionKind.IDENTIFIER
: CompletionSuggestionKind.INVOCATION);

@override
String get completion {
Expand Down Expand Up @@ -273,7 +277,7 @@ sealed class ExecutableSuggestion extends ImportableSuggestion {
}

/// The information about a candidate suggestion based on an extension.
final class ExtensionSuggestion extends ImportableSuggestion
final class ExtensionSuggestion extends ExecutableSuggestion
implements ElementBasedSuggestion {
@override
final ExtensionElement element;
Expand All @@ -282,7 +286,8 @@ final class ExtensionSuggestion extends ImportableSuggestion
ExtensionSuggestion(
{required super.importData,
required this.element,
required super.matcherScore});
required super.matcherScore,
super.kind = CompletionSuggestionKind.INVOCATION});

@override
String get completion => '$completionPrefix${element.name!}';
Expand Down Expand Up @@ -997,24 +1002,17 @@ final class SuperParameterSuggestion extends CandidateSuggestion

/// The information about a candidate suggestion based on a top-level getter or
/// setter.
final class TopLevelFunctionSuggestion extends ImportableSuggestion
final class TopLevelFunctionSuggestion extends ExecutableSuggestion
implements ElementBasedSuggestion {
@override
final FunctionElement element;

/// The kind of suggestion to be made, either
/// [CompletionSuggestionKind.IDENTIFIER] or
/// [CompletionSuggestionKind.INVOCATION].
final CompletionSuggestionKind kind;

/// Initialize a newly created candidate suggestion to suggest the [element].
TopLevelFunctionSuggestion(
{required super.importData,
required this.element,
required this.kind,
required super.matcherScore})
: assert(kind == CompletionSuggestionKind.IDENTIFIER ||
kind == CompletionSuggestionKind.INVOCATION);
required super.kind,
required super.matcherScore});

@override
String get completion => '$completionPrefix${element.name}';
Expand Down Expand Up @@ -1155,9 +1153,7 @@ extension SuggestionBuilderExtension on SuggestionBuilder {
suggestConstructor(suggestion.element,
hasClassName: suggestion.hasClassName,
completion: completion,
kind: suggestion.isRedirect || suggestion.isTearOff
? CompletionSuggestionKind.IDENTIFIER
: CompletionSuggestionKind.INVOCATION,
kind: suggestion.kind,
prefix: suggestion.prefix,
suggestUnnamedAsNew: suggestion.suggestUnnamedAsNew,
relevance: relevance);
Expand All @@ -1174,7 +1170,9 @@ extension SuggestionBuilderExtension on SuggestionBuilder {
}
case ExtensionSuggestion():
suggestExtension(suggestion.element,
prefix: suggestion.prefix, relevance: relevance);
prefix: suggestion.prefix,
relevance: relevance,
kind: suggestion.kind);
case ExtensionTypeSuggestion():
suggestInterface(suggestion.element,
prefix: suggestion.prefix, relevance: relevance);
Expand Down Expand Up @@ -1219,9 +1217,11 @@ extension SuggestionBuilderExtension on SuggestionBuilder {
case LoadLibraryFunctionSuggestion():
suggestLoadLibraryFunction(
suggestion.element,
kind: suggestion.kind,
);
case LocalFunctionSuggestion():
suggestTopLevelFunction(suggestion.element, relevance: relevance);
suggestTopLevelFunction(suggestion.element,
relevance: relevance, kind: suggestion.kind);
case LocalVariableSuggestion():
suggestLocalVariable(
element: suggestion.element,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,14 +470,15 @@ class SuggestionBuilder {

/// Add a suggestion for the `loadLibrary` [function] associated with a
/// prefix.
void suggestLoadLibraryFunction(FunctionElement function) {
void suggestLoadLibraryFunction(FunctionElement function,
{CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION}) {
// TODO(brianwilkerson): This might want to use the context type rather than
// a fixed value.
var relevance = Relevance.loadLibrary;
_addBuilder(
_createCompletionSuggestionBuilder(
function,
kind: CompletionSuggestionKind.INVOCATION,
kind: kind,
relevance: relevance,
isNotImported: isNotImportedLibrary,
),
Expand Down

0 comments on commit 19eab32

Please sign in to comment.