| Index: pkg/analysis_server/lib/src/services/completion/dart/reference_contributor.dart
|
| diff --git a/pkg/analysis_server/lib/src/services/completion/dart/reference_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/reference_contributor.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f26cbd7f03e13e0287e81f3898f955b8fe1894d5
|
| --- /dev/null
|
| +++ b/pkg/analysis_server/lib/src/services/completion/dart/reference_contributor.dart
|
| @@ -0,0 +1,62 @@
|
| +// Copyright (c) 2014, 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.
|
| +
|
| +library services.completion.contributor.dart.reference;
|
| +
|
| +import 'dart:async';
|
| +
|
| +import 'package:analysis_server/plugin/protocol/protocol.dart'
|
| + show CompletionSuggestion, CompletionSuggestionKind;
|
| +import 'package:analysis_server/src/provisional/completion/completion_dart.dart';
|
| +import 'package:analysis_server/src/provisional/completion/dart/completion_target.dart';
|
| +import 'package:analysis_server/src/services/completion/dart_completion_manager.dart'
|
| + show DART_RELEVANCE_DEFAULT, DART_RELEVANCE_LOCAL_FUNCTION;
|
| +import 'package:analysis_server/src/services/completion/suggestion_builder.dart';
|
| +import 'package:analyzer/src/generated/ast.dart';
|
| +import 'package:analyzer/src/generated/element.dart';
|
| +import 'package:analyzer/src/task/dart.dart';
|
| +import 'package:analyzer/task/model.dart';
|
| +
|
| +/**
|
| + * A contributor for calculating `completion.getSuggestions` request results
|
| + * for "free standing" identifiers.
|
| + */
|
| +class ReferenceContributor extends DartCompletionContributor {
|
| + @override
|
| + Future computeSuggestions(
|
| + DartCompletionRequest request, DartSuggestionCollector collector) {
|
| + // TODO (danrubel) determine whether references should be suggested
|
| + // Generate completions outside expressions, method and function bodies
|
| + return request.resolvedDeclarationTarget
|
| + .then((CompletionTarget resolvedTarget) {
|
| + resolvedTarget.unit.element.library.visitChildren(
|
| + new _ReferenceContributorElemVisitor(collector, true, null));
|
| + });
|
| + }
|
| +}
|
| +
|
| +/**
|
| + * Build suggestions from visited elements.
|
| + */
|
| +class _ReferenceContributorElemVisitor extends GeneralizingElementVisitor {
|
| + final DartSuggestionCollector collector;
|
| + final bool isLocal;
|
| + final String prefix;
|
| +
|
| + _ReferenceContributorElemVisitor(this.collector, this.isLocal, this.prefix);
|
| +
|
| + @override
|
| + visitCompilationUnitElement(CompilationUnitElement element) {
|
| + element.visitChildren(this);
|
| + }
|
| +
|
| + @override
|
| + visitFunctionElement(FunctionElement element) {
|
| + collector.addElementSuggestion(element,
|
| + includePrivateElements: isLocal,
|
| + prefix: prefix,
|
| + relevance:
|
| + isLocal ? DART_RELEVANCE_LOCAL_FUNCTION : DART_RELEVANCE_DEFAULT);
|
| + }
|
| +}
|
|
|