OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library services.completion.computer.dart.keyword; | |
6 | |
7 import 'dart:async'; | |
8 | |
9 import 'package:analysis_services/completion/completion_suggestion.dart'; | |
10 import 'package:analysis_services/src/completion/dart_completion_manager.dart'; | |
11 import 'package:analyzer/src/generated/ast.dart'; | |
12 import 'package:analyzer/src/generated/scanner.dart'; | |
13 | |
14 /** | |
15 * A computer for calculating `completion.getSuggestions` request results | |
16 * for the local library in which the completion is requested. | |
17 */ | |
18 class KeywordComputer extends DartCompletionComputer { | |
19 | |
20 @override | |
21 bool computeFast(DartCompletionRequest request) { | |
22 request.node.accept(new _KeywordVisitor(request)); | |
23 return true; | |
24 } | |
25 | |
26 @override | |
27 Future<bool> computeFull(DartCompletionRequest request) { | |
28 return new Future.value(false); | |
29 } | |
30 } | |
31 | |
32 /** | |
33 * A vistor for generating keyword suggestions. | |
34 */ | |
35 class _KeywordVisitor extends GeneralizingAstVisitor { | |
36 final DartCompletionRequest request; | |
37 | |
38 _KeywordVisitor(this.request); | |
39 | |
40 @override | |
41 visitClassDeclaration(ClassDeclaration node) { | |
42 _addSuggestions([Keyword.EXTENDS, Keyword.IMPLEMENTS, Keyword.WITH]); | |
43 } | |
44 | |
45 @override | |
46 visitCompilationUnit(CompilationUnit node) { | |
47 _addSuggestions( | |
48 [ | |
49 Keyword.ABSTRACT, | |
50 Keyword.CLASS, | |
51 Keyword.CONST, | |
52 Keyword.EXPORT, | |
53 Keyword.FINAL, | |
54 Keyword.IMPORT, | |
55 Keyword.LIBRARY, | |
56 Keyword.PART, | |
57 Keyword.TYPEDEF, | |
58 Keyword.VAR]); | |
59 } | |
60 | |
61 @override | |
62 visitNode(AstNode node) { | |
63 // ignored | |
64 } | |
65 | |
66 void _addSuggestions(List<Keyword> keywords) { | |
67 keywords.forEach((Keyword keyword) { | |
68 String completion = keyword.syntax; | |
69 request.suggestions.add( | |
70 new CompletionSuggestion( | |
71 CompletionSuggestionKind.KEYWORD, | |
72 CompletionRelevance.DEFAULT, | |
73 completion, | |
74 completion.length, | |
75 0, | |
76 false, | |
77 false)); | |
78 }); | |
79 } | |
80 } | |
OLD | NEW |