Index: pkg/analysis_server/lib/src/computer/computer_navigation.dart |
diff --git a/pkg/analysis_server/lib/src/computer/computer_navigation.dart b/pkg/analysis_server/lib/src/computer/computer_navigation.dart |
index 2236ee4d5cf0cb912c4e3e92d405f450e14f24cd..504bf407323b1315f48b1073cef074be82fb5989 100644 |
--- a/pkg/analysis_server/lib/src/computer/computer_navigation.dart |
+++ b/pkg/analysis_server/lib/src/computer/computer_navigation.dart |
@@ -10,6 +10,7 @@ import 'package:analysis_server/src/protocol_server.dart' as protocol; |
import 'package:analyzer/src/generated/ast.dart'; |
import 'package:analyzer/src/generated/element.dart'; |
import 'package:analyzer/src/generated/scanner.dart'; |
+import 'package:analyzer/src/generated/source.dart'; |
/** |
* A computer for navigation regions in a Dart [CompilationUnit]. |
@@ -161,8 +162,8 @@ class _DartUnitNavigationComputerVisitor extends RecursiveAstVisitor { |
visitExportDirective(ExportDirective node) { |
ExportElement exportElement = node.element; |
if (exportElement != null) { |
- Element element = exportElement.exportedLibrary; |
- computer._addRegion_tokenStart_nodeEnd(node.keyword, node.uri, element); |
+ Element libraryElement = exportElement.exportedLibrary; |
+ _addUriDirectiveRegion(node, libraryElement); |
} |
super.visitExportDirective(node); |
} |
@@ -171,8 +172,8 @@ class _DartUnitNavigationComputerVisitor extends RecursiveAstVisitor { |
visitImportDirective(ImportDirective node) { |
ImportElement importElement = node.element; |
if (importElement != null) { |
- Element element = importElement.importedLibrary; |
- computer._addRegion_tokenStart_nodeEnd(node.keyword, node.uri, element); |
+ Element libraryElement = importElement.importedLibrary; |
+ _addUriDirectiveRegion(node, libraryElement); |
} |
super.visitImportDirective(node); |
} |
@@ -185,8 +186,7 @@ class _DartUnitNavigationComputerVisitor extends RecursiveAstVisitor { |
@override |
visitPartDirective(PartDirective node) { |
- computer._addRegion_tokenStart_nodeEnd( |
- node.keyword, node.uri, node.element); |
+ _addUriDirectiveRegion(node, node.element); |
super.visitPartDirective(node); |
} |
@@ -260,6 +260,19 @@ class _DartUnitNavigationComputerVisitor extends RecursiveAstVisitor { |
} |
} |
+ /** |
+ * If the source of the given [element] (referenced by the [node]) exists, |
+ * then add the navigation region from the [node] to the [element]. |
+ */ |
+ void _addUriDirectiveRegion(UriBasedDirective node, Element element) { |
+ if (element != null) { |
+ Source source = element.source; |
+ if (element.context.exists(source)) { |
+ computer._addRegion_tokenStart_nodeEnd(node.keyword, node.uri, element); |
+ } |
+ } |
+ } |
+ |
void _safelyVisit(AstNode node) { |
if (node != null) { |
node.accept(this); |