Chromium Code Reviews| Index: pkg/analysis_services/lib/src/completion/keyword_computer.dart |
| diff --git a/pkg/analysis_services/lib/src/completion/keyword_computer.dart b/pkg/analysis_services/lib/src/completion/keyword_computer.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a917b4082a426bafc5cc5955a0863b878704e87e |
| --- /dev/null |
| +++ b/pkg/analysis_services/lib/src/completion/keyword_computer.dart |
| @@ -0,0 +1,76 @@ |
| +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +library services.completion.computer.dart.keyword; |
| + |
| +import 'dart:async'; |
| + |
| +import 'package:analysis_services/completion/completion_computer.dart'; |
| +import 'package:analysis_services/completion/completion_suggestion.dart'; |
| +import 'package:analyzer/src/generated/ast.dart'; |
| +import 'package:analyzer/src/generated/scanner.dart'; |
| + |
| +/** |
| + * A computer for calculating `completion.getSuggestions` request results |
| + * for the local library in which the completion is requested. |
| + */ |
| +class KeywordComputer extends CompletionComputer { |
| + |
| + @override |
| + bool computeFast(CompilationUnit unit, AstNode node, |
| + List<CompletionSuggestion> suggestions) { |
| + node.accept(new _KeywordVisitor(suggestions)); |
| + return true; |
| + } |
| + |
| + @override |
| + Future<bool> computeFull(CompilationUnit unit, AstNode node, |
| + List<CompletionSuggestion> suggestions) { |
| + return new Future.value(false); |
| + } |
| +} |
| + |
| +/** |
| + * A vistor for generating keyword suggestions. |
| + */ |
| +class _KeywordVisitor extends GeneralizingAstVisitor { |
|
Brian Wilkerson
2014/08/12 15:33:37
It seems unlikely that we'd ever want to add sugge
danrubel
2014/08/15 03:23:26
I'm thinking that there may be some more general s
|
| + final List<CompletionSuggestion> suggestions; |
| + |
| + _KeywordVisitor(this.suggestions); |
| + |
| + visitCompilationUnit(CompilationUnit node) { |
|
Brian Wilkerson
2014/08/12 15:33:37
Missing @override annotations.
danrubel
2014/08/15 03:23:26
I wish that the tool would insert these automatica
|
| + _addSuggestions( |
|
Brian Wilkerson
2014/08/13 16:20:15
This should check to see whether we are in the "di
danrubel
2014/08/15 03:23:26
Good points. I'll add tests for these. This curren
|
| + [ |
| + Keyword.ABSTRACT, |
| + Keyword.CLASS, |
| + Keyword.CONST, |
| + Keyword.EXPORT, |
| + Keyword.FINAL, |
| + Keyword.IMPORT, |
| + Keyword.LIBRARY, |
| + Keyword.PART, |
| + Keyword.VAR]); |
|
Brian Wilkerson
2014/08/12 15:33:37
Missing 'typedef'.
danrubel
2014/08/15 03:23:26
Done.
|
| + } |
| + |
| + visitClassDeclaration(ClassDeclaration node) { |
| + _addSuggestions([Keyword.EXTENDS, Keyword.IMPLEMENTS, Keyword.WITH]); |
|
Brian Wilkerson
2014/08/12 15:33:38
This should check that we're not within the body o
danrubel
2014/08/15 03:23:26
Will definitely add these as a follow on CL. As st
|
| + } |
| + |
| + void _addSuggestions(List<Keyword> keywords) { |
| + keywords.forEach((Keyword keyword) { |
| + String completion = keyword.syntax; |
| + suggestions.add( |
| + new CompletionSuggestion( |
| + CompletionSuggestionKind.KEYWORD, |
| + CompletionRelevance.DEFAULT, |
| + completion, |
| + completion.length, |
| + 0, |
| + false, |
| + false)); |
| + }); |
| + } |
| + |
| + visitNode(AstNode node) {} |
| +} |