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

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

Issue 845553005: Change code completion relevance from CompletionRelevance.LOW/DEFAULT/HIGH to int (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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.keyword; 5 library services.completion.computer.dart.keyword;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol.dart'; 9 import 'package:analysis_server/src/protocol.dart';
10 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart'; 10 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart';
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 Keyword.OPERATOR, 80 Keyword.OPERATOR,
81 Keyword.SET, 81 Keyword.SET,
82 Keyword.STATIC, 82 Keyword.STATIC,
83 Keyword.VAR, 83 Keyword.VAR,
84 Keyword.VOID]); 84 Keyword.VOID]);
85 return; 85 return;
86 } 86 }
87 // Very simplistic suggestion because analyzer will warn if 87 // Very simplistic suggestion because analyzer will warn if
88 // the extends / with / implements keywords are out of order 88 // the extends / with / implements keywords are out of order
89 if (node.extendsClause == null) { 89 if (node.extendsClause == null) {
90 _addSuggestion(Keyword.EXTENDS, CompletionRelevance.HIGH); 90 _addSuggestion(Keyword.EXTENDS, COMPLETION_RELEVANCE_HIGH);
91 } else if (node.withClause == null) { 91 } else if (node.withClause == null) {
92 _addSuggestion(Keyword.WITH, CompletionRelevance.HIGH); 92 _addSuggestion(Keyword.WITH, COMPLETION_RELEVANCE_HIGH);
93 } 93 }
94 if (node.implementsClause == null) { 94 if (node.implementsClause == null) {
95 _addSuggestion(Keyword.IMPLEMENTS, CompletionRelevance.HIGH); 95 _addSuggestion(Keyword.IMPLEMENTS, COMPLETION_RELEVANCE_HIGH);
96 } 96 }
97 } 97 }
98 98
99 @override 99 @override
100 visitCompilationUnit(CompilationUnit node) { 100 visitCompilationUnit(CompilationUnit node) {
101 Directive firstDirective; 101 Directive firstDirective;
102 int endOfDirectives = 0; 102 int endOfDirectives = 0;
103 if (node.directives.length > 0) { 103 if (node.directives.length > 0) {
104 firstDirective = node.directives[0]; 104 firstDirective = node.directives[0];
105 endOfDirectives = node.directives.last.end - 1; 105 endOfDirectives = node.directives.last.end - 1;
106 } 106 }
107 int startOfDeclarations = node.end; 107 int startOfDeclarations = node.end;
108 if (node.declarations.length > 0) { 108 if (node.declarations.length > 0) {
109 startOfDeclarations = node.declarations[0].offset; 109 startOfDeclarations = node.declarations[0].offset;
110 // If the first token is a simple identifier 110 // If the first token is a simple identifier
111 // and cursor position in within that first token 111 // and cursor position in within that first token
112 // then consider cursor to be before the first declaration 112 // then consider cursor to be before the first declaration
113 Token token = node.declarations[0].firstTokenAfterCommentAndMetadata; 113 Token token = node.declarations[0].firstTokenAfterCommentAndMetadata;
114 if (token.offset <= request.offset && request.offset <= token.end) { 114 if (token.offset <= request.offset && request.offset <= token.end) {
115 startOfDeclarations = token.end; 115 startOfDeclarations = token.end;
116 } 116 }
117 } 117 }
118 118
119 // Simplistic check for library as first directive 119 // Simplistic check for library as first directive
120 if (firstDirective is! LibraryDirective) { 120 if (firstDirective is! LibraryDirective) {
121 if (firstDirective != null) { 121 if (firstDirective != null) {
122 if (request.offset <= firstDirective.offset) { 122 if (request.offset <= firstDirective.offset) {
123 _addSuggestions([Keyword.LIBRARY], CompletionRelevance.HIGH); 123 _addSuggestions([Keyword.LIBRARY], COMPLETION_RELEVANCE_HIGH);
124 } 124 }
125 } else { 125 } else {
126 if (request.offset <= startOfDeclarations) { 126 if (request.offset <= startOfDeclarations) {
127 _addSuggestions([Keyword.LIBRARY], CompletionRelevance.HIGH); 127 _addSuggestions([Keyword.LIBRARY], COMPLETION_RELEVANCE_HIGH);
128 } 128 }
129 } 129 }
130 } 130 }
131 if (request.offset <= startOfDeclarations) { 131 if (request.offset <= startOfDeclarations) {
132 _addSuggestions( 132 _addSuggestions(
133 [Keyword.EXPORT, Keyword.IMPORT, Keyword.PART], 133 [Keyword.EXPORT, Keyword.IMPORT, Keyword.PART],
134 CompletionRelevance.HIGH); 134 COMPLETION_RELEVANCE_HIGH);
135 } 135 }
136 if (request.offset >= endOfDirectives) { 136 if (request.offset >= endOfDirectives) {
137 _addSuggestions( 137 _addSuggestions(
138 [ 138 [
139 Keyword.ABSTRACT, 139 Keyword.ABSTRACT,
140 Keyword.CLASS, 140 Keyword.CLASS,
141 Keyword.CONST, 141 Keyword.CONST,
142 Keyword.FINAL, 142 Keyword.FINAL,
143 Keyword.TYPEDEF, 143 Keyword.TYPEDEF,
144 Keyword.VAR], 144 Keyword.VAR],
145 CompletionRelevance.HIGH); 145 COMPLETION_RELEVANCE_HIGH);
146 } 146 }
147 } 147 }
148 148
149 @override 149 @override
150 visitNode(AstNode node) { 150 visitNode(AstNode node) {
151 if (_isOffsetAfterNode(node)) { 151 if (_isOffsetAfterNode(node)) {
152 node.parent.accept(this); 152 node.parent.accept(this);
153 } 153 }
154 } 154 }
155 155
156 visitSimpleIdentifier(SimpleIdentifier node) { 156 visitSimpleIdentifier(SimpleIdentifier node) {
157 AstNode parent = node.getAncestor((n) => n is TopLevelVariableDeclaration); 157 AstNode parent = node.getAncestor((n) => n is TopLevelVariableDeclaration);
158 if (parent is TopLevelVariableDeclaration) { 158 if (parent is TopLevelVariableDeclaration) {
159 if (parent.variables != null && 159 if (parent.variables != null &&
160 parent.variables.type != null && 160 parent.variables.type != null &&
161 parent.variables.type.name == node) { 161 parent.variables.type.name == node) {
162 AstNode unit = node.getAncestor((n) => n is CompilationUnit); 162 AstNode unit = node.getAncestor((n) => n is CompilationUnit);
163 if (unit is CompilationUnit) { 163 if (unit is CompilationUnit) {
164 visitCompilationUnit(unit); 164 visitCompilationUnit(unit);
165 } 165 }
166 } 166 }
167 } 167 }
168 } 168 }
169 169
170 void _addSuggestion(Keyword keyword, [CompletionRelevance relevance = 170 void _addSuggestion(Keyword keyword, [int relevance =
171 CompletionRelevance.DEFAULT]) { 171 COMPLETION_RELEVANCE_DEFAULT]) {
172 String completion = keyword.syntax; 172 String completion = keyword.syntax;
173 request.suggestions.add( 173 request.suggestions.add(
174 new CompletionSuggestion( 174 new CompletionSuggestion(
175 CompletionSuggestionKind.KEYWORD, 175 CompletionSuggestionKind.KEYWORD,
176 relevance, 176 relevance,
177 completion, 177 completion,
178 completion.length, 178 completion.length,
179 0, 179 0,
180 false, 180 false,
181 false)); 181 false));
182 } 182 }
183 183
184 void _addSuggestions(List<Keyword> keywords, [CompletionRelevance relevance = 184 void _addSuggestions(List<Keyword> keywords, [int relevance =
185 CompletionRelevance.DEFAULT]) { 185 COMPLETION_RELEVANCE_DEFAULT]) {
186 keywords.forEach((Keyword keyword) { 186 keywords.forEach((Keyword keyword) {
187 _addSuggestion(keyword, relevance); 187 _addSuggestion(keyword, relevance);
188 }); 188 });
189 } 189 }
190 190
191 bool _isOffsetAfterNode(AstNode node) { 191 bool _isOffsetAfterNode(AstNode node) {
192 if (request.offset == node.end) { 192 if (request.offset == node.end) {
193 Token token = node.endToken; 193 Token token = node.endToken;
194 if (token != null && !token.isSynthetic) { 194 if (token != null && !token.isSynthetic) {
195 if (token.lexeme == ';' || token.lexeme == '}') { 195 if (token.lexeme == ';' || token.lexeme == '}') {
196 return true; 196 return true;
197 } 197 }
198 } 198 }
199 } 199 }
200 return false; 200 return false;
201 } 201 }
202 } 202 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698