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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.computer.dart.local; 5 library services.completion.computer.dart.local;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol.dart' as protocol show Element, 9 import 'package:analysis_server/src/protocol.dart' as protocol show Element,
10 ElementKind; 10 ElementKind;
(...skipping 17 matching lines...) Expand all
28 _LocalVisitor localVisitor = new _LocalVisitor( 28 _LocalVisitor localVisitor = new _LocalVisitor(
29 request, 29 request,
30 request.offset, 30 request.offset,
31 optype.includeOnlyTypeNameSuggestions, 31 optype.includeOnlyTypeNameSuggestions,
32 !optype.includeVoidReturnSuggestions); 32 !optype.includeVoidReturnSuggestions);
33 33
34 // Collect suggestions from the specific child [AstNode] that contains 34 // Collect suggestions from the specific child [AstNode] that contains
35 // the completion offset and all of its parents recursively. 35 // the completion offset and all of its parents recursively.
36 request.node.accept(localVisitor); 36 request.node.accept(localVisitor);
37 } 37 }
38 if (optype.includeStatementLabelSuggestions) {
39 _LabelVisitor labelVisitor = new _LabelVisitor(request);
40 request.node.accept(labelVisitor);
41 }
38 42
39 // If the unit is not a part and does not reference any parts 43 // If the unit is not a part and does not reference any parts
40 // then work is complete 44 // then work is complete
41 return !request.unit.directives.any( 45 return !request.unit.directives.any(
42 (Directive directive) => 46 (Directive directive) =>
43 directive is PartOfDirective || directive is PartDirective); 47 directive is PartOfDirective || directive is PartDirective);
44 } 48 }
45 49
46 @override 50 @override
47 Future<bool> computeFull(DartCompletionRequest request) { 51 Future<bool> computeFull(DartCompletionRequest request) {
48 // TODO: implement computeFull 52 // TODO: implement computeFull
49 // include results from part files that are included in the library 53 // include results from part files that are included in the library
50 return new Future.value(false); 54 return new Future.value(false);
51 } 55 }
52 } 56 }
53 57
54 /** 58 /**
59 * A visitor for collecting suggestions for break and continue labels.
60 */
61 class _LabelVisitor extends LocalDeclarationVisitor {
62 final DartCompletionRequest request;
63
64 _LabelVisitor(DartCompletionRequest request)
65 : super(request.offset),
66 request = request;
67
68 @override
69 void declaredClass(ClassDeclaration declaration) {
70 // ignored
71 }
72
73 @override
74 void declaredClassTypeAlias(ClassTypeAlias declaration) {
75 // ignored
76 }
77
78 @override
79 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) {
80 // ignored
81 }
82
83 @override
84 void declaredFunction(FunctionDeclaration declaration) {
85 // ignored
86 }
87
88 @override
89 void declaredFunctionTypeAlias(FunctionTypeAlias declaration) {
90 // ignored
91 }
92
93 @override
94 void declaredLabel(Label label) {
95 CompletionSuggestion suggestion = _addSuggestion(label.label);
96 if (suggestion != null) {
97 suggestion.element =
98 _createElement(protocol.ElementKind.LABEL, label.label);
99 }
100 }
101
102 @override
103 void declaredLocalVar(SimpleIdentifier name, TypeName type) {
104 // ignored
105 }
106
107 @override
108 void declaredMethod(MethodDeclaration declaration) {
109 // ignored
110 }
111
112 @override
113 void declaredParam(SimpleIdentifier name, TypeName type) {
114 // ignored
115 }
116
117 @override
118 void declaredTopLevelVar(VariableDeclarationList varList,
119 VariableDeclaration varDecl) {
120 // ignored
121 }
122
123 @override
124 bool visitFunctionExpression(FunctionExpression node) {
125 // Labels are only accessible within the local function, so stop visiting
126 // once we reach a function boundary.
127 finished = true;
128 return true;
129 }
130
131 @override
132 bool visitMethodDeclaration(MethodDeclaration node) {
133 // Labels are only accessible within the local function, so stop visiting
134 // once we reach a function boundary.
135 finished = true;
136 return true;
137 }
138
139 CompletionSuggestion _addSuggestion(SimpleIdentifier id) {
140 if (id != null) {
141 String completion = id.name;
142 if (completion != null && completion.length > 0 && completion != '_') {
143 CompletionSuggestion suggestion = new CompletionSuggestion(
144 CompletionSuggestionKind.IDENTIFIER,
145 COMPLETION_RELEVANCE_DEFAULT,
146 completion,
147 completion.length,
148 0,
149 false,
150 false);
151 request.suggestions.add(suggestion);
152 return suggestion;
153 }
154 }
155 return null;
156 }
157
158 /**
159 * Create a new protocol Element for inclusion in a completion suggestion.
160 */
161 protocol.Element _createElement(protocol.ElementKind kind,
162 SimpleIdentifier id) {
163 String name = id.name;
164 int flags =
165 protocol.Element.makeFlags(isPrivate: Identifier.isPrivateName(name));
166 return new protocol.Element(kind, name, flags);
167 }
168 }
169
170 /**
55 * A visitor for collecting suggestions from the most specific child [AstNode] 171 * A visitor for collecting suggestions from the most specific child [AstNode]
56 * that contains the completion offset to the [CompilationUnit]. 172 * that contains the completion offset to the [CompilationUnit].
57 */ 173 */
58 class _LocalVisitor extends LocalDeclarationVisitor { 174 class _LocalVisitor extends LocalDeclarationVisitor {
59 static const DYNAMIC = 'dynamic'; 175 static const DYNAMIC = 'dynamic';
60 176
61 static final TypeName NO_RETURN_TYPE = new TypeName( 177 static final TypeName NO_RETURN_TYPE = new TypeName(
62 new SimpleIdentifier(new StringToken(TokenType.IDENTIFIER, '', 0)), 178 new SimpleIdentifier(new StringToken(TokenType.IDENTIFIER, '', 0)),
63 null); 179 null);
64 180
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 if (name == null || name.length <= 0) { 478 if (name == null || name.length <= 0) {
363 return DYNAMIC; 479 return DYNAMIC;
364 } 480 }
365 TypeArgumentList typeArgs = type.typeArguments; 481 TypeArgumentList typeArgs = type.typeArguments;
366 if (typeArgs != null) { 482 if (typeArgs != null) {
367 //TODO (danrubel) include type arguments 483 //TODO (danrubel) include type arguments
368 } 484 }
369 return name; 485 return name;
370 } 486 }
371 } 487 }
OLDNEW
« 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