| 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.dart; | 5 library services.completion.dart; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol.dart'; | 9 import 'package:analysis_server/src/protocol.dart'; |
| 10 import 'package:analysis_server/src/services/completion/arglist_computer.dart'; | 10 import 'package:analysis_server/src/services/completion/arglist_computer.dart'; |
| 11 import 'package:analysis_server/src/services/completion/combinator_computer.dart
'; | 11 import 'package:analysis_server/src/services/completion/combinator_computer.dart
'; |
| 12 import 'package:analysis_server/src/services/completion/completion_manager.dart'
; | 12 import 'package:analysis_server/src/services/completion/completion_manager.dart'
; |
| 13 import 'package:analysis_server/src/services/completion/dart_completion_cache.da
rt'; | 13 import 'package:analysis_server/src/services/completion/dart_completion_cache.da
rt'; |
| 14 import 'package:analysis_server/src/services/completion/imported_computer.dart'; | 14 import 'package:analysis_server/src/services/completion/imported_computer.dart'; |
| 15 import 'package:analysis_server/src/services/completion/invocation_computer.dart
'; | 15 import 'package:analysis_server/src/services/completion/invocation_computer.dart
'; |
| 16 import 'package:analysis_server/src/services/completion/keyword_computer.dart'; | 16 import 'package:analysis_server/src/services/completion/keyword_computer.dart'; |
| 17 import 'package:analysis_server/src/services/completion/local_computer.dart'; | 17 import 'package:analysis_server/src/services/completion/local_computer.dart'; |
| 18 import 'package:analysis_server/src/services/completion/optype.dart'; |
| 18 import 'package:analysis_server/src/services/search/search_engine.dart'; | 19 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 19 import 'package:analyzer/src/generated/ast.dart'; | 20 import 'package:analyzer/src/generated/ast.dart'; |
| 20 import 'package:analyzer/src/generated/engine.dart'; | 21 import 'package:analyzer/src/generated/engine.dart'; |
| 21 import 'package:analyzer/src/generated/source.dart'; | 22 import 'package:analyzer/src/generated/source.dart'; |
| 22 | 23 |
| 23 /** | 24 /** |
| 24 * The base class for computing code completion suggestions. | 25 * The base class for computing code completion suggestions. |
| 25 */ | 26 */ |
| 26 abstract class DartCompletionComputer { | 27 abstract class DartCompletionComputer { |
| 27 /** | 28 /** |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 CompilationUnit unit; | 231 CompilationUnit unit; |
| 231 | 232 |
| 232 /** | 233 /** |
| 233 * The node in which the completion occurred. This node | 234 * The node in which the completion occurred. This node |
| 234 * may or may not be resolved when [DartCompletionComputer.computeFast] | 235 * may or may not be resolved when [DartCompletionComputer.computeFast] |
| 235 * is called but is resolved when [DartCompletionComputer.computeFull]. | 236 * is called but is resolved when [DartCompletionComputer.computeFull]. |
| 236 */ | 237 */ |
| 237 AstNode node; | 238 AstNode node; |
| 238 | 239 |
| 239 /** | 240 /** |
| 241 * Information about the types of suggestions that should be included. |
| 242 */ |
| 243 OpType _optype; |
| 244 |
| 245 /** |
| 240 * The offset of the start of the text to be replaced. | 246 * The offset of the start of the text to be replaced. |
| 241 * This will be different than the offset used to request the completion | 247 * This will be different than the offset used to request the completion |
| 242 * suggestions if there was a portion of an identifier before the original | 248 * suggestions if there was a portion of an identifier before the original |
| 243 * offset. In particular, the replacementOffset will be the offset of the | 249 * offset. In particular, the replacementOffset will be the offset of the |
| 244 * beginning of said identifier. | 250 * beginning of said identifier. |
| 245 */ | 251 */ |
| 246 int replacementOffset; | 252 int replacementOffset; |
| 247 | 253 |
| 248 /** | 254 /** |
| 249 * The length of the text to be replaced if the remainder of the identifier | 255 * The length of the text to be replaced if the remainder of the identifier |
| (...skipping 12 matching lines...) Expand all Loading... |
| 262 : super(offset, performance); | 268 : super(offset, performance); |
| 263 | 269 |
| 264 /** | 270 /** |
| 265 * Return the original text from the [replacementOffset] to the [offset] | 271 * Return the original text from the [replacementOffset] to the [offset] |
| 266 * that can be used to filter the suggestions on the server side. | 272 * that can be used to filter the suggestions on the server side. |
| 267 */ | 273 */ |
| 268 String get filterText { | 274 String get filterText { |
| 269 return context.getContents( | 275 return context.getContents( |
| 270 source).data.substring(replacementOffset, offset); | 276 source).data.substring(replacementOffset, offset); |
| 271 } | 277 } |
| 278 |
| 279 /** |
| 280 * Information about the types of suggestions that should be included. |
| 281 * This will return `null` if the [node] has not been set. |
| 282 */ |
| 283 OpType get optype { |
| 284 if (_optype == null && node != null) { |
| 285 _optype = new OpType.forCompletion(node, offset); |
| 286 } |
| 287 return _optype; |
| 288 } |
| 272 } | 289 } |
| 273 | 290 |
| 274 /** | 291 /** |
| 275 * Visitor used to determine the replacement offset and length | 292 * Visitor used to determine the replacement offset and length |
| 276 * based upon the cursor location. | 293 * based upon the cursor location. |
| 277 */ | 294 */ |
| 278 class _ReplacementOffsetBuilder extends SimpleAstVisitor { | 295 class _ReplacementOffsetBuilder extends SimpleAstVisitor { |
| 279 final DartCompletionRequest request; | 296 final DartCompletionRequest request; |
| 280 | 297 |
| 281 _ReplacementOffsetBuilder(this.request) { | 298 _ReplacementOffsetBuilder(this.request) { |
| 282 request.replacementOffset = request.offset; | 299 request.replacementOffset = request.offset; |
| 283 request.replacementLength = 0; | 300 request.replacementLength = 0; |
| 284 } | 301 } |
| 285 | 302 |
| 286 visitSimpleIdentifier(SimpleIdentifier node) { | 303 visitSimpleIdentifier(SimpleIdentifier node) { |
| 287 request.replacementOffset = node.offset; | 304 request.replacementOffset = node.offset; |
| 288 request.replacementLength = node.length; | 305 request.replacementLength = node.length; |
| 289 } | 306 } |
| 290 } | 307 } |
| OLD | NEW |