Port a missed piece to remove invalid reference to analysis_server

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2930723002 .
This commit is contained in:
Brian Wilkerson 2017-06-07 10:06:31 -07:00
parent dce88b45e7
commit 9b0a98fd42
2 changed files with 119 additions and 16 deletions

View file

@ -0,0 +1,114 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analysis_server/src/protocol_server.dart' as protocol;
import 'package:analysis_server/src/protocol_server.dart'
hide Element, ElementKind;
import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer_plugin/src/utilities/completion/suggestion_builder.dart';
/**
* Common mixin for sharing behavior.
*/
abstract class ElementSuggestionBuilder {
// Copied from analysis_server/lib/src/services/completion/dart/suggestion_builder.dart
/**
* A collection of completion suggestions.
*/
final List<CompletionSuggestion> suggestions = <CompletionSuggestion>[];
/**
* A set of existing completions used to prevent duplicate suggestions.
*/
final Set<String> _completions = new Set<String>();
/**
* A map of element names to suggestions for synthetic getters and setters.
*/
final Map<String, CompletionSuggestion> _syntheticMap =
<String, CompletionSuggestion>{};
/**
* Return the library in which the completion is requested.
*/
LibraryElement get containingLibrary;
/**
* Return the kind of suggestions that should be built.
*/
CompletionSuggestionKind get kind;
/**
* Return the resource provider used to access the file system.
*/
ResourceProvider get resourceProvider;
/**
* Add a suggestion based upon the given element.
*/
void addSuggestion(Element element,
{String prefix, int relevance: DART_RELEVANCE_DEFAULT}) {
if (element.isPrivate) {
if (element.library != containingLibrary) {
return;
}
}
String completion = element.displayName;
if (prefix != null && prefix.length > 0) {
if (completion == null || completion.length <= 0) {
completion = prefix;
} else {
completion = '$prefix.$completion';
}
}
if (completion == null || completion.length <= 0) {
return;
}
SuggestionBuilderImpl builder = new SuggestionBuilderImpl(resourceProvider);
CompletionSuggestion suggestion = builder.forElement(element,
completion: completion, kind: kind, relevance: relevance);
if (suggestion != null) {
if (element.isSynthetic && element is PropertyAccessorElement) {
String cacheKey;
if (element.isGetter) {
cacheKey = element.name;
}
if (element.isSetter) {
cacheKey = element.name;
cacheKey = cacheKey.substring(0, cacheKey.length - 1);
}
if (cacheKey != null) {
CompletionSuggestion existingSuggestion = _syntheticMap[cacheKey];
// Pair getter/setter by updating the existing suggestion
if (existingSuggestion != null) {
CompletionSuggestion getter =
element.isGetter ? suggestion : existingSuggestion;
protocol.ElementKind elemKind =
element.enclosingElement is ClassElement
? protocol.ElementKind.FIELD
: protocol.ElementKind.TOP_LEVEL_VARIABLE;
existingSuggestion.element = new protocol.Element(
elemKind,
existingSuggestion.element.name,
existingSuggestion.element.flags,
location: getter.element.location,
typeParameters: getter.element.typeParameters,
parameters: null,
returnType: getter.returnType);
return;
}
// Cache lone getter/setter so that it can be paired
_syntheticMap[cacheKey] = suggestion;
}
}
if (_completions.add(suggestion.completion)) {
suggestions.add(suggestion);
}
}
}
}

View file

@ -4,13 +4,14 @@
import 'dart:async';
import 'package:analysis_server/src/services/completion/dart/suggestion_builder.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/standard_resolution_map.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer_plugin/protocol/protocol_common.dart' hide Element;
import 'package:analyzer_plugin/src/utilities/completion/completion_target.dart';
import 'package:analyzer_plugin/src/utilities/completion/element_suggestion_builder.dart';
import 'package:analyzer_plugin/src/utilities/completion/optype.dart';
import 'package:analyzer_plugin/utilities/completion/completion_core.dart';
@ -26,6 +27,9 @@ class InheritedReferenceContributor extends Object
@override
CompletionSuggestionKind kind;
@override
ResourceProvider resourceProvider;
@override
Future<Null> computeSuggestions(
CompletionRequest request, CompletionCollector collector) async {
@ -48,21 +52,6 @@ class InheritedReferenceContributor extends Object
optype);
}
List<CompletionSuggestion> computeSuggestionsForClass(
CompletionCollector collector,
ClassElement classElement,
CompletionRequest request,
{bool skipChildClass: true}) {
// if (!request.includeIdentifiers) {
// return const <CompletionSuggestion>[];
// }
// containingLibrary = request.result.libraryElement;
//
// return _computeSuggestionsForClass2(collector, classElement, request,
// skipChildClass: skipChildClass);
throw new StateError('Unexpected invocation of computeSuggestionsForClass');
}
_addSuggestionsForType(InterfaceType type, OpType optype,
{bool isFunctionalArgument: false}) {
if (!isFunctionalArgument) {