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

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

Issue 580623002: add element to completion suggestions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 6 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 | 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.suggestion.builder; 5 library services.completion.suggestion.builder;
6 6
7 import 'package:analysis_server/src/protocol.dart' hide Element; 7 import 'package:analysis_server/src/protocol.dart' as protocol show Element, Ele mentKind;
8 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind;
8 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart'; 9 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart';
9 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
10 11
11 /** 12 /**
12 * This class visits elements in a class and provides suggestions based upon 13 * This class visits elements in a class and provides suggestions based upon
13 * the visible members in that class. Clients should call 14 * the visible members in that class. Clients should call
14 * [ClassElementSuggestionBuilder.suggestionsFor]. 15 * [ClassElementSuggestionBuilder.suggestionsFor].
15 */ 16 */
16 class ClassElementSuggestionBuilder extends GeneralizingElementVisitor { 17 class ClassElementSuggestionBuilder extends GeneralizingElementVisitor {
17 final DartCompletionRequest request; 18 final DartCompletionRequest request;
(...skipping 11 matching lines...) Expand all
29 30
30 @override 31 @override
31 visitElement(Element element) { 32 visitElement(Element element) {
32 // ignored 33 // ignored
33 } 34 }
34 35
35 @override 36 @override
36 visitFieldElement(FieldElement element) { 37 visitFieldElement(FieldElement element) {
37 _addSuggestion( 38 _addSuggestion(
38 element, 39 element,
39 CompletionSuggestionKind.FIELD, 40 CompletionSuggestionKind.GETTER,
40 element.type, 41 element.type,
41 element.enclosingElement); 42 element.enclosingElement);
42 } 43 }
43 44
44 @override 45 @override
45 visitMethodElement(MethodElement element) { 46 visitMethodElement(MethodElement element) {
46 _addSuggestion( 47 _addSuggestion(
47 element, 48 element,
48 CompletionSuggestionKind.METHOD, 49 CompletionSuggestionKind.METHOD,
49 element.returnType, 50 element.returnType,
(...skipping 30 matching lines...) Expand all
80 if (elementLibrary != unitLibrary) { 81 if (elementLibrary != unitLibrary) {
81 return; 82 return;
82 } 83 }
83 } 84 }
84 String completion = element.displayName; 85 String completion = element.displayName;
85 if (completion == null || 86 if (completion == null ||
86 completion.length <= 0 || 87 completion.length <= 0 ||
87 !_completions.add(completion)) { 88 !_completions.add(completion)) {
88 return; 89 return;
89 } 90 }
90 var suggestion = new CompletionSuggestion( 91 CompletionSuggestion suggestion = new CompletionSuggestion(
91 kind, 92 kind,
92 CompletionRelevance.DEFAULT, 93 CompletionRelevance.DEFAULT,
93 completion, 94 completion,
94 completion.length, 95 completion.length,
95 0, 96 0,
96 element.isDeprecated, 97 element.isDeprecated,
97 false); 98 false);
99 suggestion.element = new protocol.Element.fromEngine(element);
100 if (suggestion.element != null) {
101 if (element is FieldElement) {
102 suggestion.element.kind = protocol.ElementKind.GETTER;
103 suggestion.element.returnType =
104 element.type != null ? element.type.displayName : 'dynamic';
105 }
106 }
98 if (enclosingElement != null) { 107 if (enclosingElement != null) {
99 suggestion.declaringType = enclosingElement.displayName; 108 suggestion.declaringType = enclosingElement.displayName;
100 } 109 }
101 if (type != null) { 110 if (type != null) {
102 String typeName = type.displayName; 111 String typeName = type.displayName;
103 if (typeName != null && typeName.length > 0 && typeName != 'dynamic') { 112 if (typeName != null && typeName.length > 0 && typeName != 'dynamic') {
104 suggestion.returnType = typeName; 113 suggestion.returnType = typeName;
105 } 114 }
106 } 115 }
107 request.suggestions.add(suggestion); 116 request.suggestions.add(suggestion);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 159
151 @override 160 @override
152 visitTopLevelVariableElement(TopLevelVariableElement element) { 161 visitTopLevelVariableElement(TopLevelVariableElement element) {
153 _addSuggestion(element); 162 _addSuggestion(element);
154 } 163 }
155 164
156 void _addSuggestion(Element element) { 165 void _addSuggestion(Element element) {
157 if (element != null) { 166 if (element != null) {
158 String completion = element.name; 167 String completion = element.name;
159 if (completion != null && completion.length > 0) { 168 if (completion != null && completion.length > 0) {
160 request.suggestions.add( 169 CompletionSuggestion suggestion = new CompletionSuggestion(
161 new CompletionSuggestion( 170 new CompletionSuggestionKind.fromElementKind(element.kind),
162 new CompletionSuggestionKind.fromElementKind(element.kind), 171 CompletionRelevance.DEFAULT,
163 CompletionRelevance.DEFAULT, 172 completion,
164 completion, 173 completion.length,
165 completion.length, 174 0,
166 0, 175 element.isDeprecated,
167 element.isDeprecated, 176 false);
168 false)); 177
178 suggestion.element = new protocol.Element.fromEngine(element);
179
180 request.suggestions.add(suggestion);
169 } 181 }
170 } 182 }
171 } 183 }
172 184
173 /** 185 /**
174 * Add suggestions for the visible members in the given library 186 * Add suggestions for the visible members in the given library
175 */ 187 */
176 static void suggestionsFor(DartCompletionRequest request, 188 static void suggestionsFor(DartCompletionRequest request,
177 LibraryElement library) { 189 LibraryElement library) {
178 if (library != null) { 190 if (library != null) {
179 library.visitChildren(new LibraryElementSuggestionBuilder(request)); 191 library.visitChildren(new LibraryElementSuggestionBuilder(request));
180 } 192 }
181 } 193 }
182 } 194 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698