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

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

Issue 424543004: incremental progress aligning code completion api to spec (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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 ad273dd81cac910a94700eeb52dd96d65f20279c..5e02d49ac17f52b7e471e41909d332a07751badb 100644
--- a/pkg/analysis_services/lib/completion/completion_computer.dart
+++ b/pkg/analysis_services/lib/completion/completion_computer.dart
@@ -7,8 +7,10 @@ library services.completion.computer;
import 'dart:async';
import 'package:analysis_services/completion/completion_suggestion.dart';
-import 'package:analysis_services/src/completion/top_level_computer.dart';
import 'package:analysis_services/search/search_engine.dart';
+import 'package:analysis_services/src/completion/top_level_computer.dart';
+import 'package:analyzer/src/generated/engine.dart';
+import 'package:analyzer/src/generated/source.dart';
/**
* The base class for computing code completion suggestions.
@@ -16,16 +18,93 @@ import 'package:analysis_services/search/search_engine.dart';
abstract class CompletionComputer {
/**
- * Create a collection of code completion computers for the given situation.
+ * Computes [CompletionSuggestion]s for the specified position in the source.
+ */
+ Future<List<CompletionSuggestion>> compute();
+}
+
+/**
+ * Manages `CompletionComputer`s for a given completion request.
+ */
+abstract class CompletionManager {
+
+ /**
+ * 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).
*/
- static Future<List<CompletionComputer>> create(SearchEngine searchEngine) {
+ int get replacementLength;
+
+ /**
+ * The offset of the start of the text to be replaced. This will be different
+ * than the offset used to request the completion suggestions if there was a
+ * 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;
+
+ /**
+ * Generate code completion computers for the given situation.
+ */
+ Future<List<CompletionComputer>> generate();
+
+ /**
+ * 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);
+ }
+}
+
+/**
+ * Manages code completion for a given Dart file completion request.
+ */
+class DartCompletionManager extends CompletionManager {
+ final Source source;
+ final int offset;
+ 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
+
+ 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);
}
+}
- /**
- * Computes [CompletionSuggestion]s for the specified position in the source.
- */
- Future<List<CompletionSuggestion>> compute();
+class NoOpCompletionComputer extends CompletionComputer {
+ @override
+ Future<List<CompletionSuggestion>> compute() {
+ return new Future.value([]);
+ }
+}
+
+class NoOpCompletionManager extends CompletionManager {
+ final Source source;
+ final int offset;
+
+ 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()]);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698