| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library services.completion.dart; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 | |
| 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; | |
| 10 import 'package:analysis_server/src/provisional/completion/completion_core.dart' | |
| 11 show | |
| 12 AnalysisRequest, | |
| 13 CompletionContributor, | |
| 14 CompletionRequest, | |
| 15 CompletionResult; | |
| 16 import 'package:analysis_server/src/services/completion/completion_core.dart'; | |
| 17 import 'package:analysis_server/src/services/completion/completion_manager.dart'
; | |
| 18 import 'package:analysis_server/src/services/search/search_engine.dart'; | |
| 19 import 'package:analyzer/src/generated/engine.dart'; | |
| 20 import 'package:analyzer/src/generated/source.dart'; | |
| 21 | |
| 22 /** | |
| 23 * Manages code completion for a given Dart file completion request. | |
| 24 */ | |
| 25 class DartCompletionManager extends CompletionManager { | |
| 26 final SearchEngine searchEngine; | |
| 27 Iterable<CompletionContributor> newContributors; | |
| 28 | |
| 29 DartCompletionManager( | |
| 30 AnalysisContext context, this.searchEngine, Source source, | |
| 31 [this.newContributors]) | |
| 32 : super(context, source) { | |
| 33 if (newContributors == null) { | |
| 34 newContributors = <CompletionContributor>[]; | |
| 35 } | |
| 36 } | |
| 37 | |
| 38 /** | |
| 39 * Create a new initialized Dart source completion manager | |
| 40 */ | |
| 41 factory DartCompletionManager.create( | |
| 42 AnalysisContext context, | |
| 43 SearchEngine searchEngine, | |
| 44 Source source, | |
| 45 Iterable<CompletionContributor> newContributors) { | |
| 46 return new DartCompletionManager( | |
| 47 context, searchEngine, source, newContributors); | |
| 48 } | |
| 49 | |
| 50 @override | |
| 51 Future<CompletionResult> computeSuggestions( | |
| 52 CompletionRequestImpl request) async { | |
| 53 CompletionPerformance performance = new CompletionPerformance(); | |
| 54 List<CompletionSuggestion> suggestions = <CompletionSuggestion>[]; | |
| 55 | |
| 56 const COMPUTE_SUGGESTIONS_TAG = 'computeSuggestions'; | |
| 57 performance.logStartTime(COMPUTE_SUGGESTIONS_TAG); | |
| 58 for (CompletionContributor contributor in newContributors) { | |
| 59 String contributorTag = 'computeSuggestions - ${contributor.runtimeType}'; | |
| 60 performance.logStartTime(contributorTag); | |
| 61 suggestions.addAll(await contributor.computeSuggestions(request)); | |
| 62 performance.logElapseTime(contributorTag); | |
| 63 } | |
| 64 performance.logElapseTime(COMPUTE_SUGGESTIONS_TAG); | |
| 65 | |
| 66 // TODO (danrubel) if request is obsolete | |
| 67 // (processAnalysisRequest returns false) | |
| 68 // then send empty results | |
| 69 | |
| 70 return new CompletionResultImpl( | |
| 71 request.replacementOffset, request.replacementLength, suggestions); | |
| 72 } | |
| 73 } | |
| OLD | NEW |