Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1585)

Unified Diff: pkg/analysis_server/lib/src/services/completion/import_uri_contributor.dart

Issue 1325583002: improve import uri completions - fixes #24000 (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge and fix test source path Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/services/completion/import_uri_contributor.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/import_uri_contributor.dart b/pkg/analysis_server/lib/src/services/completion/import_uri_contributor.dart
index b4059723cccf1e9f119a8c0987b591e0180b3d34..498c289740baebf31f9b02c7c74715136db66b5b 100644
--- a/pkg/analysis_server/lib/src/services/completion/import_uri_contributor.dart
+++ b/pkg/analysis_server/lib/src/services/completion/import_uri_contributor.dart
@@ -12,7 +12,8 @@ import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/generated/ast.dart';
import 'package:analyzer/src/generated/sdk.dart';
import 'package:analyzer/src/generated/source.dart';
-import 'package:path/path.dart';
+import 'package:path/path.dart' show posix;
+import 'package:path/src/context.dart';
import '../../protocol_server.dart'
show CompletionSuggestion, CompletionSuggestionKind;
@@ -95,32 +96,42 @@ class _ImportUriSuggestionBuilder extends SimpleAstVisitor {
}
}
- void _addFileSuggestions(String partial) {
+ void _addFileSuggestions(String partialUri) {
+ ResourceProvider resProvider = request.resourceProvider;
+ Context resContext = resProvider.pathContext;
Source source = request.source;
- String sourceFullName = source.fullName;
- String sourceShortName = source.shortName;
- String dirPath = (partial.endsWith('/') || partial.endsWith(separator))
- ? partial
- : dirname(partial);
- String prefix = dirPath == '.' ? '' : dirPath;
- if (isRelative(dirPath)) {
- String sourceDir = dirname(sourceFullName);
- if (isAbsolute(sourceDir)) {
- dirPath = join(sourceDir, dirPath);
+
+ String parentUri;
+ if ((partialUri.endsWith('/'))) {
+ parentUri = partialUri;
+ } else {
+ parentUri = posix.dirname(partialUri);
+ if (parentUri != '.' && !parentUri.endsWith('/')) {
+ parentUri = '$parentUri/';
+ }
+ }
+ String uriPrefix = parentUri == '.' ? '' : parentUri;
+
+ String dirPath = resContext.normalize(parentUri);
+ if (resContext.isRelative(dirPath)) {
+ String sourceDirPath = resContext.dirname(source.fullName);
+ if (resContext.isAbsolute(sourceDirPath)) {
+ dirPath = resContext.join(sourceDirPath, dirPath);
} else {
return;
}
}
- Resource dir = request.resourceProvider.getResource(dirPath);
+
+ Resource dir = resProvider.getResource(dirPath);
if (dir is Folder) {
for (Resource child in dir.getChildren()) {
String completion;
if (child is Folder) {
- completion = '$prefix${child.shortName}$separator';
+ completion = '$uriPrefix${child.shortName}/';
} else {
- completion = '$prefix${child.shortName}';
+ completion = '$uriPrefix${child.shortName}';
}
- if (completion != sourceShortName && completion != sourceFullName) {
+ if (completion != source.shortName) {
_addSuggestion(completion);
}
}
« no previous file with comments | « no previous file | pkg/analysis_server/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698