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

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

Issue 543393002: improve keyword suggestions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/src/services/completion/keyword_computer.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/keyword_computer.dart b/pkg/analysis_server/lib/src/services/completion/keyword_computer.dart
index 4137c7d99f4b1e6a980e1e3fdb29b7e2d1514349..4091f9f2828bef5b4fe5f042313f94d1c0663f31 100644
--- a/pkg/analysis_server/lib/src/services/completion/keyword_computer.dart
+++ b/pkg/analysis_server/lib/src/services/completion/keyword_computer.dart
@@ -38,7 +38,52 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
_KeywordVisitor(this.request);
@override
+ visitBlock(Block node) {
+ if (_isOffsetAfterNode(node)) {
+ node.parent.accept(this);
+ } else {
+ _addSuggestions(
+ [
+ Keyword.ASSERT,
+ Keyword.CASE,
+ Keyword.CONTINUE,
+ Keyword.DO,
+ Keyword.FACTORY,
+ Keyword.FINAL,
+ Keyword.FOR,
+ Keyword.IF,
+ Keyword.NEW,
+ Keyword.RETHROW,
+ Keyword.RETURN,
+ Keyword.SUPER,
+ Keyword.SWITCH,
+ Keyword.THIS,
+ Keyword.THROW,
+ Keyword.TRY,
+ Keyword.VAR,
+ Keyword.VOID,
+ Keyword.WHILE]);
+ }
+ }
+
+ @override
visitClassDeclaration(ClassDeclaration node) {
+ // Inside the class declaration { }
+ if (request.offset > node.leftBracket.offset) {
+ _addSuggestions(
+ [
+ Keyword.CONST,
+ Keyword.DYNAMIC,
+ Keyword.FACTORY,
+ Keyword.FINAL,
+ Keyword.GET,
+ Keyword.OPERATOR,
+ Keyword.SET,
+ Keyword.STATIC,
+ Keyword.VAR,
+ Keyword.VOID]);
+ return;
+ }
// Very simplistic suggestion because analyzer will warn if
// the extends / with / implements keywords are out of order
if (node.extendsClause == null) {
@@ -100,22 +145,17 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
@override
visitNode(AstNode node) {
- if (request.offset == node.end) {
- Token token = node.endToken;
- if (token != null && !token.isSynthetic) {
- if (token.lexeme == ';' || token.lexeme == '}') {
- node.parent.accept(this);
- }
- }
+ if (_isOffsetAfterNode(node)) {
+ node.parent.accept(this);
}
}
visitSimpleIdentifier(SimpleIdentifier node) {
- AstNode parent =
- node.getAncestor((n) => n is TopLevelVariableDeclaration);
+ AstNode parent = node.getAncestor((n) => n is TopLevelVariableDeclaration);
if (parent is TopLevelVariableDeclaration) {
- if (parent.variables != null && parent.variables.type != null
- && parent.variables.type.name == node) {
+ if (parent.variables != null &&
+ parent.variables.type != null &&
+ parent.variables.type.name == node) {
AstNode unit = node.getAncestor((n) => n is CompilationUnit);
if (unit is CompilationUnit) {
visitCompilationUnit(unit);
@@ -142,4 +182,16 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
_addSuggestion(keyword);
});
}
+
+ bool _isOffsetAfterNode(AstNode node) {
+ if (request.offset == node.end) {
+ Token token = node.endToken;
+ if (token != null && !token.isSynthetic) {
+ if (token.lexeme == ';' || token.lexeme == '}') {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
}

Powered by Google App Engine
This is Rietveld 408576698