| 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/provisional/completion/dart/completion_dart.
dart'; |
| 11 import 'package:analyzer/file_system/file_system.dart'; | 11 import 'package:analyzer/file_system/file_system.dart'; |
| 12 import 'package:analyzer/src/generated/ast.dart'; | 12 import 'package:analyzer/src/generated/ast.dart'; |
| 13 import 'package:analyzer/src/generated/sdk.dart'; | 13 import 'package:analyzer/src/generated/sdk.dart'; |
| 14 import 'package:analyzer/src/generated/source.dart'; | 14 import 'package:analyzer/src/generated/source.dart'; |
| 15 import 'package:path/path.dart' show posix; | 15 import 'package:path/path.dart' show posix; |
| 16 import 'package:path/src/context.dart'; | 16 import 'package:path/src/context.dart'; |
| 17 | 17 |
| 18 import '../../protocol_server.dart' | 18 import '../../../protocol_server.dart' |
| 19 show CompletionSuggestion, CompletionSuggestionKind; | 19 show CompletionSuggestion, CompletionSuggestionKind; |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * A contributor for calculating uri suggestions | 22 * A contributor for calculating uri suggestions |
| 23 * for import and part directives. | 23 * for import and part directives. |
| 24 */ | 24 */ |
| 25 class UriContributor extends DartCompletionContributor { | 25 class UriContributor extends DartCompletionContributor { |
| 26 _UriSuggestionBuilder builder; | 26 _UriSuggestionBuilder builder; |
| 27 | 27 |
| 28 @override | 28 @override |
| 29 bool computeFast(DartCompletionRequest request) { | 29 Future<List<CompletionSuggestion>> computeSuggestions( |
| 30 DartCompletionRequest request) async { |
| 30 builder = new _UriSuggestionBuilder(request); | 31 builder = new _UriSuggestionBuilder(request); |
| 31 return builder.computeFast(request.target.containingNode); | 32 request.target.containingNode.accept(builder); |
| 32 } | 33 return builder.suggestions; |
| 33 | |
| 34 @override | |
| 35 Future<bool> computeFull(DartCompletionRequest request) { | |
| 36 return new Future.value(false); | |
| 37 } | 34 } |
| 38 } | 35 } |
| 39 | 36 |
| 40 class _UriSuggestionBuilder extends SimpleAstVisitor { | 37 class _UriSuggestionBuilder extends SimpleAstVisitor { |
| 41 final DartCompletionRequest request; | 38 final DartCompletionRequest request; |
| 39 final List<CompletionSuggestion> suggestions = <CompletionSuggestion>[]; |
| 42 | 40 |
| 43 _UriSuggestionBuilder(this.request); | 41 _UriSuggestionBuilder(this.request); |
| 44 | 42 |
| 45 bool computeFast(AstNode node) { | |
| 46 node.accept(this); | |
| 47 return true; | |
| 48 } | |
| 49 | |
| 50 @override | 43 @override |
| 51 visitExportDirective(ExportDirective node) { | 44 visitExportDirective(ExportDirective node) { |
| 52 visitNamespaceDirective(node); | 45 visitNamespaceDirective(node); |
| 53 } | 46 } |
| 54 | 47 |
| 55 @override | 48 @override |
| 56 visitImportDirective(ImportDirective node) { | 49 visitImportDirective(ImportDirective node) { |
| 57 visitNamespaceDirective(node); | 50 visitNamespaceDirective(node); |
| 58 } | 51 } |
| 59 | 52 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 if (folder.exists) { | 165 if (folder.exists) { |
| 173 _addPackageFolderSuggestions(partial, prefix, folder); | 166 _addPackageFolderSuggestions(partial, prefix, folder); |
| 174 } | 167 } |
| 175 } | 168 } |
| 176 }); | 169 }); |
| 177 } | 170 } |
| 178 } | 171 } |
| 179 | 172 |
| 180 void _addSuggestion(String completion, | 173 void _addSuggestion(String completion, |
| 181 {int relevance: DART_RELEVANCE_DEFAULT}) { | 174 {int relevance: DART_RELEVANCE_DEFAULT}) { |
| 182 request.addSuggestion(new CompletionSuggestion( | 175 suggestions.add(new CompletionSuggestion(CompletionSuggestionKind.IMPORT, |
| 183 CompletionSuggestionKind.IMPORT, | 176 relevance, completion, completion.length, 0, false, false)); |
| 184 relevance, | |
| 185 completion, | |
| 186 completion.length, | |
| 187 0, | |
| 188 false, | |
| 189 false)); | |
| 190 } | 177 } |
| 191 | 178 |
| 192 String _extractPartialUri(SimpleStringLiteral node) { | 179 String _extractPartialUri(SimpleStringLiteral node) { |
| 193 if (request.offset < node.contentsOffset) { | 180 if (request.offset < node.contentsOffset) { |
| 194 return null; | 181 return null; |
| 195 } | 182 } |
| 196 String partial = node.literal.lexeme.substring( | 183 return node.literal.lexeme.substring( |
| 197 node.contentsOffset - node.offset, request.offset - node.offset); | 184 node.contentsOffset - node.offset, request.offset - node.offset); |
| 198 request.replacementOffset = node.contentsOffset; | |
| 199 request.replacementLength = node.contentsEnd - node.contentsOffset; | |
| 200 return partial; | |
| 201 } | 185 } |
| 202 } | 186 } |
| OLD | NEW |