Skip to content

Commit

Permalink
[Element.migrate] Migrate CompletionState
Browse files Browse the repository at this point in the history
Change-Id: I08bb8ffc4fa079d1f5b126af5de3101673f1be55
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/396520
Reviewed-by: Brian Wilkerson <[email protected]>
Commit-Queue: Keerti Parthasarathy <[email protected]>
  • Loading branch information
keertip authored and Commit Queue committed Nov 20, 2024
1 parent 1af77fa commit f6e4b3e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
1 change: 0 additions & 1 deletion pkg/analysis_server/analyzer_use_new_elements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ lib/src/protocol_server.dart
lib/src/search/element_references.dart
lib/src/search/type_hierarchy.dart
lib/src/services/completion/dart/completion_manager.dart
lib/src/services/completion/dart/completion_state.dart
lib/src/services/completion/dart/declaration_helper.dart
lib/src/services/completion/dart/feature_computer.dart
lib/src/services/completion/dart/identifier_helper.dart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:analysis_server_plugin/src/utilities/selection.dart';
import 'package:analyzer/dart/analysis/code_style_options.dart';
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/utilities/completion_matcher.dart';

Expand Down Expand Up @@ -58,7 +58,7 @@ class CompletionState {
}

/// The element of the library containing the completion location.
LibraryElement get libraryElement => request.libraryElement;
LibraryElement2 get libraryElement => request.libraryElement2;

/// The type of quotes preferred for [String]s as specified in [CodeStyleOptions].
String get preferredQuoteForStrings =>
Expand All @@ -75,19 +75,19 @@ class CompletionState {
while (node != null) {
switch (node) {
case ClassDeclaration():
var element = node.declaredElement;
var element = node.declaredFragment?.element;
if (element != null) {
return element.thisType;
}
case EnumDeclaration():
var element = node.declaredElement;
var element = node.declaredFragment?.element;
if (element != null) {
return element.thisType;
}
case ExtensionDeclaration():
return node.onClause?.extendedType.type;
case MixinDeclaration():
var element = node.declaredElement;
var element = node.declaredFragment?.element;
if (element != null) {
return element.thisType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ class IdentifierHelper {
if (candidateName == null) {
return;
}
for (var unit in state.libraryElement.units) {
for (var childElement in unit.children) {
if (childElement.name == candidateName) {
for (var childElement in state.libraryElement.children2) {
if (childElement.name3 == candidateName) {
// Don't suggest a name that's already declared in the library.
return;
}
}
}
var matcherScore = state.matcher.score(candidateName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
if (constructorElement == null) {
return;
}
var libraryElement = state.libraryElement;
var libraryElement = state.libraryElement.asElement as LibraryElement;
declarationHelper(
mustBeConstant: constructorElement.isConst,
).addPossibleRedirectionsInLibrary(constructorElement, libraryElement);
Expand Down

0 comments on commit f6e4b3e

Please sign in to comment.