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

Side by Side Diff: pkg/analysis_services/lib/completion/completion_suggestion.dart

Issue 407833002: more progress implementing analysis server code completion (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library server.completion.suggestion;
6
7 import 'package:analysis_services/json.dart';
8
9 import '../constants.dart';
scheglov 2014/07/20 19:09:55 Use package Uri?
danrubel 2014/07/21 12:54:14 Done.
10 import 'package:analyzer/src/generated/element.dart';
11
12 /**
13 * A single completion suggestion.
14 */
15 class CompletionSuggestion implements HasToJson {
16 final CompletionSuggestionKind kind;
17 final CompletionRelevance relevance;
18 final String completion;
19 final int selectionOffset;
20 final int selectionLength;
21 final bool isDeprecated;
22 final bool isPotential;
23
24 CompletionSuggestion(this.kind, this.relevance, this.completion,
25 this.selectionOffset, this.selectionLength, this.isDeprecated,
26 this.isPotential);
27
28 factory CompletionSuggestion.fromJson(Map<String, Object> json) {
29 return new CompletionSuggestion(
30 CompletionSuggestionKind.valueOf(json[KIND]),
31 CompletionRelevance.value(json[RELEVANCE]),
32 json[COMPLETION],
33 json[SELECTION_OFFSET],
34 json[SELECTION_LENGTH],
35 json[IS_DEPRECATED],
36 json[IS_POTENTIAL]);
37 }
38
39 @override
40 Map<String, Object> toJson() {
41 return {
42 KIND: kind.name,
43 RELEVANCE: relevance.name,
44 COMPLETION: completion,
45 SELECTION_OFFSET: selectionOffset,
46 SELECTION_LENGTH: selectionLength,
47 IS_DEPRECATED: isDeprecated,
48 IS_POTENTIAL: isPotential
49 };
50 }
51 }
52
53 /**
54 * An enumeration of the kinds of elements that can be included
55 * in a completion suggestion.
56 */
57 class CompletionSuggestionKind {
58 static const CompletionSuggestionKind CLASS =
59 const CompletionSuggestionKind('CLASS');
60 static const CompletionSuggestionKind CLASS_ALIAS =
61 const CompletionSuggestionKind('CLASS_ALIAS');
62 static const CompletionSuggestionKind CONSTRUCTOR =
63 const CompletionSuggestionKind('CONSTRUCTOR');
64 static const CompletionSuggestionKind FIELD =
65 const CompletionSuggestionKind('FIELD');
66 static const CompletionSuggestionKind FUNCTION =
67 const CompletionSuggestionKind('FUNCTION');
68 static const CompletionSuggestionKind FUNCTION_ALIAS =
69 const CompletionSuggestionKind('FUNCTION_ALIAS');
70 static const CompletionSuggestionKind GETTER =
71 const CompletionSuggestionKind('GETTER');
72 static const CompletionSuggestionKind IMPORT =
73 const CompletionSuggestionKind('IMPORT');
74 static const CompletionSuggestionKind LIBRARY_PREFIX =
75 const CompletionSuggestionKind('LIBRARY_PREFIX');
76 static const CompletionSuggestionKind METHOD =
77 const CompletionSuggestionKind('METHOD');
78 static const CompletionSuggestionKind METHOD_NAME =
79 const CompletionSuggestionKind('METHOD_NAME');
80 static const CompletionSuggestionKind PARAMETER =
81 const CompletionSuggestionKind('PARAMETER');
82 static const CompletionSuggestionKind SETTER =
83 const CompletionSuggestionKind('SETTER');
84 static const CompletionSuggestionKind VARIABLE =
85 const CompletionSuggestionKind('VARIABLE');
86 static const CompletionSuggestionKind TYPE_PARAMETER =
87 const CompletionSuggestionKind('TYPE_PARAMETER');
88 static const CompletionSuggestionKind ARGUMENT_LIST =
89 const CompletionSuggestionKind('ARGUMENT_LIST');
90 static const CompletionSuggestionKind OPTIONAL_ARGUMENT =
91 const CompletionSuggestionKind('OPTIONAL_ARGUMENT');
92 static const CompletionSuggestionKind NAMED_ARGUMENT =
93 const CompletionSuggestionKind('NAMED_ARGUMENT');
94 static const CompletionSuggestionKind TOP_LEVEL_VARIABLE =
95 const CompletionSuggestionKind('TOP_LEVEL_VARIABLE');
96
97 final String name;
98
99 const CompletionSuggestionKind(this.name);
100
101 @override
102 String toString() => name;
103
104 static CompletionSuggestionKind valueOf(String name) {
105 if (CLASS.name == name) return CLASS;
106 if (CLASS_ALIAS.name == name) return CLASS_ALIAS;
107 if (CONSTRUCTOR.name == name) return CONSTRUCTOR;
108 if (FIELD.name == name) return FIELD;
109 if (FUNCTION.name == name) return FUNCTION;
110 if (FUNCTION_ALIAS.name == name) return FUNCTION_ALIAS;
111 if (GETTER.name == name) return GETTER;
112 if (IMPORT.name == name) return IMPORT;
113 if (LIBRARY_PREFIX.name == name) return LIBRARY_PREFIX;
114 if (METHOD.name == name) return METHOD;
115 if (METHOD_NAME.name == name) return METHOD_NAME;
116 if (PARAMETER.name == name) return PARAMETER;
117 if (SETTER.name == name) return SETTER;
118 if (VARIABLE.name == name) return VARIABLE;
119 if (TYPE_PARAMETER.name == name) return TYPE_PARAMETER;
120 if (ARGUMENT_LIST.name == name) return ARGUMENT_LIST;
121 if (OPTIONAL_ARGUMENT.name == name) return OPTIONAL_ARGUMENT;
122 if (NAMED_ARGUMENT.name == name) return NAMED_ARGUMENT;
123 if (TOP_LEVEL_VARIABLE.name == name) return TOP_LEVEL_VARIABLE;
124 throw new ArgumentError('Unknown CompletionSuggestionKind: $name');
125 }
126
127 static CompletionSuggestionKind fromElementKind(ElementKind kind) {
128 // ElementKind.ANGULAR_FORMATTER,
129 // ElementKind.ANGULAR_COMPONENT,
130 // ElementKind.ANGULAR_CONTROLLER,
131 // ElementKind.ANGULAR_DIRECTIVE,
132 // ElementKind.ANGULAR_PROPERTY,
133 // ElementKind.ANGULAR_SCOPE_PROPERTY,
134 // ElementKind.ANGULAR_SELECTOR,
135 // ElementKind.ANGULAR_VIEW,
136 if (kind == ElementKind.CLASS) return CLASS;
137 // ElementKind.COMPILATION_UNIT,
138 if (kind == ElementKind.CONSTRUCTOR) return CONSTRUCTOR;
139 // ElementKind.DYNAMIC,
140 // ElementKind.EMBEDDED_HTML_SCRIPT,
141 // ElementKind.ERROR,
142 // ElementKind.EXPORT,
143 // ElementKind.EXTERNAL_HTML_SCRIPT,
144 if (kind == ElementKind.FIELD) return FIELD;
145 if (kind == ElementKind.FUNCTION) return FUNCTION;
146 if (kind == ElementKind.GETTER) return GETTER;
147 // ElementKind.HTML,
148 if (kind == ElementKind.IMPORT) return IMPORT;
149 // ElementKind.LABEL,
150 // ElementKind.LIBRARY,
151 // ElementKind.LOCAL_VARIABLE,
152 if (kind == ElementKind.METHOD) return METHOD;
153 // ElementKind.METHOD,
154 // ElementKind.NAME,
155 if (kind == ElementKind.PARAMETER) return PARAMETER;
156 // ElementKind.POLYMER_ATTRIBUTE,
157 // ElementKind.POLYMER_TAG_DART,
158 // ElementKind.POLYMER_TAG_HTML,
159 // ElementKind.PREFIX,
160 if (kind == ElementKind.SETTER) return SETTER;
161 if (kind == ElementKind.TOP_LEVEL_VARIABLE) return TOP_LEVEL_VARIABLE;
162 // ElementKind.FUNCTION_TYPE_ALIAS,
163 // ElementKind.TYPE_PARAMETER,
164 // ElementKind.UNIVERSE
165 throw new ArgumentError('Unknown CompletionSuggestionKind for: $kind');
166 }
167 }
168
169 /**
170 * An enumeration of the relevance of a completion suggestion.
171 */
172 class CompletionRelevance {
173 static const CompletionRelevance LOW = const CompletionRelevance('LOW');
174 static const CompletionRelevance DEFAULT =
175 const CompletionRelevance('DEFAULT');
176 static const CompletionRelevance HIGH = const CompletionRelevance('HIGH');
177
178 final String name;
179
180 const CompletionRelevance(this.name);
181
182 static CompletionRelevance value(String name) {
183 if (LOW.name == name) return LOW;
184 if (DEFAULT.name == name) return DEFAULT;
185 if (HIGH.name == name) return HIGH;
186 throw new ArgumentError('Unknown CompletionRelevance: $name');
187 }
188 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698