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

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

Powered by Google App Engine
This is Rietveld 408576698