| OLD | NEW |
| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 Token token = node.declarations[0].firstTokenAfterCommentAndMetadata; | 109 Token token = node.declarations[0].firstTokenAfterCommentAndMetadata; |
| 110 if (token.offset <= request.offset && request.offset <= token.end) { | 110 if (token.offset <= request.offset && request.offset <= token.end) { |
| 111 startOfDeclarations = token.end; | 111 startOfDeclarations = token.end; |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 | 114 |
| 115 // Simplistic check for library as first directive | 115 // Simplistic check for library as first directive |
| 116 if (firstDirective is! LibraryDirective) { | 116 if (firstDirective is! LibraryDirective) { |
| 117 if (firstDirective != null) { | 117 if (firstDirective != null) { |
| 118 if (request.offset <= firstDirective.offset) { | 118 if (request.offset <= firstDirective.offset) { |
| 119 _addSuggestions([Keyword.LIBRARY], COMPLETION_RELEVANCE_HIGH); | 119 _addSuggestions([Keyword.LIBRARY], DART_RELEVANCE_HIGH); |
| 120 } | 120 } |
| 121 } else { | 121 } else { |
| 122 if (request.offset <= startOfDeclarations) { | 122 if (request.offset <= startOfDeclarations) { |
| 123 _addSuggestions([Keyword.LIBRARY], COMPLETION_RELEVANCE_HIGH); | 123 _addSuggestions([Keyword.LIBRARY], DART_RELEVANCE_HIGH); |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 if (request.offset <= startOfDeclarations) { | 127 if (request.offset <= startOfDeclarations) { |
| 128 _addSuggestions( | 128 _addSuggestions( |
| 129 [Keyword.EXPORT, Keyword.IMPORT, Keyword.PART], | 129 [Keyword.EXPORT, Keyword.IMPORT, Keyword.PART], |
| 130 COMPLETION_RELEVANCE_HIGH); | 130 DART_RELEVANCE_HIGH); |
| 131 } | 131 } |
| 132 if (request.offset >= endOfDirectives) { | 132 if (request.offset >= endOfDirectives) { |
| 133 _addSuggestions( | 133 _addSuggestions( |
| 134 [ | 134 [ |
| 135 Keyword.ABSTRACT, | 135 Keyword.ABSTRACT, |
| 136 Keyword.CLASS, | 136 Keyword.CLASS, |
| 137 Keyword.CONST, | 137 Keyword.CONST, |
| 138 Keyword.FINAL, | 138 Keyword.FINAL, |
| 139 Keyword.TYPEDEF, | 139 Keyword.TYPEDEF, |
| 140 Keyword.VAR], | 140 Keyword.VAR], |
| 141 COMPLETION_RELEVANCE_HIGH); | 141 DART_RELEVANCE_HIGH); |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 | 144 |
| 145 @override | 145 @override |
| 146 visitNode(AstNode node) { | 146 visitNode(AstNode node) { |
| 147 if (_isOffsetAfterNode(node)) { | 147 if (_isOffsetAfterNode(node)) { |
| 148 node.parent.accept(this); | 148 node.parent.accept(this); |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 } | 183 } |
| 184 | 184 |
| 185 void visitVariableDeclarationList(VariableDeclarationList node) { | 185 void visitVariableDeclarationList(VariableDeclarationList node) { |
| 186 node.parent.accept(this); | 186 node.parent.accept(this); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void _addClassDeclarationKeywords(ClassDeclaration node) { | 189 void _addClassDeclarationKeywords(ClassDeclaration node) { |
| 190 // Very simplistic suggestion because analyzer will warn if | 190 // Very simplistic suggestion because analyzer will warn if |
| 191 // the extends / with / implements keywords are out of order | 191 // the extends / with / implements keywords are out of order |
| 192 if (node.extendsClause == null) { | 192 if (node.extendsClause == null) { |
| 193 _addSuggestion(Keyword.EXTENDS, COMPLETION_RELEVANCE_HIGH); | 193 _addSuggestion(Keyword.EXTENDS, DART_RELEVANCE_HIGH); |
| 194 } else if (node.withClause == null) { | 194 } else if (node.withClause == null) { |
| 195 _addSuggestion(Keyword.WITH, COMPLETION_RELEVANCE_HIGH); | 195 _addSuggestion(Keyword.WITH, DART_RELEVANCE_HIGH); |
| 196 } | 196 } |
| 197 if (node.implementsClause == null) { | 197 if (node.implementsClause == null) { |
| 198 _addSuggestion(Keyword.IMPLEMENTS, COMPLETION_RELEVANCE_HIGH); | 198 _addSuggestion(Keyword.IMPLEMENTS, DART_RELEVANCE_HIGH); |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 | 201 |
| 202 void _addSuggestion(Keyword keyword, [int relevance = | 202 void _addSuggestion(Keyword keyword, [int relevance = |
| 203 COMPLETION_RELEVANCE_DEFAULT]) { | 203 DART_RELEVANCE_DEFAULT]) { |
| 204 String completion = keyword.syntax; | 204 String completion = keyword.syntax; |
| 205 request.suggestions.add( | 205 request.suggestions.add( |
| 206 new CompletionSuggestion( | 206 new CompletionSuggestion( |
| 207 CompletionSuggestionKind.KEYWORD, | 207 CompletionSuggestionKind.KEYWORD, |
| 208 relevance, | 208 relevance, |
| 209 completion, | 209 completion, |
| 210 completion.length, | 210 completion.length, |
| 211 0, | 211 0, |
| 212 false, | 212 false, |
| 213 false)); | 213 false)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 225 Token token = node.endToken; | 225 Token token = node.endToken; |
| 226 if (token != null && !token.isSynthetic) { | 226 if (token != null && !token.isSynthetic) { |
| 227 if (token.lexeme == ';' || token.lexeme == '}') { | 227 if (token.lexeme == ';' || token.lexeme == '}') { |
| 228 return true; | 228 return true; |
| 229 } | 229 } |
| 230 } | 230 } |
| 231 } | 231 } |
| 232 return false; | 232 return false; |
| 233 } | 233 } |
| 234 } | 234 } |
| OLD | NEW |