| 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 test.services.completion.util; | 5 library test.services.completion.util; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol.dart' as protocol show Element, | 9 import 'package:analysis_server/src/protocol.dart' as protocol show Element, |
| 10 ElementKind; | 10 ElementKind; |
| 11 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind; | 11 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind; |
| 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/completion_target.dart'; |
| 13 import 'package:analysis_server/src/services/completion/dart_completion_cache.da
rt'; | 14 import 'package:analysis_server/src/services/completion/dart_completion_cache.da
rt'; |
| 14 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; | 15 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
| 15 import 'package:analysis_server/src/services/completion/imported_computer.dart'; | 16 import 'package:analysis_server/src/services/completion/imported_computer.dart'; |
| 16 import 'package:analysis_server/src/services/completion/invocation_computer.dart
'; | 17 import 'package:analysis_server/src/services/completion/invocation_computer.dart
'; |
| 17 import 'package:analysis_server/src/services/completion/local_computer.dart'; | 18 import 'package:analysis_server/src/services/completion/local_computer.dart'; |
| 18 import 'package:analysis_server/src/services/index/index.dart'; | 19 import 'package:analysis_server/src/services/index/index.dart'; |
| 19 import 'package:analysis_server/src/services/index/local_memory_index.dart'; | 20 import 'package:analysis_server/src/services/index/local_memory_index.dart'; |
| 20 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; | 21 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; |
| 21 import 'package:analyzer/src/generated/ast.dart'; | 22 import 'package:analyzer/src/generated/ast.dart'; |
| 22 import 'package:analyzer/src/generated/element.dart'; | 23 import 'package:analyzer/src/generated/element.dart'; |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 } | 415 } |
| 415 } | 416 } |
| 416 | 417 |
| 417 bool computeFast() { | 418 bool computeFast() { |
| 418 _computeFastCalled = true; | 419 _computeFastCalled = true; |
| 419 testUnit = context.parseCompilationUnit(testSource); | 420 testUnit = context.parseCompilationUnit(testSource); |
| 420 completionNode = | 421 completionNode = |
| 421 new NodeLocator.con1(completionOffset).searchWithin(testUnit); | 422 new NodeLocator.con1(completionOffset).searchWithin(testUnit); |
| 422 request.unit = testUnit; | 423 request.unit = testUnit; |
| 423 request.node = completionNode; | 424 request.node = completionNode; |
| 425 request.target = new CompletionTarget.forOffset(testUnit, completionOffset); |
| 424 return computer.computeFast(request); | 426 return computer.computeFast(request); |
| 425 } | 427 } |
| 426 | 428 |
| 427 Future computeFull(assertFunction(bool result), {bool fullAnalysis: true}) { | 429 Future computeFull(assertFunction(bool result), {bool fullAnalysis: true}) { |
| 428 if (!_computeFastCalled) { | 430 if (!_computeFastCalled) { |
| 429 expect(computeFast(), isFalse); | 431 expect(computeFast(), isFalse); |
| 430 } | 432 } |
| 431 | 433 |
| 432 // Index SDK | 434 // Index SDK |
| 433 for (Source librarySource in context.librarySources) { | 435 for (Source librarySource in context.librarySources) { |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 // the user may be either (1) entering a type for the assignment | 944 // the user may be either (1) entering a type for the assignment |
| 943 // or (2) starting a new statement. | 945 // or (2) starting a new statement. |
| 944 // Consider suggesting only types | 946 // Consider suggesting only types |
| 945 // if only spaces separates the 1st and 2nd identifiers. | 947 // if only spaces separates the 1st and 2nd identifiers. |
| 946 //assertNotSuggested('a'); | 948 //assertNotSuggested('a'); |
| 947 //assertNotSuggested('main'); | 949 //assertNotSuggested('main'); |
| 948 //assertNotSuggested('identical'); | 950 //assertNotSuggested('identical'); |
| 949 }); | 951 }); |
| 950 } | 952 } |
| 951 | 953 |
| 954 test_AssignmentExpression_type_newline() { |
| 955 // SimpleIdentifier TypeName VariableDeclarationList |
| 956 // VariableDeclarationStatement Block |
| 957 addTestSource(''' |
| 958 class A {} main() { |
| 959 int a; |
| 960 ^ |
| 961 b = 1;}'''); |
| 962 computeFast(); |
| 963 return computeFull((bool result) { |
| 964 assertSuggestLocalClass('A'); |
| 965 assertSuggestImportedClass('int'); |
| 966 // Allow non-types preceding an identifier on LHS of assignment |
| 967 // if newline follows first identifier |
| 968 // because user is probably starting a new statement |
| 969 assertSuggestLocalVariable('a', 'int'); |
| 970 assertSuggestLocalFunction('main', null); |
| 971 assertSuggestImportedFunction('identical', 'bool'); |
| 972 }); |
| 973 } |
| 974 |
| 952 test_AssignmentExpression_type_partial() { | 975 test_AssignmentExpression_type_partial() { |
| 953 // SimpleIdentifier TypeName VariableDeclarationList | 976 // SimpleIdentifier TypeName VariableDeclarationList |
| 954 // VariableDeclarationStatement Block | 977 // VariableDeclarationStatement Block |
| 955 addTestSource(''' | 978 addTestSource(''' |
| 956 class A {} main() { | 979 class A {} main() { |
| 957 int a; | 980 int a; |
| 958 int^ b = 1;}'''); | 981 int^ b = 1;}'''); |
| 959 computeFast(); | 982 computeFast(); |
| 960 return computeFull((bool result) { | 983 return computeFull((bool result) { |
| 961 assertSuggestLocalClass('A'); | 984 assertSuggestLocalClass('A'); |
| 962 assertSuggestImportedClass('int'); | 985 assertSuggestImportedClass('int'); |
| 963 // TODO (danrubel) When entering 1st of 2 identifiers on assignment LHS | 986 // TODO (danrubel) When entering 1st of 2 identifiers on assignment LHS |
| 964 // the user may be either (1) entering a type for the assignment | 987 // the user may be either (1) entering a type for the assignment |
| 965 // or (2) starting a new statement. | 988 // or (2) starting a new statement. |
| 966 // Consider suggesting only types | 989 // Consider suggesting only types |
| 967 // if only spaces separates the 1st and 2nd identifiers. | 990 // if only spaces separates the 1st and 2nd identifiers. |
| 968 //assertNotSuggested('a'); | 991 //assertNotSuggested('a'); |
| 969 //assertNotSuggested('main'); | 992 //assertNotSuggested('main'); |
| 970 //assertNotSuggested('identical'); | 993 //assertNotSuggested('identical'); |
| 971 }); | 994 }); |
| 972 } | 995 } |
| 973 | 996 |
| 974 test_AssignmentExpression_type_newline() { | |
| 975 // SimpleIdentifier TypeName VariableDeclarationList | |
| 976 // VariableDeclarationStatement Block | |
| 977 addTestSource(''' | |
| 978 class A {} main() { | |
| 979 int a; | |
| 980 ^ | |
| 981 b = 1;}'''); | |
| 982 computeFast(); | |
| 983 return computeFull((bool result) { | |
| 984 assertSuggestLocalClass('A'); | |
| 985 assertSuggestImportedClass('int'); | |
| 986 // Allow non-types preceding an identifier on LHS of assignment | |
| 987 // if newline follows first identifier | |
| 988 // because user is probably starting a new statement | |
| 989 assertSuggestLocalVariable('a', 'int'); | |
| 990 assertSuggestLocalFunction('main', null); | |
| 991 assertSuggestImportedFunction('identical', 'bool'); | |
| 992 }); | |
| 993 } | |
| 994 | |
| 995 test_AssignmentExpression_type_partial_newline() { | 997 test_AssignmentExpression_type_partial_newline() { |
| 996 // SimpleIdentifier TypeName VariableDeclarationList | 998 // SimpleIdentifier TypeName VariableDeclarationList |
| 997 // VariableDeclarationStatement Block | 999 // VariableDeclarationStatement Block |
| 998 addTestSource(''' | 1000 addTestSource(''' |
| 999 class A {} main() { | 1001 class A {} main() { |
| 1000 int a; | 1002 int a; |
| 1001 i^ | 1003 i^ |
| 1002 b = 1;}'''); | 1004 b = 1;}'''); |
| 1003 computeFast(); | 1005 computeFast(); |
| 1004 return computeFull((bool result) { | 1006 return computeFull((bool result) { |
| (...skipping 1406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2411 assertNotSuggested('bar2'); | 2413 assertNotSuggested('bar2'); |
| 2412 assertNotSuggested('_B'); | 2414 assertNotSuggested('_B'); |
| 2413 assertSuggestLocalClass('Y'); | 2415 assertSuggestLocalClass('Y'); |
| 2414 assertSuggestLocalClass('C'); | 2416 assertSuggestLocalClass('C'); |
| 2415 assertSuggestLocalVariable('f', null); | 2417 assertSuggestLocalVariable('f', null); |
| 2416 assertNotSuggested('x'); | 2418 assertNotSuggested('x'); |
| 2417 assertNotSuggested('e'); | 2419 assertNotSuggested('e'); |
| 2418 }); | 2420 }); |
| 2419 } | 2421 } |
| 2420 } | 2422 } |
| OLD | NEW |