Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1142)

Side by Side Diff: pkg/analysis_server/lib/src/domains/analysis/navigation_dart.dart

Issue 2582753003: Fix analysis.getNavigation with the new analysis driver. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 domains.analysis.navigation_dart; 5 library domains.analysis.navigation_dart;
6 6
7 import 'package:analysis_server/plugin/analysis/navigation/navigation_core.dart' ; 7 import 'package:analysis_server/plugin/analysis/navigation/navigation_core.dart' ;
8 import 'package:analysis_server/src/protocol_server.dart' as protocol; 8 import 'package:analysis_server/src/protocol_server.dart' as protocol;
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
11 import 'package:analyzer/dart/ast/visitor.dart'; 11 import 'package:analyzer/dart/ast/visitor.dart';
12 import 'package:analyzer/dart/element/element.dart'; 12 import 'package:analyzer/dart/element/element.dart';
13 import 'package:analyzer/src/dart/ast/utilities.dart'; 13 import 'package:analyzer/src/dart/ast/utilities.dart';
14 import 'package:analyzer/src/dart/element/element.dart'; 14 import 'package:analyzer/src/dart/element/element.dart';
15 import 'package:analyzer/src/generated/engine.dart'; 15 import 'package:analyzer/src/generated/engine.dart';
16 import 'package:analyzer/src/generated/source.dart'; 16 import 'package:analyzer/src/generated/source.dart';
17 17
18 NavigationCollector computeSimpleDartNavigation( 18 NavigationCollector computeDartNavigation(NavigationCollector collector,
19 NavigationCollector collector, CompilationUnit unit) { 19 CompilationUnit unit, int offset, int length) {
20 _DartNavigationCollector dartCollector = 20 _DartNavigationCollector dartCollector =
21 new _DartNavigationCollector(collector); 21 new _DartNavigationCollector(collector);
22 _DartNavigationComputerVisitor visitor = 22 _DartNavigationComputerVisitor visitor =
23 new _DartNavigationComputerVisitor(dartCollector); 23 new _DartNavigationComputerVisitor(dartCollector);
24 unit.accept(visitor); 24 if (offset == null || length == null) {
25 unit.accept(visitor);
26 } else {
27 AstNode node = _getNodeForRange(unit, offset, length);
28 node?.accept(visitor);
29 }
25 return collector; 30 return collector;
26 } 31 }
27 32
33 AstNode _getNodeForRange(CompilationUnit unit, int offset, int length) {
34 AstNode node = new NodeLocator(offset, offset + length).searchWithin(unit);
35 for (AstNode n = node; n != null; n = n.parent) {
36 if (n is Directive) {
37 return n;
38 }
39 }
40 return node;
41 }
42
28 /** 43 /**
29 * A computer for navigation regions in a Dart [CompilationUnit]. 44 * A computer for navigation regions in a Dart [CompilationUnit].
30 */ 45 */
31 class DartNavigationComputer implements NavigationContributor { 46 class DartNavigationComputer implements NavigationContributor {
32 @override 47 @override
33 void computeNavigation(NavigationCollector collector, AnalysisContext context, 48 void computeNavigation(NavigationCollector collector, AnalysisContext context,
34 Source source, int offset, int length) { 49 Source source, int offset, int length) {
35 List<Source> libraries = context.getLibrariesContaining(source); 50 List<Source> libraries = context.getLibrariesContaining(source);
36 if (libraries.isNotEmpty) { 51 if (libraries.isNotEmpty) {
37 CompilationUnit unit = 52 CompilationUnit unit =
38 context.getResolvedCompilationUnit2(source, libraries.first); 53 context.getResolvedCompilationUnit2(source, libraries.first);
39 if (unit != null) { 54 if (unit != null) {
40 _DartNavigationCollector dartCollector = 55 computeDartNavigation(collector, unit, offset, length);
41 new _DartNavigationCollector(collector);
42 _DartNavigationComputerVisitor visitor =
43 new _DartNavigationComputerVisitor(dartCollector);
44 if (offset == null || length == null) {
45 unit.accept(visitor);
46 } else {
47 AstNode node = _getNodeForRange(unit, offset, length);
48 node?.accept(visitor);
49 }
50 } 56 }
51 } 57 }
52 } 58 }
53
54 static AstNode _getNodeForRange(
55 CompilationUnit unit, int offset, int length) {
56 AstNode node = new NodeLocator(offset, offset + length).searchWithin(unit);
57 for (AstNode n = node; n != null; n = n.parent) {
58 if (n is Directive) {
59 return n;
60 }
61 }
62 return node;
63 }
64 } 59 }
65 60
66 /** 61 /**
67 * A Dart specific wrapper around [NavigationCollector]. 62 * A Dart specific wrapper around [NavigationCollector].
68 */ 63 */
69 class _DartNavigationCollector { 64 class _DartNavigationCollector {
70 final NavigationCollector collector; 65 final NavigationCollector collector;
71 66
72 _DartNavigationCollector(this.collector); 67 _DartNavigationCollector(this.collector);
73 68
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 */ 323 */
329 void _addUriDirectiveRegion(UriBasedDirective node, Element element) { 324 void _addUriDirectiveRegion(UriBasedDirective node, Element element) {
330 if (element != null) { 325 if (element != null) {
331 Source source = element.source; 326 Source source = element.source;
332 if (element.context.exists(source)) { 327 if (element.context.exists(source)) {
333 computer._addRegionForNode(node.uri, element); 328 computer._addRegionForNode(node.uri, element);
334 } 329 }
335 } 330 }
336 } 331 }
337 } 332 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/domain_analysis.dart ('k') | pkg/analysis_server/test/analysis/get_navigation_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698