| 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.contributor.dart.keyword; | 5 library services.completion.contributor.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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 } | 99 } |
| 100 if (previousMember is ClassDeclaration) { | 100 if (previousMember is ClassDeclaration) { |
| 101 if (previousMember.leftBracket == null || | 101 if (previousMember.leftBracket == null || |
| 102 previousMember.leftBracket.isSynthetic) { | 102 previousMember.leftBracket.isSynthetic) { |
| 103 // If the prior member is an unfinished class declaration | 103 // If the prior member is an unfinished class declaration |
| 104 // then the user is probably finishing that | 104 // then the user is probably finishing that |
| 105 _addClassDeclarationKeywords(previousMember); | 105 _addClassDeclarationKeywords(previousMember); |
| 106 return; | 106 return; |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 if (previousMember is ImportDirective) { |
| 110 if (previousMember.semicolon == null || previousMember.semicolon.isSynthet
ic) { |
| 111 // If the prior member is an unfinished import directive |
| 112 // then the user is probably finishing that |
| 113 _addImportDirectiveKeywords(previousMember); |
| 114 return; |
| 115 } |
| 116 } |
| 109 if (previousMember == null || previousMember is Directive) { | 117 if (previousMember == null || previousMember is Directive) { |
| 110 if (previousMember == null && | 118 if (previousMember == null && |
| 111 !node.directives.any((d) => d is LibraryDirective)) { | 119 !node.directives.any((d) => d is LibraryDirective)) { |
| 112 _addSuggestions([Keyword.LIBRARY], DART_RELEVANCE_HIGH); | 120 _addSuggestions([Keyword.LIBRARY], DART_RELEVANCE_HIGH); |
| 113 } | 121 } |
| 114 _addSuggestions( | 122 _addSuggestions( |
| 115 [Keyword.EXPORT, Keyword.IMPORT, Keyword.PART], DART_RELEVANCE_HIGH); | 123 [Keyword.EXPORT, Keyword.IMPORT, Keyword.PART], DART_RELEVANCE_HIGH); |
| 116 } | 124 } |
| 117 if (entity == null || entity is Declaration) { | 125 if (entity == null || entity is Declaration) { |
| 118 _addSuggestions([ | 126 _addSuggestions([ |
| 119 Keyword.ABSTRACT, | 127 Keyword.ABSTRACT, |
| 120 Keyword.CLASS, | 128 Keyword.CLASS, |
| 121 Keyword.CONST, | 129 Keyword.CONST, |
| 122 Keyword.DYNAMIC, | 130 Keyword.DYNAMIC, |
| 123 Keyword.FINAL, | 131 Keyword.FINAL, |
| 124 Keyword.TYPEDEF, | 132 Keyword.TYPEDEF, |
| 125 Keyword.VAR, | 133 Keyword.VAR, |
| 126 Keyword.VOID | 134 Keyword.VOID |
| 127 ], DART_RELEVANCE_HIGH); | 135 ], DART_RELEVANCE_HIGH); |
| 128 } | 136 } |
| 129 } | 137 } |
| 130 | 138 |
| 139 @override |
| 140 visitImportDirective(ImportDirective node) { |
| 141 if (entity == node.asKeyword) { |
| 142 if (node.deferredKeyword == null) { |
| 143 _addSuggestion(Keyword.DEFERRED, DART_RELEVANCE_HIGH); |
| 144 } |
| 145 } |
| 146 if (entity == node.semicolon) { |
| 147 _addImportDirectiveKeywords(node); |
| 148 } |
| 149 } |
| 150 |
| 151 void _addImportDirectiveKeywords(ImportDirective node) { |
| 152 if (node.asKeyword == null) { |
| 153 _addSuggestion(Keyword.AS, DART_RELEVANCE_HIGH); |
| 154 if (node.deferredKeyword == null) { |
| 155 _addSuggestion(Keyword.DEFERRED, DART_RELEVANCE_HIGH); |
| 156 } |
| 157 } |
| 158 } |
| 159 |
| 131 void _addClassDeclarationKeywords(ClassDeclaration node) { | 160 void _addClassDeclarationKeywords(ClassDeclaration node) { |
| 132 // Very simplistic suggestion because analyzer will warn if | 161 // Very simplistic suggestion because analyzer will warn if |
| 133 // the extends / with / implements keywords are out of order | 162 // the extends / with / implements keywords are out of order |
| 134 if (node.extendsClause == null) { | 163 if (node.extendsClause == null) { |
| 135 _addSuggestion(Keyword.EXTENDS, DART_RELEVANCE_HIGH); | 164 _addSuggestion(Keyword.EXTENDS, DART_RELEVANCE_HIGH); |
| 136 } else if (node.withClause == null) { | 165 } else if (node.withClause == null) { |
| 137 _addSuggestion(Keyword.WITH, DART_RELEVANCE_HIGH); | 166 _addSuggestion(Keyword.WITH, DART_RELEVANCE_HIGH); |
| 138 } | 167 } |
| 139 if (node.implementsClause == null) { | 168 if (node.implementsClause == null) { |
| 140 _addSuggestion(Keyword.IMPLEMENTS, DART_RELEVANCE_HIGH); | 169 _addSuggestion(Keyword.IMPLEMENTS, DART_RELEVANCE_HIGH); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 163 return false; | 192 return false; |
| 164 } | 193 } |
| 165 AstNode parent = body.parent; | 194 AstNode parent = body.parent; |
| 166 if (parent is ConstructorDeclaration || parent is MethodDeclaration) { | 195 if (parent is ConstructorDeclaration || parent is MethodDeclaration) { |
| 167 return true; | 196 return true; |
| 168 } | 197 } |
| 169 node = parent; | 198 node = parent; |
| 170 } | 199 } |
| 171 } | 200 } |
| 172 } | 201 } |
| OLD | NEW |