OLD | NEW |
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 services.completion.computer.dart.relevance; | 5 library services.completion.computer.dart.relevance; |
6 | 6 |
7 import 'package:analysis_server/src/protocol_server.dart' as protocol; | 7 import 'package:analysis_server/src/protocol_server.dart' as protocol; |
8 import 'package:analysis_server/src/protocol_server.dart' | 8 import 'package:analysis_server/src/protocol_server.dart' |
9 show CompletionSuggestion, CompletionSuggestionKind; | 9 show CompletionSuggestion, CompletionSuggestionKind; |
10 import 'package:analysis_server/src/provisional/completion/completion_dart.dart'
; | 10 import 'package:analysis_server/src/provisional/completion/completion_core.dart'
; |
| 11 import 'package:analysis_server/src/provisional/completion/dart/completion_targe
t.dart'; |
11 import 'package:analysis_server/src/services/completion/contribution_sorter.dart
'; | 12 import 'package:analysis_server/src/services/completion/contribution_sorter.dart
'; |
12 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart' | 13 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart' |
13 show DART_RELEVANCE_COMMON_USAGE; | 14 show DART_RELEVANCE_COMMON_USAGE; |
14 import 'package:analyzer/src/generated/ast.dart'; | 15 import 'package:analyzer/src/generated/ast.dart'; |
15 import 'package:analyzer/src/generated/element.dart'; | 16 import 'package:analyzer/src/generated/element.dart'; |
16 import 'package:analysis_server/src/provisional/completion/completion_core.dart'
; | 17 import 'package:analyzer/src/task/dart.dart'; |
17 import 'package:analysis_server/src/provisional/completion/dart/completion_targe
t.dart'; | |
18 import 'package:analyzer/task/dart.dart'; | 18 import 'package:analyzer/task/dart.dart'; |
19 import 'package:analyzer/src/task/dart.dart'; | |
20 | 19 |
21 part 'common_usage_generated.dart'; | 20 part 'common_usage_generated.dart'; |
22 | 21 |
23 /** | 22 /** |
24 * A computer for adjusting the relevance of completions computed by others | 23 * A computer for adjusting the relevance of completions computed by others |
25 * based upon common Dart usage patterns. This is a long-lived object | 24 * based upon common Dart usage patterns. This is a long-lived object |
26 * that should not maintain state between calls to it's [sort] method. | 25 * that should not maintain state between calls to it's [sort] method. |
27 */ | 26 */ |
28 class CommonUsageComputer implements ContributionSorter { | 27 class CommonUsageComputer implements ContributionSorter { |
29 /** | 28 /** |
30 * A map of <library>.<classname> to an ordered list of method names, | 29 * A map of <library>.<classname> to an ordered list of method names, |
31 * field names, getter names, and named constructors. | 30 * field names, getter names, and named constructors. |
32 * The names are ordered from most relevant to least relevant. | 31 * The names are ordered from most relevant to least relevant. |
33 * Names not listed are considered equally less relevant than those listed. | 32 * Names not listed are considered equally less relevant than those listed. |
34 */ | 33 */ |
35 Map<String, List<String>> selectorRelevance; | 34 Map<String, List<String>> selectorRelevance; |
36 | 35 |
37 CommonUsageComputer([this.selectorRelevance = defaultSelectorRelevance]); | 36 CommonUsageComputer([this.selectorRelevance = defaultSelectorRelevance]); |
38 | 37 |
39 @override | 38 @override |
40 AnalysisRequest sort( | 39 AnalysisRequest sort(CompletionRequest request, |
41 CompletionRequest request, Iterable<CompletionSuggestion> suggestions) { | 40 Iterable<CompletionSuggestion> suggestions) { |
42 _update(request, suggestions); | 41 _update(request, suggestions); |
43 return null; | 42 return null; |
44 } | 43 } |
45 | 44 |
46 CompletionTarget _getCompletionTarget(CompletionRequest request) { | 45 CompletionTarget _getCompletionTarget(CompletionRequest request) { |
47 // TODO (danrubel) get cached completion target | 46 // TODO (danrubel) get cached completion target |
48 var libSrcs = request.context.getLibrariesContaining(request.source); | 47 var libSrcs = request.context.getLibrariesContaining(request.source); |
49 if (libSrcs.length == 0) { | 48 if (libSrcs.length == 0) { |
50 return null; | 49 return null; |
51 } | 50 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 DartType visitPropertyAccess(PropertyAccess node) { | 153 DartType visitPropertyAccess(PropertyAccess node) { |
155 if (node.propertyName == entity) { | 154 if (node.propertyName == entity) { |
156 Expression target = node.realTarget; | 155 Expression target = node.realTarget; |
157 if (target != null) { | 156 if (target != null) { |
158 return target.bestType; | 157 return target.bestType; |
159 } | 158 } |
160 } | 159 } |
161 return null; | 160 return null; |
162 } | 161 } |
163 } | 162 } |
OLD | NEW |