| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library services.completion.computer.dart.keyword; | 5 library services.completion.computer.dart.keyword; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol.dart'; | 9 import 'package:analysis_server/src/protocol.dart'; |
| 10 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; | 10 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 visitCompilationUnit(CompilationUnit node) { | 55 visitCompilationUnit(CompilationUnit node) { |
| 56 Directive firstDirective; | 56 Directive firstDirective; |
| 57 int endOfDirectives = 0; | 57 int endOfDirectives = 0; |
| 58 if (node.directives.length > 0) { | 58 if (node.directives.length > 0) { |
| 59 firstDirective = node.directives[0]; | 59 firstDirective = node.directives[0]; |
| 60 endOfDirectives = node.directives.last.end - 1; | 60 endOfDirectives = node.directives.last.end - 1; |
| 61 } | 61 } |
| 62 int startOfDeclarations = node.end; | 62 int startOfDeclarations = node.end; |
| 63 if (node.declarations.length > 0) { | 63 if (node.declarations.length > 0) { |
| 64 startOfDeclarations = node.declarations[0].offset; | 64 startOfDeclarations = node.declarations[0].offset; |
| 65 // If the first token is a simple identifier |
| 66 // and cursor position in within that first token |
| 67 // then consider cursor to be before the first declaration |
| 68 Token token = node.declarations[0].firstTokenAfterCommentAndMetadata; |
| 69 if (token.offset <= request.offset && request.offset <= token.end) { |
| 70 startOfDeclarations = token.end; |
| 71 } |
| 65 } | 72 } |
| 66 | 73 |
| 67 // Simplistic check for library as first directive | 74 // Simplistic check for library as first directive |
| 68 if (firstDirective is! LibraryDirective) { | 75 if (firstDirective is! LibraryDirective) { |
| 69 if (firstDirective != null) { | 76 if (firstDirective != null) { |
| 70 if (request.offset <= firstDirective.offset) { | 77 if (request.offset <= firstDirective.offset) { |
| 71 _addSuggestions([Keyword.LIBRARY]); | 78 _addSuggestions([Keyword.LIBRARY]); |
| 72 } | 79 } |
| 73 } else { | 80 } else { |
| 74 if (request.offset <= startOfDeclarations) { | 81 if (request.offset <= startOfDeclarations) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 96 if (request.offset == node.end) { | 103 if (request.offset == node.end) { |
| 97 Token token = node.endToken; | 104 Token token = node.endToken; |
| 98 if (token != null && !token.isSynthetic) { | 105 if (token != null && !token.isSynthetic) { |
| 99 if (token.lexeme == ';' || token.lexeme == '}') { | 106 if (token.lexeme == ';' || token.lexeme == '}') { |
| 100 node.parent.accept(this); | 107 node.parent.accept(this); |
| 101 } | 108 } |
| 102 } | 109 } |
| 103 } | 110 } |
| 104 } | 111 } |
| 105 | 112 |
| 113 visitSimpleIdentifier(SimpleIdentifier node) { |
| 114 AstNode parent = |
| 115 node.getAncestor((n) => n is TopLevelVariableDeclaration); |
| 116 if (parent is TopLevelVariableDeclaration) { |
| 117 if (parent.variables != null && parent.variables.type != null |
| 118 && parent.variables.type.name == node) { |
| 119 AstNode unit = node.getAncestor((n) => n is CompilationUnit); |
| 120 if (unit is CompilationUnit) { |
| 121 visitCompilationUnit(unit); |
| 122 } |
| 123 } |
| 124 } |
| 125 } |
| 126 |
| 106 void _addSuggestion(Keyword keyword) { | 127 void _addSuggestion(Keyword keyword) { |
| 107 String completion = keyword.syntax; | 128 String completion = keyword.syntax; |
| 108 request.suggestions.add( | 129 request.suggestions.add( |
| 109 new CompletionSuggestion( | 130 new CompletionSuggestion( |
| 110 CompletionSuggestionKind.KEYWORD, | 131 CompletionSuggestionKind.KEYWORD, |
| 111 CompletionRelevance.DEFAULT, | 132 CompletionRelevance.DEFAULT, |
| 112 completion, | 133 completion, |
| 113 completion.length, | 134 completion.length, |
| 114 0, | 135 0, |
| 115 false, | 136 false, |
| 116 false)); | 137 false)); |
| 117 } | 138 } |
| 118 | 139 |
| 119 void _addSuggestions(List<Keyword> keywords) { | 140 void _addSuggestions(List<Keyword> keywords) { |
| 120 keywords.forEach((Keyword keyword) { | 141 keywords.forEach((Keyword keyword) { |
| 121 _addSuggestion(keyword); | 142 _addSuggestion(keyword); |
| 122 }); | 143 }); |
| 123 } | 144 } |
| 124 } | 145 } |
| OLD | NEW |