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/analysis_server.dart'; | 9 import 'package:analysis_server/src/analysis_server.dart'; |
10 import 'package:analysis_server/src/protocol.dart' as protocol | 10 import 'package:analysis_server/src/protocol.dart' as protocol |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 int completionOffset; | 45 int completionOffset; |
46 AstNode completionNode; | 46 AstNode completionNode; |
47 bool computeFastResult; | 47 bool computeFastResult; |
48 DartCompletionRequest request; | 48 DartCompletionRequest request; |
49 DartCompletionCache cache; | 49 DartCompletionCache cache; |
50 DartCompletionManager _completionManager; | 50 DartCompletionManager _completionManager; |
51 | 51 |
52 void addResolvedUnit(String file, String code) { | 52 void addResolvedUnit(String file, String code) { |
53 Source source = addSource(file, code); | 53 Source source = addSource(file, code); |
54 CompilationUnit unit = resolveLibraryUnit(source); | 54 CompilationUnit unit = resolveLibraryUnit(source); |
55 index.indexUnit(context, unit); | 55 index.index(context, unit); |
56 } | 56 } |
57 | 57 |
58 void addTestSource(String content) { | 58 void addTestSource(String content) { |
59 expect(completionOffset, isNull, reason: 'Call addTestUnit exactly once'); | 59 expect(completionOffset, isNull, reason: 'Call addTestUnit exactly once'); |
60 completionOffset = content.indexOf('^'); | 60 completionOffset = content.indexOf('^'); |
61 expect(completionOffset, isNot(equals(-1)), reason: 'missing ^'); | 61 expect(completionOffset, isNot(equals(-1)), reason: 'missing ^'); |
62 int nextOffset = content.indexOf('^', completionOffset + 1); | 62 int nextOffset = content.indexOf('^', completionOffset + 1); |
63 expect(nextOffset, equals(-1), reason: 'too many ^'); | 63 expect(nextOffset, equals(-1), reason: 'too many ^'); |
64 content = content.substring(0, completionOffset) + | 64 content = content.substring(0, completionOffset) + |
65 content.substring(completionOffset + 1); | 65 content.substring(completionOffset + 1); |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 }); | 511 }); |
512 return cs; | 512 return cs; |
513 } | 513 } |
514 | 514 |
515 void resolve(bool fullAnalysis) { | 515 void resolve(bool fullAnalysis) { |
516 // Index SDK | 516 // Index SDK |
517 for (Source librarySource in context.librarySources) { | 517 for (Source librarySource in context.librarySources) { |
518 CompilationUnit unit = | 518 CompilationUnit unit = |
519 context.getResolvedCompilationUnit2(librarySource, librarySource); | 519 context.getResolvedCompilationUnit2(librarySource, librarySource); |
520 if (unit != null) { | 520 if (unit != null) { |
521 index.indexUnit(context, unit); | 521 index.index(context, unit); |
522 } | 522 } |
523 } | 523 } |
524 | 524 |
525 var result = context.performAnalysisTask(); | 525 var result = context.performAnalysisTask(); |
526 bool resolved = false; | 526 bool resolved = false; |
527 while (result.hasMoreWork) { | 527 while (result.hasMoreWork) { |
528 // Update the index | 528 // Update the index |
529 result.changeNotices.forEach((ChangeNotice notice) { | 529 result.changeNotices.forEach((ChangeNotice notice) { |
530 CompilationUnit unit = notice.resolvedDartUnit; | 530 CompilationUnit unit = notice.resolvedDartUnit; |
531 if (unit != null) { | 531 if (unit != null) { |
532 index.indexUnit(context, unit); | 532 index.index(context, unit); |
533 } | 533 } |
534 }); | 534 }); |
535 | 535 |
536 // If the unit has been resolved, then finish the completion | 536 // If the unit has been resolved, then finish the completion |
537 List<Source> libSourceList = context.getLibrariesContaining(testSource); | 537 List<Source> libSourceList = context.getLibrariesContaining(testSource); |
538 if (libSourceList.length > 0) { | 538 if (libSourceList.length > 0) { |
539 LibraryElement library = context.getLibraryElement(libSourceList[0]); | 539 LibraryElement library = context.getLibraryElement(libSourceList[0]); |
540 if (library != null) { | 540 if (library != null) { |
541 CompilationUnit unit = | 541 CompilationUnit unit = |
542 context.getResolvedCompilationUnit(testSource, library); | 542 context.getResolvedCompilationUnit(testSource, library); |
(...skipping 4156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4699 assertNotSuggested('bar2'); | 4699 assertNotSuggested('bar2'); |
4700 assertNotSuggested('_B'); | 4700 assertNotSuggested('_B'); |
4701 assertSuggestLocalClass('Y'); | 4701 assertSuggestLocalClass('Y'); |
4702 assertSuggestLocalClass('C'); | 4702 assertSuggestLocalClass('C'); |
4703 assertSuggestLocalVariable('f', null); | 4703 assertSuggestLocalVariable('f', null); |
4704 assertNotSuggested('x'); | 4704 assertNotSuggested('x'); |
4705 assertNotSuggested('e'); | 4705 assertNotSuggested('e'); |
4706 }); | 4706 }); |
4707 } | 4707 } |
4708 } | 4708 } |
OLD | NEW |