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

Unified Diff: editor/tools/plugins/com.google.dart.engine.services/src/com/google/dart/engine/services/completion/CompletionEngine.java

Issue 172763003: Issue 16153. Auto-complete for import statements. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Extract helper and use marker constant Created 6 years, 10 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: editor/tools/plugins/com.google.dart.engine.services/src/com/google/dart/engine/services/completion/CompletionEngine.java
diff --git a/editor/tools/plugins/com.google.dart.engine.services/src/com/google/dart/engine/services/completion/CompletionEngine.java b/editor/tools/plugins/com.google.dart.engine.services/src/com/google/dart/engine/services/completion/CompletionEngine.java
index caef044d8dea480668a04d25181304e18e045a10..94b331949bed41da0c6a17d0afc71074a68d6d86 100644
--- a/editor/tools/plugins/com.google.dart.engine.services/src/com/google/dart/engine/services/completion/CompletionEngine.java
+++ b/editor/tools/plugins/com.google.dart.engine.services/src/com/google/dart/engine/services/completion/CompletionEngine.java
@@ -74,6 +74,7 @@ import com.google.dart.engine.ast.SimpleFormalParameter;
import com.google.dart.engine.ast.SimpleIdentifier;
import com.google.dart.engine.ast.SimpleStringLiteral;
import com.google.dart.engine.ast.Statement;
+import com.google.dart.engine.ast.StringLiteral;
import com.google.dart.engine.ast.SuperConstructorInvocation;
import com.google.dart.engine.ast.SuperExpression;
import com.google.dart.engine.ast.SwitchCase;
@@ -1270,6 +1271,16 @@ public class CompletionEngine {
}
@Override
+ public Void visitNamespaceDirective(NamespaceDirective node) {
+ StringLiteral uri = node.getUri();
+ if (uri != null && uri.isSynthetic()
+ && node.getKeyword().getEnd() <= context.getSelectionOffset()) {
+ uri.accept(this);
+ }
+ return super.visitNamespaceDirective(node);
+ }
+
+ @Override
public Void visitPartOfDirective(PartOfDirective node) {
if (isCompletingKeyword(node.getOfToken())) {
pKeyword(node.getOfToken());
@@ -2086,7 +2097,7 @@ public class CompletionEngine {
}
// if no URI yet, propose package:
if (prefix.isEmpty()) {
- pName("package:", ProposalKind.IMPORT);
+ pImportUriWithoutPrefix(node, "package:");
return;
}
// check "packages" folder for package libraries that are not added to AnalysisContext
@@ -2175,7 +2186,7 @@ public class CompletionEngine {
return;
}
if (prefix.isEmpty()) {
- pName("dart:", ProposalKind.IMPORT);
+ pImportUriWithoutPrefix(node, "dart:");
return;
}
// add DartSdk libraries
@@ -2660,6 +2671,23 @@ public class CompletionEngine {
requestor.accept(prop);
}
+ /**
+ * Proposes URI with the given scheme for the given {@link NamespaceDirective}.
+ */
+ private void pImportUriWithoutPrefix(NamespaceDirective node, String uriScheme) {
+ String newUri = uriScheme + CompletionProposal.CURSOR_MARKER;
+ if (node.getUri().isSynthetic()) {
+ newUri = "'" + newUri + "'";
+ }
+ if (context.getSelectionOffset() == node.getKeyword().getEnd()) {
+ newUri = " " + newUri;
+ }
+ if (node.getSemicolon() == null || node.getSemicolon().isSynthetic()) {
+ newUri += ";";
+ }
+ pName(newUri, ProposalKind.IMPORT);
+ }
+
private void pKeyword(Token keyword) {
filter = new Filter(keyword.getLexeme(), keyword.getOffset(), completionLocation());
// This isn't as useful as it might seem. It only works in the case that completion

Powered by Google App Engine
This is Rietveld 408576698