Skip to content

Commit

Permalink
Issue 24599. Fix for requesting navigation for directives.
Browse files Browse the repository at this point in the history
R=brianwilkerson@google.com
BUG= #24599

Review URL: https://codereview.chromium.org/1405033002 .
  • Loading branch information
scheglov committed Oct 15, 2015
1 parent 9e8c868 commit a30bcd7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
Expand Up @@ -58,8 +58,7 @@ class _DartNavigationCollector {
if (element.location == null) {
return;
}
protocol.ElementKind kind =
protocol.convertElementKind(element.kind);
protocol.ElementKind kind = protocol.convertElementKind(element.kind);
protocol.Location location = protocol.newLocation_fromElement(element);
if (location == null) {
return;
Expand Down Expand Up @@ -326,9 +325,11 @@ class _DartRangeAstVisitor extends UnifyingAstVisitor {
return;
}
// The node starts or ends in the range.
if (isInRange(node.offset) || isInRange(node.end)) {
node.accept(visitor);
return;
if (node is! CompilationUnit) {
if (isInRange(node.offset) || isInRange(node.end) || node is Directive) {
node.accept(visitor);
return;
}
}
// Go deeper.
super.visitNode(node);
Expand Down
42 changes: 42 additions & 0 deletions pkg/analysis_server/test/analysis/get_navigation_test.dart
Expand Up @@ -58,6 +58,48 @@ main() {
return _checkInvalid(file, -1, -1);
}

test_issue24599_importDirective() async {
addTestFile('''
import 'dart:math';
main() {
}''');
await waitForTasksFinished();
await _getNavigation(testFile, 0, 17);
expect(regions, hasLength(1));
assertHasRegionString("'dart:math'");
expect(testTargets, hasLength(1));
expect(testTargets[0].kind, ElementKind.LIBRARY);
}

test_issue24599_importKeyword() async {
addTestFile('''
import 'dart:math';
main() {
}''');
await waitForTasksFinished();
await _getNavigation(testFile, 0, 1);
expect(regions, hasLength(1));
assertHasRegionString("'dart:math'");
expect(testTargets, hasLength(1));
expect(testTargets[0].kind, ElementKind.LIBRARY);
}

test_issue24599_importUri() async {
addTestFile('''
import 'dart:math';
main() {
}''');
await waitForTasksFinished();
await _getNavigation(testFile, 7, 11);
expect(regions, hasLength(1));
assertHasRegionString("'dart:math'");
expect(testTargets, hasLength(1));
expect(testTargets[0].kind, ElementKind.LIBRARY);
}

test_multipleRegions() async {
addTestFile('''
main() {
Expand Down
Expand Up @@ -26,15 +26,14 @@ class AbstractNavigationTest extends AbstractAnalysisTest {

NavigationRegion testRegion;
List<int> testTargetIndexes;
List<NavigationTarget> testTargets;
NavigationTarget testTarget;

/**
* Validates that there is a target in [testTargetIndexes] with [file],
* at [offset] and with the given [length].
*/
void assertHasFileTarget(String file, int offset, int length) {
List<NavigationTarget> testTargets =
testTargetIndexes.map((int index) => targets[index]).toList();
for (NavigationTarget target in testTargets) {
if (targetFiles[target.fileIndex] == file &&
target.offset == offset &&
Expand Down Expand Up @@ -167,6 +166,7 @@ class AbstractNavigationTest extends AbstractAnalysisTest {
}
testRegion = region;
testTargetIndexes = region.targets;
testTargets = testTargetIndexes.map((i) => targets[i]).toList();
return;
}
}
Expand Down

0 comments on commit a30bcd7

Please sign in to comment.