| OLD | NEW |
| 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.manager; | 5 library services.completion.manager; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/completion/completion_core.dart' | 9 import 'package:analysis_server/completion/completion_core.dart' |
| 10 show CompletionRequest, CompletionResult; | 10 show CompletionRequest, CompletionResult; |
| 11 import 'package:analysis_server/src/analysis_server.dart'; | 11 import 'package:analysis_server/src/analysis_server.dart'; |
| 12 import 'package:analysis_server/src/protocol.dart'; | 12 import 'package:analysis_server/src/protocol.dart'; |
| 13 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; | 13 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
| 14 import 'package:analysis_server/src/services/search/search_engine.dart'; | 14 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 15 import 'package:analyzer/file_system/file_system.dart'; | 15 import 'package:analyzer/file_system/file_system.dart'; |
| 16 import 'package:analyzer/src/generated/engine.dart'; | 16 import 'package:analyzer/src/generated/engine.dart'; |
| 17 import 'package:analyzer/src/generated/source.dart'; | 17 import 'package:analyzer/src/generated/source.dart'; |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * [CompletionCache] contains information about the prior code completion | 20 * [CompletionCache] contains information about the prior code completion |
| 21 * for use in the next code completion. | 21 * for use in the next code completion. |
| 22 */ | 22 */ |
| 23 abstract class CompletionCache { | 23 abstract class CompletionCache { |
| 24 | |
| 25 /** | 24 /** |
| 26 * The context in which the completion was computed. | 25 * The context in which the completion was computed. |
| 27 */ | 26 */ |
| 28 final AnalysisContext context; | 27 final AnalysisContext context; |
| 29 | 28 |
| 30 /** | 29 /** |
| 31 * The source in which the completion was computed. | 30 * The source in which the completion was computed. |
| 32 */ | 31 */ |
| 33 final Source source; | 32 final Source source; |
| 34 | 33 |
| 35 CompletionCache(this.context, this.source); | 34 CompletionCache(this.context, this.source); |
| 36 } | 35 } |
| 37 | 36 |
| 38 /** | 37 /** |
| 39 * Manages completion contributors for a given completion request. | 38 * Manages completion contributors for a given completion request. |
| 40 */ | 39 */ |
| 41 abstract class CompletionManager { | 40 abstract class CompletionManager { |
| 42 | |
| 43 /** | 41 /** |
| 44 * The context in which the completion was computed. | 42 * The context in which the completion was computed. |
| 45 */ | 43 */ |
| 46 final AnalysisContext context; | 44 final AnalysisContext context; |
| 47 | 45 |
| 48 /** | 46 /** |
| 49 * The source in which the completion was computed. | 47 * The source in which the completion was computed. |
| 50 */ | 48 */ |
| 51 final Source source; | 49 final Source source; |
| 52 | 50 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 String prefix = contents.substring(start, offset); | 213 String prefix = contents.substring(start, offset); |
| 216 String suffix = contents.substring(offset, end); | 214 String suffix = contents.substring(offset, end); |
| 217 return '$prefix^$suffix'; | 215 return '$prefix^$suffix'; |
| 218 } | 216 } |
| 219 } | 217 } |
| 220 | 218 |
| 221 /** | 219 /** |
| 222 * Encapsulates information specific to a particular completion request. | 220 * Encapsulates information specific to a particular completion request. |
| 223 */ | 221 */ |
| 224 class CompletionRequestImpl implements CompletionRequest { | 222 class CompletionRequestImpl implements CompletionRequest { |
| 225 | |
| 226 /** | 223 /** |
| 227 * The underlying analysis server for this completion request. | 224 * The underlying analysis server for this completion request. |
| 228 */ | 225 */ |
| 229 final AnalysisServer server; | 226 final AnalysisServer server; |
| 230 | 227 |
| 231 @override | 228 @override |
| 232 final AnalysisContext context; | 229 final AnalysisContext context; |
| 233 | 230 |
| 234 @override | 231 @override |
| 235 final Source source; | 232 final Source source; |
| 236 | 233 |
| 237 @override | 234 @override |
| 238 final int offset; | 235 final int offset; |
| 239 | 236 |
| 240 CompletionRequestImpl(this.server, this.context, this.source, this.offset); | 237 CompletionRequestImpl(this.server, this.context, this.source, this.offset); |
| 241 | 238 |
| 242 @override | 239 @override |
| 243 ResourceProvider get resourceProvider => server.resourceProvider; | 240 ResourceProvider get resourceProvider => server.resourceProvider; |
| 244 } | 241 } |
| 245 | 242 |
| 246 /** | 243 /** |
| 247 * Code completion result generated by an [CompletionManager]. | 244 * Code completion result generated by an [CompletionManager]. |
| 248 */ | 245 */ |
| 249 class CompletionResultImpl implements CompletionResult { | 246 class CompletionResultImpl implements CompletionResult { |
| 250 | |
| 251 /** | 247 /** |
| 252 * The length of the text to be replaced if the remainder of the identifier | 248 * The length of the text to be replaced if the remainder of the identifier |
| 253 * containing the cursor is to be replaced when the suggestion is applied | 249 * containing the cursor is to be replaced when the suggestion is applied |
| 254 * (that is, the number of characters in the existing identifier). | 250 * (that is, the number of characters in the existing identifier). |
| 255 */ | 251 */ |
| 256 final int replacementLength; | 252 final int replacementLength; |
| 257 | 253 |
| 258 /** | 254 /** |
| 259 * The offset of the start of the text to be replaced. This will be different | 255 * The offset of the start of the text to be replaced. This will be different |
| 260 * than the offset used to request the completion suggestions if there was a | 256 * than the offset used to request the completion suggestions if there was a |
| (...skipping 30 matching lines...) Expand all Loading... |
| 291 @override | 287 @override |
| 292 void computeSuggestions(CompletionRequest request) { | 288 void computeSuggestions(CompletionRequest request) { |
| 293 controller.add(new CompletionResultImpl(request.offset, 0, [], true)); | 289 controller.add(new CompletionResultImpl(request.offset, 0, [], true)); |
| 294 } | 290 } |
| 295 } | 291 } |
| 296 | 292 |
| 297 /** | 293 /** |
| 298 * The performance of an operation when computing code completion. | 294 * The performance of an operation when computing code completion. |
| 299 */ | 295 */ |
| 300 class OperationPerformance { | 296 class OperationPerformance { |
| 301 | |
| 302 /** | 297 /** |
| 303 * The name of the operation | 298 * The name of the operation |
| 304 */ | 299 */ |
| 305 final String name; | 300 final String name; |
| 306 | 301 |
| 307 /** | 302 /** |
| 308 * The elapse time or `null` if undefined. | 303 * The elapse time or `null` if undefined. |
| 309 */ | 304 */ |
| 310 final Duration elapsed; | 305 final Duration elapsed; |
| 311 | 306 |
| 312 OperationPerformance(this.name, this.elapsed); | 307 OperationPerformance(this.name, this.elapsed); |
| 313 } | 308 } |
| OLD | NEW |