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

Side by Side Diff: pkg/analysis_server/lib/src/services/completion/common_usage_computer.dart

Issue 1353913002: Add defaultCompletionSorter allowing sorting to be overridden - fixes #24339 (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 months 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/lib/src/services/completion/contribution_sorter.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 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/services/completion/contribution_sorter.dart ';
10 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart'; 11 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart';
11 import 'package:analyzer/src/generated/ast.dart'; 12 import 'package:analyzer/src/generated/ast.dart';
12 import 'package:analyzer/src/generated/element.dart'; 13 import 'package:analyzer/src/generated/element.dart';
13 14
14 part 'common_usage_generated.dart'; 15 part 'common_usage_generated.dart';
15 16
16 /** 17 /**
17 * A computer for adjusting the relevance of completions computed by others 18 * A computer for adjusting the relevance of completions computed by others
18 * based upon common Dart usage patterns. 19 * based upon common Dart usage patterns. This is a long-lived object
20 * that should not maintain state between calls to it's [sort] method.
19 */ 21 */
20 class CommonUsageComputer { 22 class CommonUsageComputer implements ContributionSorter {
21 /** 23 /**
22 * A map of <library>.<classname> to an ordered list of method names, 24 * A map of <library>.<classname> to an ordered list of method names,
23 * field names, getter names, and named constructors. 25 * field names, getter names, and named constructors.
24 * The names are ordered from most relevant to least relevant. 26 * The names are ordered from most relevant to least relevant.
25 * Names not listed are considered equally less relevant than those listed. 27 * Names not listed are considered equally less relevant than those listed.
26 */ 28 */
27 Map<String, List<String>> selectorRelevance; 29 Map<String, List<String>> selectorRelevance;
28 30
29 CommonUsageComputer([this.selectorRelevance = defaultSelectorRelevance]); 31 CommonUsageComputer([this.selectorRelevance = defaultSelectorRelevance]);
30 32
31 /** 33 @override
32 * Adjusts the relevance based on the given completion context. 34 void sort(DartCompletionRequest request) {
33 * The compilation unit and completion node
34 * in the given completion context may not be resolved.
35 * This method should execute quickly and not block waiting for any analysis.
36 */
37 void computeFast(DartCompletionRequest request) {
38 _update(request); 35 _update(request);
39 } 36 }
40 37
41 /**
42 * Adjusts the relevance based on the given completion context.
43 * The compilation unit and completion node
44 * in the given completion context are resolved.
45 */
46 void computeFull(DartCompletionRequest request) {
47 _update(request);
48 }
49
50 /** 38 /**
51 * Adjusts the relevance based on the given completion context. 39 * Adjusts the relevance based on the given completion context.
52 * The compilation unit and completion node 40 * The compilation unit and completion node
53 * in the given completion context may not be resolved. 41 * in the given completion context may not be resolved.
54 */ 42 */
55 void _update(DartCompletionRequest request) { 43 void _update(DartCompletionRequest request) {
56 var visitor = new _BestTypeVisitor(request.target.entity); 44 var visitor = new _BestTypeVisitor(request.target.entity);
57 DartType type = request.target.containingNode.accept(visitor); 45 DartType type = request.target.containingNode.accept(visitor);
58 if (type != null) { 46 if (type != null) {
59 Element typeElem = type.element; 47 Element typeElem = type.element;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 DartType visitPropertyAccess(PropertyAccess node) { 124 DartType visitPropertyAccess(PropertyAccess node) {
137 if (node.propertyName == entity) { 125 if (node.propertyName == entity) {
138 Expression target = node.realTarget; 126 Expression target = node.realTarget;
139 if (target != null) { 127 if (target != null) {
140 return target.bestType; 128 return target.bestType;
141 } 129 }
142 } 130 }
143 return null; 131 return null;
144 } 132 }
145 } 133 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/completion/contribution_sorter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698