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

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

Issue 483803002: improve keyword suggestions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 6 years, 4 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
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/completion/keyword_computer_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 37942d420578589804b61f8e2035e247d2c918e3..5e681656aebcfde4ee41647a6bd9ec38e3f3bcba 100644
--- a/pkg/analysis_server/lib/src/services/completion/keyword_computer.dart
+++ b/pkg/analysis_server/lib/src/services/completion/keyword_computer.dart
@@ -39,42 +39,86 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
@override
visitClassDeclaration(ClassDeclaration node) {
- _addSuggestions([Keyword.EXTENDS, Keyword.IMPLEMENTS, Keyword.WITH]);
+ // Very simplistic suggestion because analyzer will warn if
+ // the extends / with / implements keywords are out of order
+ if (node.extendsClause == null) {
+ _addSuggestion(Keyword.EXTENDS);
+ } else if (node.withClause == null) {
+ _addSuggestion(Keyword.WITH);
+ }
+ if (node.implementsClause == null) {
+ _addSuggestion(Keyword.IMPLEMENTS);
+ }
}
@override
visitCompilationUnit(CompilationUnit node) {
- _addSuggestions(
- [
- Keyword.ABSTRACT,
- Keyword.CLASS,
- Keyword.CONST,
- Keyword.EXPORT,
- Keyword.FINAL,
- Keyword.IMPORT,
- Keyword.LIBRARY,
- Keyword.PART,
- Keyword.TYPEDEF,
- Keyword.VAR]);
+ Directive firstDirective;
+ int endOfDirectives = 0;
+ if (node.directives.length > 0) {
+ firstDirective = node.directives[0];
+ endOfDirectives = node.directives.last.end - 1;
+ }
+ int startOfDeclarations = node.end;
+ if (node.declarations.length > 0) {
+ startOfDeclarations = node.declarations[0].offset;
+ }
+
+ // Simplistic check for library as first directive
+ if (firstDirective is! LibraryDirective) {
+ if (firstDirective != null) {
+ if (request.offset <= firstDirective.offset) {
+ _addSuggestions([Keyword.LIBRARY]);
+ }
+ } else {
+ if (request.offset <= startOfDeclarations) {
+ _addSuggestions([Keyword.LIBRARY]);
+ }
+ }
+ }
+ if (request.offset <= startOfDeclarations) {
+ _addSuggestions([Keyword.EXPORT, Keyword.IMPORT, Keyword.PART]);
+ }
+ if (request.offset >= endOfDirectives) {
+ _addSuggestions(
+ [
+ Keyword.ABSTRACT,
+ Keyword.CLASS,
+ Keyword.CONST,
+ Keyword.FINAL,
+ Keyword.TYPEDEF,
+ Keyword.VAR]);
+ }
}
@override
visitNode(AstNode node) {
- // ignored
+ if (request.offset == node.end) {
+ Token token = node.endToken;
+ if (token != null && !token.isSynthetic) {
+ if (token.lexeme == ';' || token.lexeme == '}') {
+ node.parent.accept(this);
+ }
+ }
+ }
+ }
+
+ void _addSuggestion(Keyword keyword) {
+ String completion = keyword.syntax;
+ request.suggestions.add(
+ new CompletionSuggestion(
+ CompletionSuggestionKind.KEYWORD,
+ CompletionRelevance.DEFAULT,
+ completion,
+ completion.length,
+ 0,
+ false,
+ false));
}
void _addSuggestions(List<Keyword> keywords) {
keywords.forEach((Keyword keyword) {
- String completion = keyword.syntax;
- request.suggestions.add(
- new CompletionSuggestion(
- CompletionSuggestionKind.KEYWORD,
- CompletionRelevance.DEFAULT,
- completion,
- completion.length,
- 0,
- false,
- false));
+ _addSuggestion(keyword);
});
}
}
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/completion/keyword_computer_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698