Chromium Code Reviews| 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_computer.dart'; | |
| 10 import 'package:analysis_services/completion/completion_suggestion.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 CompletionComputer { | |
| 19 | |
| 20 @override | |
| 21 bool computeFast(CompilationUnit unit, AstNode node, | |
| 22 List<CompletionSuggestion> suggestions) { | |
| 23 node.accept(new _KeywordVisitor(suggestions)); | |
| 24 return true; | |
| 25 } | |
| 26 | |
| 27 @override | |
| 28 Future<bool> computeFull(CompilationUnit unit, AstNode node, | |
| 29 List<CompletionSuggestion> suggestions) { | |
| 30 return new Future.value(false); | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 /** | |
| 35 * A vistor for generating keyword suggestions. | |
| 36 */ | |
| 37 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
| |
| 38 final List<CompletionSuggestion> suggestions; | |
| 39 | |
| 40 _KeywordVisitor(this.suggestions); | |
| 41 | |
| 42 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
| |
| 43 _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
| |
| 44 [ | |
| 45 Keyword.ABSTRACT, | |
| 46 Keyword.CLASS, | |
| 47 Keyword.CONST, | |
| 48 Keyword.EXPORT, | |
| 49 Keyword.FINAL, | |
| 50 Keyword.IMPORT, | |
| 51 Keyword.LIBRARY, | |
| 52 Keyword.PART, | |
| 53 Keyword.VAR]); | |
|
Brian Wilkerson
2014/08/12 15:33:37
Missing 'typedef'.
danrubel
2014/08/15 03:23:26
Done.
| |
| 54 } | |
| 55 | |
| 56 visitClassDeclaration(ClassDeclaration node) { | |
| 57 _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
| |
| 58 } | |
| 59 | |
| 60 void _addSuggestions(List<Keyword> keywords) { | |
| 61 keywords.forEach((Keyword keyword) { | |
| 62 String completion = keyword.syntax; | |
| 63 suggestions.add( | |
| 64 new CompletionSuggestion( | |
| 65 CompletionSuggestionKind.KEYWORD, | |
| 66 CompletionRelevance.DEFAULT, | |
| 67 completion, | |
| 68 completion.length, | |
| 69 0, | |
| 70 false, | |
| 71 false)); | |
| 72 }); | |
| 73 } | |
| 74 | |
| 75 visitNode(AstNode node) {} | |
| 76 } | |
| OLD | NEW |