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

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

Issue 901253002: move relevance computation from client to server (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix test Created 5 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.toplevel; 5 library services.completion.computer.dart.toplevel;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analysis_server/src/protocol_server.dart' hide Element, 10 import 'package:analysis_server/src/protocol_server.dart' hide Element,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 } 104 }
105 if (future != null) { 105 if (future != null) {
106 return future.then(addSuggestions); 106 return future.then(addSuggestions);
107 } 107 }
108 return addSuggestions(true); 108 return addSuggestions(true);
109 } 109 }
110 110
111 /** 111 /**
112 * Add imported element suggestions. 112 * Add imported element suggestions.
113 */ 113 */
114 void _addElementSuggestions(List<Element> elements) { 114 void _addElementSuggestions(List<Element> elements, {int relevance:
115 COMPLETION_RELEVANCE_DEFAULT}) {
115 elements.forEach((Element elem) { 116 elements.forEach((Element elem) {
116 if (elem is! ClassElement) { 117 if (elem is! ClassElement) {
117 if (typesOnly) { 118 if (typesOnly) {
118 return; 119 return;
119 } 120 }
120 if (elem is ExecutableElement) { 121 if (elem is ExecutableElement) {
121 DartType returnType = elem.returnType; 122 DartType returnType = elem.returnType;
122 if (returnType != null && returnType.isVoid) { 123 if (returnType != null && returnType.isVoid) {
123 if (excludeVoidReturn) { 124 if (excludeVoidReturn) {
124 return; 125 return;
125 } 126 }
126 } 127 }
127 } 128 }
128 } 129 }
129 addSuggestion(elem); 130 addSuggestion(elem, relevance: relevance);
130 }); 131 });
131 } 132 }
132 133
133 /** 134 /**
134 * Add suggestions for any inherited imported members. 135 * Add suggestions for any inherited imported members.
135 */ 136 */
136 void _addInheritedSuggestions(AstNode node) { 137 void _addInheritedSuggestions(AstNode node) {
137 var classDecl = node.getAncestor((p) => p is ClassDeclaration); 138 var classDecl = node.getAncestor((p) => p is ClassDeclaration);
138 if (classDecl is ClassDeclaration) { 139 if (classDecl is ClassDeclaration) {
139 // Build a list of inherited types that are imported 140 // Build a list of inherited types that are imported
140 // and include any inherited imported members 141 // and include any inherited imported members
141 List<String> inheritedTypes = new List<String>(); 142 List<String> inheritedTypes = new List<String>();
142 visitInheritedTypes(classDecl, (_) { 143 visitInheritedTypes(classDecl, (_) {
143 // local declarations are handled by the local computer 144 // local declarations are handled by the local computer
144 }, (String typeName) { 145 }, (String typeName) {
145 inheritedTypes.add(typeName); 146 inheritedTypes.add(typeName);
146 }); 147 });
147 HashSet<String> visited = new HashSet<String>(); 148 HashSet<String> visited = new HashSet<String>();
148 while (inheritedTypes.length > 0) { 149 while (inheritedTypes.length > 0) {
149 String name = inheritedTypes.removeLast(); 150 String name = inheritedTypes.removeLast();
150 ClassElement elem = cache.importedClassMap[name]; 151 ClassElement elem = cache.importedClassMap[name];
151 if (visited.add(name) && elem != null) { 152 if (visited.add(name) && elem != null) {
152 _addElementSuggestions(elem.fields); 153 _addElementSuggestions(
153 _addElementSuggestions(elem.accessors); 154 elem.fields,
154 _addElementSuggestions(elem.methods); 155 relevance: DART_RELEVANCE_INHERITED_FIELD);
156 _addElementSuggestions(
157 elem.accessors,
158 relevance: DART_RELEVANCE_INHERITED_ACCESSOR);
159 _addElementSuggestions(
160 elem.methods,
161 relevance: DART_RELEVANCE_INHERITED_METHOD);
155 elem.allSupertypes.forEach((InterfaceType type) { 162 elem.allSupertypes.forEach((InterfaceType type) {
156 if (visited.add(type.name) && type.element != null) { 163 if (visited.add(type.name) && type.element != null) {
157 _addElementSuggestions(type.element.fields); 164 _addElementSuggestions(
158 _addElementSuggestions(type.element.accessors); 165 type.element.fields,
159 _addElementSuggestions(type.element.methods); 166 relevance: DART_RELEVANCE_INHERITED_FIELD);
167 _addElementSuggestions(
168 type.element.accessors,
169 relevance: DART_RELEVANCE_INHERITED_ACCESSOR);
170 _addElementSuggestions(
171 type.element.methods,
172 relevance: DART_RELEVANCE_INHERITED_METHOD);
160 } 173 }
161 }); 174 });
162 } 175 }
163 } 176 }
164 } 177 }
165 } 178 }
166 179
167 /** 180 /**
168 * Add top level suggestions from the cache. 181 * Add top level suggestions from the cache.
169 * To reduce the number of suggestions sent to the client, 182 * To reduce the number of suggestions sent to the client,
(...skipping 26 matching lines...) Expand all
196 addFilteredSuggestions(cache.importedTypeSuggestions); 209 addFilteredSuggestions(cache.importedTypeSuggestions);
197 addFilteredSuggestions(cache.libraryPrefixSuggestions); 210 addFilteredSuggestions(cache.libraryPrefixSuggestions);
198 if (!typesOnly) { 211 if (!typesOnly) {
199 addFilteredSuggestions(cache.otherImportedSuggestions); 212 addFilteredSuggestions(cache.otherImportedSuggestions);
200 if (!excludeVoidReturn) { 213 if (!excludeVoidReturn) {
201 addFilteredSuggestions(cache.importedVoidReturnSuggestions); 214 addFilteredSuggestions(cache.importedVoidReturnSuggestions);
202 } 215 }
203 } 216 }
204 } 217 }
205 } 218 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698