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

Unified Diff: pkg/analysis_server/lib/src/services/completion/completion_manager.dart

Issue 729193002: add code completion cache (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 6 years, 1 month 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_server/lib/src/services/completion/completion_manager.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/completion_manager.dart b/pkg/analysis_server/lib/src/services/completion/completion_manager.dart
index 2253056e9b22d5382acaf88bf3c680ae19830645..8f1231cbed7f943c705cb8a623b04fadc99e846d 100644
--- a/pkg/analysis_server/lib/src/services/completion/completion_manager.dart
+++ b/pkg/analysis_server/lib/src/services/completion/completion_manager.dart
@@ -13,36 +13,42 @@ import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/source.dart';
/**
- * Manages `CompletionComputer`s for a given completion request.
+ * [CompletionCache] contains information about the prior code completion
+ * for use in the next code completion.
*/
-abstract class CompletionManager {
+abstract class CompletionCache {
- StreamController<CompletionResult> controller;
+ /**
+ * The context in which the completion was computed.
+ */
+ final AnalysisContext context;
/**
- * Compute completion results and append them to the stream.
- * Subclasses should override this method, append at least one result
- * to the [controller], and close the controller stream once complete.
- * Clients should not call this method directly as it is automatically called
- * when a client listens to the stream returned by [results].
+ * The source in which the completion was computed.
*/
- void compute();
+ final Source source;
+
+ CompletionCache(this.context, this.source);
+}
+
+/**
+ * Manages `CompletionComputer`s for a given completion request.
+ */
+abstract class CompletionManager {
/**
- * Generate a stream of code completion results.
+ * The controller used for returning completion results.
*/
- Stream<CompletionResult> results() {
- controller = new StreamController<CompletionResult>(onListen: () {
- scheduleMicrotask(compute);
- });
- return controller.stream;
- }
+ StreamController<CompletionResult> controller;
+
+ CompletionManager();
/**
* Create a manager for the given request.
*/
- static CompletionManager create(AnalysisContext context, Source source,
- int offset, SearchEngine searchEngine, CompletionPerformance performance) {
+ factory CompletionManager.create(AnalysisContext context, Source source,
+ int offset, SearchEngine searchEngine, CompletionCache cache,
+ CompletionPerformance performance) {
if (context != null) {
if (AnalysisEngine.isDartFileName(source.shortName)) {
return new DartCompletionManager(
@@ -59,6 +65,31 @@ abstract class CompletionManager {
}
return new NoOpCompletionManager(source, offset);
}
+
+ /**
+ * Return cached information from the current completion operation
+ * if there is any. Subclasses may override this method.
+ */
+ CompletionCache get completionCache => null;
+
+ /**
+ * 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].
+ * Subclasses should override this method, append at least one result
+ * to the [controller], and close the controller stream once complete.
+ */
+ void compute();
+
+ /**
+ * Generate a stream of code completion results.
+ */
+ Stream<CompletionResult> results() {
+ controller = new StreamController<CompletionResult>(onListen: () {
+ scheduleMicrotask(compute);
+ });
+ return controller.stream;
+ }
}
/**
@@ -67,7 +98,7 @@ abstract class CompletionManager {
class CompletionPerformance {
final Map<String, Duration> _startTimes = new Map<String, Duration>();
final Stopwatch _stopwatch = new Stopwatch();
- final List<OperationPerformance> operations = [];
+ final List<OperationPerformance> operations = <OperationPerformance>[];
CompletionPerformance() {
_stopwatch.start();

Powered by Google App Engine
This is Rietveld 408576698