| 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.contributor.dart.importuri; | 5 library services.completion.contributor.dart.importuri; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:core' hide Resource; | 8 import 'dart:core' hide Resource; |
| 9 | 9 |
| 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 30 matching lines...) Expand all Loading... |
| 41 final DartCompletionRequest request; | 41 final DartCompletionRequest request; |
| 42 | 42 |
| 43 _UriSuggestionBuilder(this.request); | 43 _UriSuggestionBuilder(this.request); |
| 44 | 44 |
| 45 bool computeFast(AstNode node) { | 45 bool computeFast(AstNode node) { |
| 46 node.accept(this); | 46 node.accept(this); |
| 47 return true; | 47 return true; |
| 48 } | 48 } |
| 49 | 49 |
| 50 @override | 50 @override |
| 51 visitExportDirective(exportDirective node) { |
| 52 visitNamespaceDirective(node); |
| 53 } |
| 54 |
| 55 @override |
| 51 visitImportDirective(ImportDirective node) { | 56 visitImportDirective(ImportDirective node) { |
| 57 visitNamespaceDirective(node); |
| 58 } |
| 59 |
| 60 visitNamespaceDirective(NamespaceDirective node) { |
| 52 StringLiteral uri = node.uri; | 61 StringLiteral uri = node.uri; |
| 53 if (uri is SimpleStringLiteral) { | 62 if (uri is SimpleStringLiteral) { |
| 54 int offset = request.offset; | 63 int offset = request.offset; |
| 55 if (uri.offset < offset && | 64 if (uri.offset < offset && |
| 56 (offset < uri.end || offset == uri.offset + 1)) { | 65 (offset < uri.end || offset == uri.offset + 1)) { |
| 57 // Handle degenerate case where import is only line in file | 66 // Handle degenerate case where import or export is only line in file |
| 58 // and there is no semicolon | 67 // and there is no semicolon |
| 59 visitSimpleStringLiteral(uri); | 68 visitSimpleStringLiteral(uri); |
| 60 } | 69 } |
| 61 } | 70 } |
| 62 } | 71 } |
| 63 | 72 |
| 64 @override | 73 @override |
| 65 visitSimpleStringLiteral(SimpleStringLiteral node) { | 74 visitSimpleStringLiteral(SimpleStringLiteral node) { |
| 66 AstNode parent = node.parent; | 75 AstNode parent = node.parent; |
| 67 if (parent is ImportDirective && parent.uri == node) { | 76 if (parent is NamespaceDirective && parent.uri == node) { |
| 68 String partial = node.literal.lexeme.substring( | 77 String partial = node.literal.lexeme.substring( |
| 69 node.contentsOffset - node.offset, request.offset - node.offset); | 78 node.contentsOffset - node.offset, request.offset - node.offset); |
| 70 request.replacementOffset = node.contentsOffset; | 79 request.replacementOffset = node.contentsOffset; |
| 71 request.replacementLength = node.contentsEnd - node.contentsOffset; | 80 request.replacementLength = node.contentsEnd - node.contentsOffset; |
| 72 _addDartSuggestions(); | 81 _addDartSuggestions(); |
| 73 _addPackageSuggestions(partial); | 82 _addPackageSuggestions(partial); |
| 74 _addFileSuggestions(partial); | 83 _addFileSuggestions(partial); |
| 75 } else if (parent is PartDirective && parent.uri == node) { | 84 } else if (parent is PartDirective && parent.uri == node) { |
| 76 String partial = node.literal.lexeme.substring( | 85 String partial = node.literal.lexeme.substring( |
| 77 node.contentsOffset - node.offset, request.offset - node.offset); | 86 node.contentsOffset - node.offset, request.offset - node.offset); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 request.addSuggestion(new CompletionSuggestion( | 184 request.addSuggestion(new CompletionSuggestion( |
| 176 CompletionSuggestionKind.IMPORT, | 185 CompletionSuggestionKind.IMPORT, |
| 177 relevance, | 186 relevance, |
| 178 completion, | 187 completion, |
| 179 completion.length, | 188 completion.length, |
| 180 0, | 189 0, |
| 181 false, | 190 false, |
| 182 false)); | 191 false)); |
| 183 } | 192 } |
| 184 } | 193 } |
| OLD | NEW |