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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 // and there is no semicolon | 67 // and there is no semicolon |
68 visitSimpleStringLiteral(uri); | 68 visitSimpleStringLiteral(uri); |
69 } | 69 } |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 @override | 73 @override |
74 visitSimpleStringLiteral(SimpleStringLiteral node) { | 74 visitSimpleStringLiteral(SimpleStringLiteral node) { |
75 AstNode parent = node.parent; | 75 AstNode parent = node.parent; |
76 if (parent is NamespaceDirective && parent.uri == node) { | 76 if (parent is NamespaceDirective && parent.uri == node) { |
77 String partial = node.literal.lexeme.substring( | 77 String partialUri = _extractPartialUri(node); |
78 node.contentsOffset - node.offset, request.offset - node.offset); | 78 if (partialUri != null) { |
79 request.replacementOffset = node.contentsOffset; | 79 _addDartSuggestions(); |
80 request.replacementLength = node.contentsEnd - node.contentsOffset; | 80 _addPackageSuggestions(partialUri); |
81 _addDartSuggestions(); | 81 _addFileSuggestions(partialUri); |
82 _addPackageSuggestions(partial); | 82 } |
83 _addFileSuggestions(partial); | |
84 } else if (parent is PartDirective && parent.uri == node) { | 83 } else if (parent is PartDirective && parent.uri == node) { |
85 String partial = node.literal.lexeme.substring( | 84 String partialUri = _extractPartialUri(node); |
86 node.contentsOffset - node.offset, request.offset - node.offset); | 85 if (partialUri != null) { |
87 request.replacementOffset = node.contentsOffset; | 86 _addFileSuggestions(partialUri); |
88 request.replacementLength = node.contentsEnd - node.contentsOffset; | 87 } |
89 _addFileSuggestions(partial); | |
90 } | 88 } |
91 } | 89 } |
92 | 90 |
93 void _addDartSuggestions() { | 91 void _addDartSuggestions() { |
94 _addSuggestion('dart:'); | 92 _addSuggestion('dart:'); |
95 SourceFactory factory = request.context.sourceFactory; | 93 SourceFactory factory = request.context.sourceFactory; |
96 for (SdkLibrary lib in factory.dartSdk.sdkLibraries) { | 94 for (SdkLibrary lib in factory.dartSdk.sdkLibraries) { |
97 if (!lib.isInternal && !lib.isImplementation) { | 95 if (!lib.isInternal && !lib.isImplementation) { |
98 if (!lib.shortName.startsWith('dart:_')) { | 96 if (!lib.shortName.startsWith('dart:_')) { |
99 _addSuggestion(lib.shortName, | 97 _addSuggestion(lib.shortName, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 {int relevance: DART_RELEVANCE_DEFAULT}) { | 181 {int relevance: DART_RELEVANCE_DEFAULT}) { |
184 request.addSuggestion(new CompletionSuggestion( | 182 request.addSuggestion(new CompletionSuggestion( |
185 CompletionSuggestionKind.IMPORT, | 183 CompletionSuggestionKind.IMPORT, |
186 relevance, | 184 relevance, |
187 completion, | 185 completion, |
188 completion.length, | 186 completion.length, |
189 0, | 187 0, |
190 false, | 188 false, |
191 false)); | 189 false)); |
192 } | 190 } |
| 191 |
| 192 String _extractPartialUri(SimpleStringLiteral node) { |
| 193 if (request.offset < node.contentsOffset) { |
| 194 return null; |
| 195 } |
| 196 String partial = node.literal.lexeme.substring( |
| 197 node.contentsOffset - node.offset, request.offset - node.offset); |
| 198 request.replacementOffset = node.contentsOffset; |
| 199 request.replacementLength = node.contentsEnd - node.contentsOffset; |
| 200 return partial; |
| 201 } |
193 } | 202 } |
OLD | NEW |