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

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

Issue 1403373018: Fix for regions reported with multiple targets. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « no previous file | pkg/analysis_server/test/analysis/navigation_collector_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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; 5 library domains.analysis.navigation;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analysis_server/plugin/analysis/navigation/navigation_core.dart' ; 9 import 'package:analysis_server/plugin/analysis/navigation/navigation_core.dart' ;
10 import 'package:analysis_server/src/analysis_server.dart'; 10 import 'package:analysis_server/src/analysis_server.dart';
11 import 'package:analysis_server/src/collections.dart'; 11 import 'package:analysis_server/src/collections.dart';
12 import 'package:analysis_server/src/protocol_server.dart' as protocol; 12 import 'package:analysis_server/src/protocol_server.dart' as protocol;
13 import 'package:analyzer/src/generated/engine.dart' 13 import 'package:analyzer/src/generated/engine.dart'
14 show AnalysisContext, AnalysisEngine; 14 show AnalysisContext, AnalysisEngine;
15 import 'package:analyzer/src/generated/java_engine.dart' show CaughtException; 15 import 'package:analyzer/src/generated/java_engine.dart' show CaughtException;
16 import 'package:analyzer/src/generated/source.dart' show Source; 16 import 'package:analyzer/src/generated/source.dart' show Source, SourceRange;
17 17
18 /** 18 /**
19 * Compute all known navigation information for the given part of [source]. 19 * Compute all known navigation information for the given part of [source].
20 */ 20 */
21 NavigationCollectorImpl computeNavigation(AnalysisServer server, 21 NavigationCollectorImpl computeNavigation(AnalysisServer server,
22 AnalysisContext context, Source source, int offset, int length) { 22 AnalysisContext context, Source source, int offset, int length) {
23 NavigationCollectorImpl collector = new NavigationCollectorImpl(); 23 NavigationCollectorImpl collector = new NavigationCollectorImpl();
24 List<NavigationContributor> contributors = 24 List<NavigationContributor> contributors =
25 server.serverPlugin.navigationContributors; 25 server.serverPlugin.navigationContributors;
26 for (NavigationContributor contributor in contributors) { 26 for (NavigationContributor contributor in contributors) {
27 try { 27 try {
28 contributor.computeNavigation(collector, context, source, offset, length); 28 contributor.computeNavigation(collector, context, source, offset, length);
29 } catch (exception, stackTrace) { 29 } catch (exception, stackTrace) {
30 AnalysisEngine.instance.logger.logError( 30 AnalysisEngine.instance.logger.logError(
31 'Exception from navigation contributor: ${contributor.runtimeType}', 31 'Exception from navigation contributor: ${contributor.runtimeType}',
32 new CaughtException(exception, stackTrace)); 32 new CaughtException(exception, stackTrace));
33 } 33 }
34 } 34 }
35 collector.sortRegions(); 35 collector.createRegions();
36 return collector; 36 return collector;
37 } 37 }
38 38
39 /** 39 /**
40 * A concrete implementation of [NavigationCollector]. 40 * A concrete implementation of [NavigationCollector].
41 */ 41 */
42 class NavigationCollectorImpl implements NavigationCollector { 42 class NavigationCollectorImpl implements NavigationCollector {
43 /** 43 /**
44 * A list of navigation regions. 44 * A list of navigation regions.
45 */ 45 */
46 final List<protocol.NavigationRegion> regions = <protocol.NavigationRegion>[]; 46 final List<protocol.NavigationRegion> regions = <protocol.NavigationRegion>[];
47 final Map<SourceRange, List<int>> regionMap =
48 new HashMap<SourceRange, List<int>>();
47 49
48 /** 50 /**
49 * All the unique targets referenced by [regions]. 51 * All the unique targets referenced by [regions].
50 */ 52 */
51 final List<protocol.NavigationTarget> targets = <protocol.NavigationTarget>[]; 53 final List<protocol.NavigationTarget> targets = <protocol.NavigationTarget>[];
52 final Map<Pair<protocol.ElementKind, protocol.Location>, int> targetMap = 54 final Map<Pair<protocol.ElementKind, protocol.Location>, int> targetMap =
53 new HashMap<Pair<protocol.ElementKind, protocol.Location>, int>(); 55 new HashMap<Pair<protocol.ElementKind, protocol.Location>, int>();
54 56
55 /** 57 /**
56 * All the unique files referenced by [targets]. 58 * All the unique files referenced by [targets].
57 */ 59 */
58 final List<String> files = <String>[]; 60 final List<String> files = <String>[];
59 final Map<String, int> fileMap = new HashMap<String, int>(); 61 final Map<String, int> fileMap = new HashMap<String, int>();
60 62
61 @override 63 @override
62 void addRegion(int offset, int length, protocol.ElementKind targetKind, 64 void addRegion(int offset, int length, protocol.ElementKind targetKind,
63 protocol.Location targetLocation) { 65 protocol.Location targetLocation) {
66 SourceRange range = new SourceRange(offset, length);
67 // prepare targets
68 List<int> targets = regionMap[range];
69 if (targets == null) {
70 targets = <int>[];
71 regionMap[range] = targets;
72 }
73 // add new target
64 int targetIndex = _addTarget(targetKind, targetLocation); 74 int targetIndex = _addTarget(targetKind, targetLocation);
65 protocol.NavigationRegion region = 75 targets.add(targetIndex);
66 new protocol.NavigationRegion(offset, length, <int>[targetIndex]);
67 regions.add(region);
68 } 76 }
69 77
70 void sortRegions() { 78 void createRegions() {
79 regionMap.forEach((range, targets) {
80 protocol.NavigationRegion region =
81 new protocol.NavigationRegion(range.offset, range.length, targets);
82 regions.add(region);
83 });
71 regions.sort((a, b) { 84 regions.sort((a, b) {
72 return a.offset - b.offset; 85 return a.offset - b.offset;
73 }); 86 });
74 } 87 }
75 88
76 int _addFile(String file) { 89 int _addFile(String file) {
77 int index = fileMap[file]; 90 int index = fileMap[file];
78 if (index == null) { 91 if (index == null) {
79 index = files.length; 92 index = files.length;
80 files.add(file); 93 files.add(file);
(...skipping 16 matching lines...) Expand all
97 location.offset, 110 location.offset,
98 location.length, 111 location.length,
99 location.startLine, 112 location.startLine,
100 location.startColumn); 113 location.startColumn);
101 targets.add(target); 114 targets.add(target);
102 targetMap[pair] = index; 115 targetMap[pair] = index;
103 } 116 }
104 return index; 117 return index;
105 } 118 }
106 } 119 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/analysis/navigation_collector_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698