@@ -16,11 +16,9 @@ import 'package:analysis_server/src/services/completion/dart/utilities.dart';
1616import 'package:analysis_server/src/utilities/extensions/ast.dart' ;
1717import 'package:analysis_server/src/utilities/extensions/element.dart' ;
1818import 'package:analysis_server/src/utilities/extensions/string.dart' ;
19- import 'package:analyzer/dart/element/element.dart' ;
2019import 'package:analyzer/dart/element/element2.dart' ;
2120import 'package:analyzer/source/line_info.dart' as server;
2221import 'package:analyzer/src/dartdoc/dartdoc_directive_info.dart' ;
23- import 'package:analyzer/src/utilities/extensions/element.dart' ;
2422import 'package:analyzer_plugin/src/utilities/client_uri_converter.dart' ;
2523import 'package:analyzer_plugin/src/utilities/documentation.dart' ;
2624import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart' ;
@@ -127,13 +125,14 @@ Future<lsp.CompletionItem?> toLspCompletionItem(
127125 // functions but they should not be included in the completions.
128126 var element =
129127 suggestion is ElementBasedSuggestion
130- ? (suggestion as ElementBasedSuggestion ).element.asElement
128+ ? (suggestion as ElementBasedSuggestion ).element
131129 : null ;
132130 var isCallable =
133131 element != null &&
134- (element is ConstructorElement ||
135- element is FunctionElement ||
136- element is MethodElement );
132+ (element is ConstructorElement2 ||
133+ element is LocalFunctionElement ||
134+ element is TopLevelFunctionElement ||
135+ element is MethodElement2 );
137136 var isInvocation =
138137 (suggestion is ExecutableSuggestion &&
139138 suggestion.kind == server.CompletionSuggestionKind .INVOCATION ) ||
@@ -191,7 +190,7 @@ Future<lsp.CompletionItem?> toLspCompletionItem(
191190 var colorPreviewHex =
192191 capabilities.completionItemKinds.contains (lsp.CompletionItemKind .Color ) &&
193192 suggestion is ElementBasedSuggestion
194- ? server.getColorHexString (element)
193+ ? server.getColorHexString2 (element)
195194 : null ;
196195
197196 var completionKind =
@@ -382,7 +381,7 @@ lsp.CompletionItemKind? _candidateToCompletionItemKind(
382381
383382 if (suggestion is ElementBasedSuggestion ) {
384383 return _elementToCompletionItemKind (
385- (suggestion as ElementBasedSuggestion ).element.asElement ! ,
384+ (suggestion as ElementBasedSuggestion ).element,
386385 supportedCompletionKinds,
387386 ).firstWhereOrNull (isSupported);
388387 }
@@ -430,30 +429,28 @@ lsp.CompletionItemKind? _candidateToCompletionItemKind(
430429 return getCompletionKind ().firstWhereOrNull (isSupported);
431430}
432431
433- /// Get the [lsp.CompletionItemKind] based on the [Element] for an [ElementBasedSuggestion] .
432+ /// Get the [lsp.CompletionItemKind] based on the [Element2] for
433+ /// an [ElementBasedSuggestion] .
434434List <lsp.CompletionItemKind > _elementToCompletionItemKind (
435- Element element,
435+ Element2 element,
436436 Set <lsp.CompletionItemKind > supportedCompletionKinds,
437437) {
438- if (element is ClassElement ) {
438+ if (element is ClassElement2 ) {
439439 return const [lsp.CompletionItemKind .Class ];
440440 }
441- if (element is CompilationUnitElement ) {
442- return const [lsp.CompletionItemKind .File , lsp.CompletionItemKind .Module ];
443- }
444- if (element is ConstructorElement ) {
441+ if (element is ConstructorElement2 ) {
445442 return const [lsp.CompletionItemKind .Constructor ];
446443 }
447- if (element is EnumElement ) {
444+ if (element is EnumElement2 ) {
448445 return const [lsp.CompletionItemKind .Enum ];
449446 }
450- if (element is ExtensionElement ) {
447+ if (element is ExtensionElement2 ) {
451448 return const [lsp.CompletionItemKind .Method ];
452449 }
453- if (element is ExtensionTypeElement ) {
450+ if (element is ExtensionTypeElement2 ) {
454451 return const [lsp.CompletionItemKind .Class ];
455452 }
456- if (element is FieldElement ) {
453+ if (element is FieldElement2 ) {
457454 if (element.isEnumConstant) {
458455 return const [
459456 lsp.CompletionItemKind .EnumMember ,
@@ -462,40 +459,43 @@ List<lsp.CompletionItemKind> _elementToCompletionItemKind(
462459 }
463460 return const [lsp.CompletionItemKind .Field ];
464461 }
465- if (element is FunctionElement ) {
462+ if (element is LocalFunctionElement ) {
466463 return const [lsp.CompletionItemKind .Function ];
467464 }
468- if (element is LabelElement ) {
465+ if (element is TopLevelFunctionElement ) {
466+ return const [lsp.CompletionItemKind .Function ];
467+ }
468+ if (element is LabelElement2 ) {
469469 return const [lsp.CompletionItemKind .Text ];
470470 }
471- if (element is LibraryElement ) {
471+ if (element is LibraryElement2 ) {
472472 return const [lsp.CompletionItemKind .Module ];
473473 }
474- if (element is LocalVariableElement ) {
474+ if (element is LocalVariableElement2 ) {
475475 return const [lsp.CompletionItemKind .Variable ];
476476 }
477- if (element is MethodElement ) {
477+ if (element is MethodElement2 ) {
478478 return const [lsp.CompletionItemKind .Method ];
479479 }
480- if (element is MixinElement ) {
480+ if (element is MixinElement2 ) {
481481 return const [lsp.CompletionItemKind .Class ];
482482 }
483- if (element is ParameterElement ) {
483+ if (element is FormalParameterElement ) {
484484 return const [lsp.CompletionItemKind .Variable ];
485485 }
486- if (element is PrefixElement ) {
486+ if (element is PrefixElement2 ) {
487487 return const [lsp.CompletionItemKind .Variable ];
488488 }
489- if (element is PropertyAccessorElement ) {
489+ if (element is PropertyAccessorElement2 ) {
490490 return const [lsp.CompletionItemKind .Property ];
491491 }
492- if (element is TopLevelVariableElement ) {
492+ if (element is TopLevelVariableElement2 ) {
493493 return const [lsp.CompletionItemKind .Variable ];
494494 }
495- if (element is TypeAliasElement ) {
495+ if (element is TypeAliasElement2 ) {
496496 return const [lsp.CompletionItemKind .Class ];
497497 }
498- if (element is TypeParameterElement ) {
498+ if (element is TypeParameterElement2 ) {
499499 return const [
500500 lsp.CompletionItemKind .TypeParameter ,
501501 lsp.CompletionItemKind .Variable ,
@@ -623,13 +623,11 @@ String _getDisplayText(
623623
624624/// If the [element] has a documentation comment, return it.
625625_ElementDocumentation ? _getDocsFromComputer (
626- Element element,
626+ Element2 element,
627627 DartCompletionRequest request,
628628) {
629- var element2 = element.asElement2;
630- if (element2 == null ) return null ;
631629 var doc = request.documentationComputer.compute (
632- element2 ,
630+ element ,
633631 includeSummary: true ,
634632 );
635633 if (doc is DocumentationWithSummary ) {
@@ -647,7 +645,7 @@ String? _getDocumentation(
647645 DartCompletionRequest request,
648646 DocumentationPreference includeDocumentation,
649647) {
650- var docs = _getDocsFromComputer (element.asElement ! , request);
648+ var docs = _getDocsFromComputer (element, request);
651649
652650 var doc = removeDartDocDelimiters (docs? .full);
653651 var rawDoc =
0 commit comments