Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(800)

Unified Diff: pkg/analysis_services/lib/completion/completion_computer.dart

Issue 436263002: incremental progress reworking code completion manager / computers (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_services/lib/completion/completion_computer.dart
diff --git a/pkg/analysis_services/lib/completion/completion_computer.dart b/pkg/analysis_services/lib/completion/completion_computer.dart
index 5158f0fac1709dfaa4c8dc31ce11a6a3b6a0e887..b4517b8f47421862f81869dc4c7a108a0eca2ad7 100644
--- a/pkg/analysis_services/lib/completion/completion_computer.dart
+++ b/pkg/analysis_services/lib/completion/completion_computer.dart
@@ -29,11 +29,47 @@ abstract class CompletionComputer {
abstract class CompletionManager {
/**
+ * Create a manager for the given request.
+ */
+ static CompletionManager create(Source source, int offset,
+ SearchEngine searchEngine) {
+ if (AnalysisEngine.isDartFileName(source.shortName)) {
+ return new DartCompletionManager(source, offset, searchEngine);
+ }
+ return new NoOpCompletionManager(source, offset);
+ }
+
+ StreamController<CompletionResult> controller;
+
+ /**
+ * Generate a stream of code completion results.
+ */
+ Stream<CompletionResult> results() {
+ controller = new StreamController<CompletionResult>(onListen: () {
+ scheduleMicrotask(compute);
+ });
+ return controller.stream;
+ }
+
+ /**
+ * Compute completion results and append them to the stream.
+ * Clients should not call this method directly as it is automatically called
+ * when a client listens to the stream returned by [results].
+ */
+ void compute();
+}
+
+/**
+ * Code completion result generated by an [CompletionManager].
+ */
+class CompletionResult {
+
+ /**
* The length of the text to be replaced if the remainder of the identifier
* containing the cursor is to be replaced when the suggestion is applied
* (that is, the number of characters in the existing identifier).
*/
- int get replacementLength;
+ final int replacementLength;
/**
* The offset of the start of the text to be replaced. This will be different
@@ -41,23 +77,21 @@ abstract class CompletionManager {
* portion of an identifier before the original offset. In particular, the
* replacementOffset will be the offset of the beginning of said identifier.
*/
- int get replacementOffset;
+ final int replacementOffset;
/**
- * Generate code completion computers for the given situation.
+ * The suggested completions.
*/
- Future<List<CompletionComputer>> generate();
+ final List<CompletionSuggestion> suggestions;
/**
- * Create a manager for the given request.
+ * `true` if this is that last set of results that will be returned
+ * for the indicated completion.
*/
- static CompletionManager create(Source source, int offset,
- SearchEngine searchEngine) {
- if (AnalysisEngine.isDartFileName(source.shortName)) {
- return new DartCompletionManager(source, offset, searchEngine);
- }
- return new NoOpCompletionManager(source, offset);
- }
+ final bool last;
+
+ CompletionResult(this.replacementOffset, this.replacementLength,
+ this.suggestions, this.last);
}
/**
@@ -71,23 +105,11 @@ class DartCompletionManager extends CompletionManager {
DartCompletionManager(this.source, this.offset, this.searchEngine);
@override
- int get replacementLength => 0;
-
- @override
- int get replacementOffset => offset;
-
- @override
- Future<List<CompletionComputer>> generate() {
- List<CompletionComputer> computers = [];
- computers.add(new TopLevelComputer(searchEngine));
- return new Future.value(computers);
- }
-}
-
-class NoOpCompletionComputer extends CompletionComputer {
- @override
- Future<List<CompletionSuggestion>> compute() {
- return new Future.value([]);
+ void compute() {
+ var computer = new TopLevelComputer(searchEngine);
+ computer.compute().then((List<CompletionSuggestion> suggestions) {
+ controller.add(new CompletionResult(offset, 0, suggestions, true));
+ });
}
}
@@ -98,13 +120,7 @@ class NoOpCompletionManager extends CompletionManager {
NoOpCompletionManager(this.source, this.offset);
@override
- int get replacementLength => 0;
-
- @override
- int get replacementOffset => offset;
-
- @override
- Future<List<CompletionComputer>> generate() {
- return new Future.value([new NoOpCompletionComputer()]);
+ void compute() {
+ controller.add(new CompletionResult(offset, 0, [], true));
}
}

Powered by Google App Engine
This is Rietveld 408576698