Chromium Code Reviews| Index: pkg/analysis_server/lib/plugin/edit/assist/assist_dart.dart |
| diff --git a/pkg/analysis_server/lib/plugin/edit/assist/assist_dart.dart b/pkg/analysis_server/lib/plugin/edit/assist/assist_dart.dart |
| index ccdc1235fe383b13eb7bb9d227b10e4a138068a1..abf804fb27d57ed26ca50d9be4b324494d499956 100644 |
| --- a/pkg/analysis_server/lib/plugin/edit/assist/assist_dart.dart |
| +++ b/pkg/analysis_server/lib/plugin/edit/assist/assist_dart.dart |
| @@ -4,42 +4,77 @@ |
| library analysis_server.plugin.edit.assist.assist_dart; |
| +import 'dart:async'; |
| + |
| import 'package:analysis_server/plugin/edit/assist/assist_core.dart'; |
| import 'package:analyzer/src/generated/ast.dart'; |
| import 'package:analyzer/src/generated/engine.dart'; |
| import 'package:analyzer/src/generated/source.dart'; |
| /** |
| - * An [AssistContributor] that can be used to contribute assists for Dart |
| - * files. |
| + * An object used to provide context information for [DartAssistContributor]s. |
| + * |
| + * Clients may not extend, implement or mix-in this class. |
| + */ |
| +class DartAssistContext { |
|
Brian Wilkerson
2015/11/20 19:10:11
It would be better for this to be an interface tha
|
| + final AssistContext _context; |
| + |
| + /** |
| + * The [CompilationUnit] to compute assists in. |
| + */ |
| + final CompilationUnit unit; |
| + |
| + DartAssistContext(this._context, this.unit); |
| + |
| + /** |
| + * The [AnalysisContext] to get assists in. |
| + */ |
| + AnalysisContext get analysisContext => _context.analysisContext; |
| + |
| + /** |
| + * The length of the selection. |
| + */ |
| + int get selectionLength => _context.selectionLength; |
| + |
| + /** |
| + * The start of the selection. |
| + */ |
| + int get selectionOffset => _context.selectionOffset; |
| + |
| + /** |
| + * The source to get assists in. |
| + */ |
| + Source get source => _context.source; |
| +} |
| + |
| +/** |
| + * An [AssistContributor] that can be used to contribute assists for Dart files. |
| * |
| * Clients may extend this class when implementing plugins. |
| */ |
| abstract class DartAssistContributor implements AssistContributor { |
| @override |
| - List<Assist> computeAssists( |
| - AnalysisContext context, Source source, int offset, int length) { |
| + Future<List<Assist>> computeAssists(AssistContext context) { |
| + AnalysisContext analysisContext = context.analysisContext; |
| + Source source = context.source; |
| if (!AnalysisEngine.isDartFileName(source.fullName)) { |
| - return Assist.EMPTY_LIST; |
| + return new Future.value(Assist.EMPTY_LIST); |
| } |
| - List<Source> libraries = context.getLibrariesContaining(source); |
| + List<Source> libraries = analysisContext.getLibrariesContaining(source); |
| if (libraries.isEmpty) { |
| - return Assist.EMPTY_LIST; |
| + return new Future.value(Assist.EMPTY_LIST); |
| } |
| CompilationUnit unit = |
| - context.resolveCompilationUnit2(source, libraries[0]); |
| + analysisContext.resolveCompilationUnit2(source, libraries[0]); |
|
Brian Wilkerson
2015/11/20 19:10:11
At some future date we should make this be an asyn
|
| if (unit == null) { |
| - return Assist.EMPTY_LIST; |
| + return new Future.value(Assist.EMPTY_LIST); |
| } |
| - return internalComputeAssists(unit, offset, length); |
| + DartAssistContext dartContext = new DartAssistContext(context, unit); |
| + return internalComputeAssists(dartContext); |
| } |
| /** |
| - * Return a list of assists for a location in the given [source]. The location |
| - * is specified by the [offset] and [length] of the selected region. The |
| - * [context] can be used to get additional information that is useful for |
| - * computing assists. |
| + * Completes with a list of assists for the given [context]. |
| */ |
| - List<Assist> internalComputeAssists( |
| - CompilationUnit unit, int offset, int length); |
| + Future<List<Assist>> internalComputeAssists(DartAssistContext context); |
| } |