OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import 'package:analyzer/dart/analysis/results.dart'; | 7 import 'package:analyzer/dart/analysis/results.dart'; |
8 import 'package:analyzer/file_system/file_system.dart'; | 8 import 'package:analyzer/file_system/file_system.dart'; |
9 import 'package:analyzer_plugin/protocol/protocol.dart'; | 9 import 'package:analyzer_plugin/protocol/protocol.dart'; |
10 import 'package:analyzer_plugin/protocol/protocol_common.dart'; | 10 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
(...skipping 28 matching lines...) Expand all Loading... |
39 * Set the offset of the region of text that should be replaced by the | 39 * Set the offset of the region of text that should be replaced by the |
40 * selected completion suggestion. | 40 * selected completion suggestion. |
41 * | 41 * |
42 * The offset can only be set once and applies to all of the suggestions. | 42 * The offset can only be set once and applies to all of the suggestions. |
43 * Hence, this setter throws a [StateError] if the offset has already been | 43 * Hence, this setter throws a [StateError] if the offset has already been |
44 * set. | 44 * set. |
45 */ | 45 */ |
46 void set offset(int offset); | 46 void set offset(int offset); |
47 | 47 |
48 /** | 48 /** |
| 49 * Indicates if the collector's offset has been set (and ultimately the |
| 50 * length too). |
| 51 */ |
| 52 bool get offsetIsSet; |
| 53 |
| 54 /** |
| 55 * Returns length of suggestions currently held. |
| 56 */ |
| 57 int get suggestionsLength; |
| 58 |
| 59 /** |
49 * Record the given completion [suggestion]. | 60 * Record the given completion [suggestion]. |
50 */ | 61 */ |
51 void addSuggestion(CompletionSuggestion suggestion); | 62 void addSuggestion(CompletionSuggestion suggestion); |
52 } | 63 } |
53 | 64 |
54 /** | 65 /** |
55 * An object used to produce completion suggestions. | 66 * An object used to produce completion suggestions. |
56 * | 67 * |
57 * Clients may implement this class when implementing plugins. | 68 * Clients may implement this class when implementing plugins. |
58 */ | 69 */ |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 await contributor.computeSuggestions(request, collector); | 108 await contributor.computeSuggestions(request, collector); |
98 } catch (exception, stackTrace) { | 109 } catch (exception, stackTrace) { |
99 notifications.add(new PluginErrorParams( | 110 notifications.add(new PluginErrorParams( |
100 false, exception.toString(), stackTrace.toString()) | 111 false, exception.toString(), stackTrace.toString()) |
101 .toNotification()); | 112 .toNotification()); |
102 } | 113 } |
103 } | 114 } |
104 } on AbortCompletion { | 115 } on AbortCompletion { |
105 return new GeneratorResult(null, notifications); | 116 return new GeneratorResult(null, notifications); |
106 } | 117 } |
| 118 collector.offset ??= request.offset; |
| 119 collector.length ??= 0; |
| 120 |
107 CompletionGetSuggestionsResult result = new CompletionGetSuggestionsResult( | 121 CompletionGetSuggestionsResult result = new CompletionGetSuggestionsResult( |
108 collector.offset, collector.length, collector.suggestions); | 122 collector.offset, collector.length, collector.suggestions); |
109 return new GeneratorResult(result, notifications); | 123 return new GeneratorResult(result, notifications); |
110 } | 124 } |
111 } | 125 } |
112 | 126 |
113 /** | 127 /** |
114 * The information about a requested list of completions. | 128 * The information about a requested list of completions. |
115 * | 129 * |
116 * Clients may not extend, implement or mix-in this class. | 130 * Clients may not extend, implement or mix-in this class. |
(...skipping 14 matching lines...) Expand all Loading... |
131 * The analysis result for the file in which the completion is being | 145 * The analysis result for the file in which the completion is being |
132 * requested. | 146 * requested. |
133 */ | 147 */ |
134 ResolveResult get result; | 148 ResolveResult get result; |
135 | 149 |
136 /** | 150 /** |
137 * Throw an [AbortCompletion] if the completion request has been aborted. | 151 * Throw an [AbortCompletion] if the completion request has been aborted. |
138 */ | 152 */ |
139 void checkAborted(); | 153 void checkAborted(); |
140 } | 154 } |
OLD | NEW |