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

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

Issue 812593008: Completion support for loop labels. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix problems with toplevel variables. Created 5 years, 11 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/lib/src/services/completion/local_declaration_visitor.dart » ('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/local_computer.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/local_computer.dart b/pkg/analysis_server/lib/src/services/completion/local_computer.dart
index 89f8a40d6964b792452a75898106212c3611fedf..bc8cf39cd5b927a9002eb43dadb2c0dfa47cd3c5 100644
--- a/pkg/analysis_server/lib/src/services/completion/local_computer.dart
+++ b/pkg/analysis_server/lib/src/services/completion/local_computer.dart
@@ -35,6 +35,10 @@ class LocalComputer extends DartCompletionComputer {
// the completion offset and all of its parents recursively.
request.node.accept(localVisitor);
}
+ if (optype.includeStatementLabelSuggestions) {
+ _LabelVisitor labelVisitor = new _LabelVisitor(request);
+ request.node.accept(labelVisitor);
+ }
// If the unit is not a part and does not reference any parts
// then work is complete
@@ -52,6 +56,118 @@ class LocalComputer extends DartCompletionComputer {
}
/**
+ * A visitor for collecting suggestions for break and continue labels.
+ */
+class _LabelVisitor extends LocalDeclarationVisitor {
+ final DartCompletionRequest request;
+
+ _LabelVisitor(DartCompletionRequest request)
+ : super(request.offset),
+ request = request;
+
+ @override
+ void declaredClass(ClassDeclaration declaration) {
+ // ignored
+ }
+
+ @override
+ void declaredClassTypeAlias(ClassTypeAlias declaration) {
+ // ignored
+ }
+
+ @override
+ void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) {
+ // ignored
+ }
+
+ @override
+ void declaredFunction(FunctionDeclaration declaration) {
+ // ignored
+ }
+
+ @override
+ void declaredFunctionTypeAlias(FunctionTypeAlias declaration) {
+ // ignored
+ }
+
+ @override
+ void declaredLabel(Label label) {
+ CompletionSuggestion suggestion = _addSuggestion(label.label);
+ if (suggestion != null) {
+ suggestion.element =
+ _createElement(protocol.ElementKind.LABEL, label.label);
+ }
+ }
+
+ @override
+ void declaredLocalVar(SimpleIdentifier name, TypeName type) {
+ // ignored
+ }
+
+ @override
+ void declaredMethod(MethodDeclaration declaration) {
+ // ignored
+ }
+
+ @override
+ void declaredParam(SimpleIdentifier name, TypeName type) {
+ // ignored
+ }
+
+ @override
+ void declaredTopLevelVar(VariableDeclarationList varList,
+ VariableDeclaration varDecl) {
+ // ignored
+ }
+
+ @override
+ bool visitFunctionExpression(FunctionExpression node) {
+ // Labels are only accessible within the local function, so stop visiting
+ // once we reach a function boundary.
+ finished = true;
+ return true;
+ }
+
+ @override
+ bool visitMethodDeclaration(MethodDeclaration node) {
+ // Labels are only accessible within the local function, so stop visiting
+ // once we reach a function boundary.
+ finished = true;
+ return true;
+ }
+
+ CompletionSuggestion _addSuggestion(SimpleIdentifier id) {
+ if (id != null) {
+ String completion = id.name;
+ if (completion != null && completion.length > 0 && completion != '_') {
+ CompletionSuggestion suggestion = new CompletionSuggestion(
+ CompletionSuggestionKind.IDENTIFIER,
+ COMPLETION_RELEVANCE_DEFAULT,
+ completion,
+ completion.length,
+ 0,
+ false,
+ false);
+ request.suggestions.add(suggestion);
+ return suggestion;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Create a new protocol Element for inclusion in a completion suggestion.
+ */
+ protocol.Element _createElement(protocol.ElementKind kind,
+ SimpleIdentifier id) {
+ String name = id.name;
+ int flags =
+ protocol.Element.makeFlags(isPrivate: Identifier.isPrivateName(name));
+ return new protocol.Element(kind, name, flags);
+ }
+}
+
+/**
* A visitor for collecting suggestions from the most specific child [AstNode]
* that contains the completion offset to the [CompilationUnit].
*/
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/completion/local_declaration_visitor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698