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

Side by Side Diff: pkg/analysis_services/lib/completion/completion_manager.dart

Issue 467233003: refactor and cleanup code completion (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/search/search_engine.dart';
11 import 'package:analysis_services/src/completion/dart_completion_manager.dart'; 11 import 'package:analysis_services/src/completion/dart_completion_manager.dart';
12 import 'package:analyzer/src/generated/ast.dart';
13 import 'package:analyzer/src/generated/engine.dart'; 12 import 'package:analyzer/src/generated/engine.dart';
14 import 'package:analyzer/src/generated/source.dart'; 13 import 'package:analyzer/src/generated/source.dart';
15 14
16 /** 15 /**
17 * The base class for computing code completion suggestions.
18 */
19 abstract class CompletionComputer {
20 AnalysisContext context;
21 Source source;
22 int offset;
23 SearchEngine searchEngine;
24
25 /**
26 * Computes the initial set of [CompletionSuggestion]s based on
27 * the compilation [unit], the AST [node] in which the completion occurred,
28 * and information already cached in the analysis context.
29 * The supplied [unit] and [node] may not be resolved.
30 * This method should execute quickly and not block waiting for any analysis.
31 * Returns `true` if the computer's work is complete
32 * or `false` if [computeFull] should be called to complete the work.
33 */
34 bool computeFast(CompilationUnit unit, AstNode node,
35 List<CompletionSuggestion> suggestions);
36
37 /**
38 * Computes the complete set of [CompletionSuggestion]s based on
39 * the resolved compilation [unit] and the resolved AST [node] in which the
40 * completion occurred.
41 * Returns `true` if the receiver modified the list of suggestions.
42 */
43 Future<bool> computeFull(CompilationUnit unit, AstNode node,
44 List<CompletionSuggestion> suggestions);
45 }
46
47 /**
48 * Manages `CompletionComputer`s for a given completion request. 16 * Manages `CompletionComputer`s for a given completion request.
49 */ 17 */
50 abstract class CompletionManager { 18 abstract class CompletionManager {
51 19
52 StreamController<CompletionResult> controller; 20 StreamController<CompletionResult> controller;
53 21
54 /** 22 /**
55 * Compute completion results and append them to the stream. 23 * Compute completion results and append them to the stream.
56 * Subclasses should override this method, append at least one result 24 * Subclasses should override this method, append at least one result
57 * to the [controller], and close the controller stream once complete. 25 * to the [controller], and close the controller stream once complete.
(...skipping 12 matching lines...) Expand all
70 return controller.stream; 38 return controller.stream;
71 } 39 }
72 40
73 /** 41 /**
74 * Create a manager for the given request. 42 * Create a manager for the given request.
75 */ 43 */
76 static CompletionManager create(AnalysisContext context, Source source, 44 static CompletionManager create(AnalysisContext context, Source source,
77 int offset, SearchEngine searchEngine) { 45 int offset, SearchEngine searchEngine) {
78 if (context != null) { 46 if (context != null) {
79 if (AnalysisEngine.isDartFileName(source.shortName)) { 47 if (AnalysisEngine.isDartFileName(source.shortName)) {
80 return new DartCompletionManager(context, source, offset, searchEngine); 48 return new DartCompletionManager(context, searchEngine, source, offset);
49 }
50 if (AnalysisEngine.isHtmlFileName(source.shortName)) {
51 //TODO (danrubel) implement
52 // return new HtmlCompletionManager(context, searchEngine, source, offset );
81 } 53 }
82 } 54 }
83 return new NoOpCompletionManager(source, offset); 55 return new NoOpCompletionManager(source, offset);
84 } 56 }
85 } 57 }
86 58
87 /** 59 /**
88 * Code completion result generated by an [CompletionManager]. 60 * Code completion result generated by an [CompletionManager].
89 */ 61 */
90 class CompletionResult { 62 class CompletionResult {
(...skipping 21 matching lines...) Expand all
112 /** 84 /**
113 * `true` if this is that last set of results that will be returned 85 * `true` if this is that last set of results that will be returned
114 * for the indicated completion. 86 * for the indicated completion.
115 */ 87 */
116 final bool last; 88 final bool last;
117 89
118 CompletionResult(this.replacementOffset, this.replacementLength, 90 CompletionResult(this.replacementOffset, this.replacementLength,
119 this.suggestions, this.last); 91 this.suggestions, this.last);
120 } 92 }
121 93
122
123 class NoOpCompletionManager extends CompletionManager { 94 class NoOpCompletionManager extends CompletionManager {
124 final Source source; 95 final Source source;
125 final int offset; 96 final int offset;
126 97
127 NoOpCompletionManager(this.source, this.offset); 98 NoOpCompletionManager(this.source, this.offset);
128 99
129 @override 100 @override
130 void compute() { 101 void compute() {
131 controller.add(new CompletionResult(offset, 0, [], true)); 102 controller.add(new CompletionResult(offset, 0, [], true));
132 } 103 }
133 } 104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698