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

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

Issue 1095113004: include importUri in out of scope suggestions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 5 years, 8 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
Index: pkg/analysis_server/lib/src/services/completion/suggestion_builder.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/suggestion_builder.dart b/pkg/analysis_server/lib/src/services/completion/suggestion_builder.dart
index ac87e30dd1d1263d6c6de605aced7022f910eb37..5c572e43bf5ed535b0da3b860039745fca1cbc22 100644
--- a/pkg/analysis_server/lib/src/services/completion/suggestion_builder.dart
+++ b/pkg/analysis_server/lib/src/services/completion/suggestion_builder.dart
@@ -14,16 +14,20 @@ import 'package:analysis_server/src/services/completion/dart_completion_manager.
import 'package:analyzer/src/generated/ast.dart';
import 'package:analyzer/src/generated/element.dart';
import 'package:analyzer/src/generated/utilities_dart.dart';
+import 'package:analyzer/src/generated/source.dart';
+import 'package:path/path.dart' as path;
const String DYNAMIC = 'dynamic';
/**
* Return a suggestion based upon the given element
* or `null` if a suggestion is not appropriate for the given element.
+ * If the suggestion is not currently in scope, then specify
+ * importForSource as the source to which an import should be added.
*/
CompletionSuggestion createSuggestion(Element element,
{CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
- int relevance: DART_RELEVANCE_DEFAULT}) {
+ int relevance: DART_RELEVANCE_DEFAULT, Source importForSource}) {
String nameForType(DartType type) {
if (type == null) {
return DYNAMIC;
@@ -78,6 +82,34 @@ CompletionSuggestion createSuggestion(Element element,
(ParameterElement parameter) =>
parameter.parameterKind == ParameterKind.NAMED);
}
+ if (importForSource != null) {
+ String srcPath = path.dirname(importForSource.fullName);
+ LibraryElement libElem = element.library;
+ if (libElem != null) {
+ Source libSource = libElem.source;
+ if (libSource != null) {
+ UriKind uriKind = libSource.uriKind;
+ if (uriKind == UriKind.DART_URI) {
+ suggestion.importUri = libSource.uri.toString();
+ } else if (uriKind == UriKind.PACKAGE_URI) {
+ // TODO(danrubel) implement
+ } else if (uriKind == UriKind.FILE_URI &&
+ element.source.uriKind == UriKind.FILE_URI) {
+ try {
+ suggestion.importUri =
+ path.relative(libSource.fullName, from: srcPath);
+ } catch (_) {
+ // ignored
+ }
+ }
+ }
+ }
+ if (suggestion.importUri == null) {
+ // Do not include out of scope suggestions
+ // for which we cannot determine an import
+ return null;
+ }
+ }
return suggestion;
}

Powered by Google App Engine
This is Rietveld 408576698