Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library services.completion.computer; | 5 library services.completion.computer; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_services/completion/completion_suggestion.dart'; | 9 import 'package:analysis_services/completion/completion_suggestion.dart'; |
| 10 import 'package:analysis_services/search/search_engine.dart'; | |
| 10 import 'package:analysis_services/src/completion/top_level_computer.dart'; | 11 import 'package:analysis_services/src/completion/top_level_computer.dart'; |
| 11 import 'package:analysis_services/search/search_engine.dart'; | 12 import 'package:analyzer/src/generated/engine.dart'; |
| 13 import 'package:analyzer/src/generated/source.dart'; | |
| 12 | 14 |
| 13 /** | 15 /** |
| 14 * The base class for computing code completion suggestions. | 16 * The base class for computing code completion suggestions. |
| 15 */ | 17 */ |
| 16 abstract class CompletionComputer { | 18 abstract class CompletionComputer { |
| 17 | 19 |
| 18 /** | 20 /** |
| 19 * Create a collection of code completion computers for the given situation. | |
| 20 */ | |
| 21 static Future<List<CompletionComputer>> create(SearchEngine searchEngine) { | |
| 22 List<CompletionComputer> computers = []; | |
| 23 computers.add(new TopLevelComputer(searchEngine)); | |
| 24 return new Future.value(computers); | |
| 25 } | |
| 26 | |
| 27 /** | |
| 28 * Computes [CompletionSuggestion]s for the specified position in the source. | 21 * Computes [CompletionSuggestion]s for the specified position in the source. |
| 29 */ | 22 */ |
| 30 Future<List<CompletionSuggestion>> compute(); | 23 Future<List<CompletionSuggestion>> compute(); |
| 31 } | 24 } |
| 25 | |
| 26 /** | |
| 27 * Manages `CompletionComputer`s for a given completion request. | |
| 28 */ | |
| 29 abstract class CompletionManager { | |
| 30 | |
| 31 /** | |
| 32 * The length of the text to be replaced if the remainder of the identifier | |
| 33 * containing the cursor is to be replaced when the suggestion is applied | |
| 34 * (that is, the number of characters in the existing identifier). | |
| 35 */ | |
| 36 int get replacementLength; | |
| 37 | |
| 38 /** | |
| 39 * The offset of the start of the text to be replaced. This will be different | |
| 40 * than the offset used to request the completion suggestions if there was a | |
| 41 * portion of an identifier before the original offset. In particular, the | |
| 42 * replacementOffset will be the offset of the beginning of said identifier. | |
| 43 */ | |
| 44 int get replacementOffset; | |
| 45 | |
| 46 /** | |
| 47 * Generate code completion computers for the given situation. | |
| 48 */ | |
| 49 Future<List<CompletionComputer>> generate(); | |
| 50 | |
| 51 /** | |
| 52 * Create a manager for the given request. | |
| 53 */ | |
| 54 static CompletionManager create(Source source, int offset, | |
| 55 SearchEngine searchEngine) { | |
| 56 if (AnalysisEngine.isDartFileName(source.shortName)) { | |
| 57 return new DartCompletionManager(source, offset, searchEngine); | |
| 58 } | |
| 59 return new NoOpCompletionManager(source, offset); | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 /** | |
| 64 * Manages code completion for a given Dart file completion request. | |
| 65 */ | |
| 66 class DartCompletionManager extends CompletionManager { | |
| 67 final Source source; | |
| 68 final int offset; | |
| 69 final SearchEngine searchEngine; | |
|
scheglov
2014/07/31 22:28:47
nit: extra spaces
Do you use our code formatter? :
danrubel
2014/08/01 16:24:31
Yes, but I forget sometimes because there is not y
| |
| 70 | |
| 71 DartCompletionManager(this.source, this.offset, this.searchEngine); | |
| 72 | |
| 73 @override | |
| 74 int get replacementLength => 0; | |
| 75 | |
| 76 @override | |
| 77 int get replacementOffset => offset; | |
| 78 | |
| 79 @override | |
| 80 Future<List<CompletionComputer>> generate() { | |
| 81 List<CompletionComputer> computers = []; | |
| 82 computers.add(new TopLevelComputer(searchEngine)); | |
| 83 return new Future.value(computers); | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 class NoOpCompletionComputer extends CompletionComputer { | |
| 88 @override | |
| 89 Future<List<CompletionSuggestion>> compute() { | |
| 90 return new Future.value([]); | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 class NoOpCompletionManager extends CompletionManager { | |
| 95 final Source source; | |
| 96 final int offset; | |
| 97 | |
| 98 NoOpCompletionManager(this.source, this.offset); | |
| 99 | |
| 100 @override | |
| 101 int get replacementLength => 0; | |
| 102 | |
| 103 @override | |
| 104 int get replacementOffset => offset; | |
| 105 | |
| 106 @override | |
| 107 Future<List<CompletionComputer>> generate() { | |
| 108 return new Future.value([new NoOpCompletionComputer()]); | |
| 109 } | |
| 110 } | |
| OLD | NEW |