Chromium Code Reviews| Index: pkg/analysis_server/lib/src/services/completion/dart_completion_manager.dart |
| diff --git a/pkg/analysis_server/lib/src/services/completion/dart_completion_manager.dart b/pkg/analysis_server/lib/src/services/completion/dart_completion_manager.dart |
| index 06c3c6a8af077fd715de028337e0620d8896eb4f..67f713b9cdb48d1c68239c289b45b9898d387e3f 100644 |
| --- a/pkg/analysis_server/lib/src/services/completion/dart_completion_manager.dart |
| +++ b/pkg/analysis_server/lib/src/services/completion/dart_completion_manager.dart |
| @@ -8,6 +8,7 @@ import 'dart:async'; |
| import 'package:analysis_server/completion/completion_core.dart' |
| show CompletionRequest; |
| +import 'package:analysis_server/completion/completion_dart.dart' as newApi; |
| import 'package:analysis_server/src/analysis_server.dart'; |
| import 'package:analysis_server/src/protocol.dart'; |
| import 'package:analysis_server/src/services/completion/arglist_contributor.dart'; |
| @@ -16,13 +17,15 @@ import 'package:analysis_server/src/services/completion/common_usage_computer.da |
| import 'package:analysis_server/src/services/completion/completion_manager.dart'; |
| import 'package:analysis_server/src/services/completion/completion_target.dart'; |
| import 'package:analysis_server/src/services/completion/dart_completion_cache.dart'; |
| -import 'package:analysis_server/src/services/completion/uri_contributor.dart'; |
| import 'package:analysis_server/src/services/completion/imported_reference_contributor.dart'; |
| +import 'package:analysis_server/src/services/completion/inherited_computer.dart'; |
| import 'package:analysis_server/src/services/completion/keyword_contributor.dart'; |
| import 'package:analysis_server/src/services/completion/local_reference_contributor.dart'; |
| import 'package:analysis_server/src/services/completion/optype.dart'; |
| import 'package:analysis_server/src/services/completion/prefixed_element_contributor.dart'; |
| +import 'package:analysis_server/src/services/completion/uri_contributor.dart'; |
| import 'package:analysis_server/src/services/search/search_engine.dart'; |
| +import 'package:analyzer/file_system/file_system.dart'; |
| import 'package:analyzer/src/generated/ast.dart'; |
| import 'package:analyzer/src/generated/engine.dart'; |
| import 'package:analyzer/src/generated/scanner.dart'; |
| @@ -93,6 +96,9 @@ class DartCompletionManager extends CompletionManager { |
| new CombinatorContributor(), |
| new PrefixedElementContributor(), |
| new UriContributor(), |
| + // TODO(brianwilkerson) Use the completion contributor extension point |
| + // to add the contributor below (and eventually, all the contributors). |
| + new NewCompletionWrapper(new InheritedContributor()) |
|
danrubel
2015/09/18 00:30:54
Please comment this line out for now and commit th
Brian Wilkerson
2015/09/18 15:59:26
Done
|
| ]; |
| } |
| if (commonUsageComputer == null) { |
| @@ -399,3 +405,78 @@ class DartCompletionRequest extends CompletionRequestImpl { |
| } |
| } |
| } |
| + |
| +/** |
| + * A wrapper around a new dart completion contributor that makes it usable where |
| + * an old dart completion contributor is expected. |
| + */ |
| +class NewCompletionWrapper implements DartCompletionContributor { |
| + /** |
| + * The new-style contributor that is being wrapped. |
| + */ |
| + final newApi.DartCompletionContributor contributor; |
| + |
| + /** |
| + * Initialize a newly created wrapper for the given [contributor]. |
| + */ |
| + NewCompletionWrapper(this.contributor); |
| + |
| + @override |
| + bool computeFast(DartCompletionRequest request) { |
| + List<CompletionSuggestion> suggestions = |
| + contributor.computeSuggestions(new OldRequestWrapper(request)); |
| + if (suggestions == null) { |
| + return false; |
| + } |
| + for (CompletionSuggestion suggestion in suggestions) { |
| + request.addSuggestion(suggestion); |
| + } |
| + return true; |
| + } |
| + |
| + @override |
| + Future<bool> computeFull(DartCompletionRequest request) async { |
| + List<CompletionSuggestion> suggestions = |
| + contributor.computeSuggestions(new OldRequestWrapper(request)); |
| + if (suggestions != null) { |
| + for (CompletionSuggestion suggestion in suggestions) { |
| + request.addSuggestion(suggestion); |
| + } |
|
danrubel
2015/09/18 00:30:54
return true after this for loop
Brian Wilkerson
2015/09/18 15:59:26
Done
|
| + } |
| + return true; |
|
danrubel
2015/09/18 00:30:54
return false here
Brian Wilkerson
2015/09/18 15:59:26
Done
|
| + } |
| + |
| + @override |
| + String toString() => 'wrapped $contributor'; |
| +} |
| + |
| +/** |
| + * A wrapper around an old dart completion request that makes it usable where a |
| + * new dart completion request is expected. |
| + */ |
| +class OldRequestWrapper implements newApi.DartCompletionRequest { |
| + final DartCompletionRequest request; |
| + |
| + OldRequestWrapper(this.request); |
| + |
| + @override |
| + AnalysisContext get context => request.context; |
| + |
| + @override |
| + bool get isResolved => request.unit.element != null; |
| + |
| + @override |
| + int get offset => request.offset; |
| + |
| + @override |
| + ResourceProvider get resourceProvider => request.resourceProvider; |
| + |
| + @override |
| + Source get source => request.source; |
| + |
| + @override |
| + CompilationUnit get unit => request.unit; |
| + |
| + @override |
| + String toString() => 'wrapped $request'; |
| +} |