| OLD | NEW |
| 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.contributor.dart.local; | 5 library services.completion.contributor.dart.local; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol.dart' as protocol | 9 import 'package:analysis_server/src/protocol.dart' as protocol |
| 10 show Element, ElementKind; | 10 show Element, ElementKind; |
| 11 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind; | 11 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind; |
| 12 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; | 12 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
| 13 import 'package:analysis_server/src/services/completion/local_declaration_visito
r.dart'; | 13 import 'package:analysis_server/src/services/completion/local_declaration_visito
r.dart'; |
| 14 import 'package:analysis_server/src/services/completion/local_suggestion_builder
.dart'; | 14 import 'package:analysis_server/src/services/completion/local_suggestion_builder
.dart'; |
| 15 import 'package:analysis_server/src/services/completion/optype.dart'; | 15 import 'package:analysis_server/src/services/completion/optype.dart'; |
| 16 import 'package:analyzer/src/generated/ast.dart'; | 16 import 'package:analyzer/src/generated/ast.dart'; |
| 17 import 'package:analyzer/src/generated/source.dart'; |
| 17 import 'package:analyzer/src/generated/utilities_dart.dart'; | 18 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 18 | 19 |
| 19 /** | 20 /** |
| 20 * A contributor for calculating `completion.getSuggestions` request results | 21 * A contributor for calculating `completion.getSuggestions` request results |
| 21 * for the local library in which the completion is requested. | 22 * for the local library in which the completion is requested. |
| 22 */ | 23 */ |
| 23 class LocalReferenceContributor extends DartCompletionContributor { | 24 class LocalReferenceContributor extends DartCompletionContributor { |
| 24 @override | 25 @override |
| 25 bool computeFast(DartCompletionRequest request) { | 26 bool computeFast(DartCompletionRequest request) { |
| 26 OpType optype = request.optype; | 27 OpType optype = request.optype; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 paramBuf.write(' '); | 176 paramBuf.write(' '); |
| 176 paramBuf.write(paramName); | 177 paramBuf.write(paramName); |
| 177 ++paramCount; | 178 ++paramCount; |
| 178 } | 179 } |
| 179 } | 180 } |
| 180 if (paramCount > requiredParameterCount) { | 181 if (paramCount > requiredParameterCount) { |
| 181 paramBuf.write(hasNamedParameters ? '}' : ']'); | 182 paramBuf.write(hasNamedParameters ? '}' : ']'); |
| 182 } | 183 } |
| 183 paramBuf.write(')'); | 184 paramBuf.write(')'); |
| 184 protocol.Element element = createElement( | 185 protocol.Element element = createElement( |
| 185 protocol.ElementKind.CONSTRUCTOR, elemId, | 186 request.source, protocol.ElementKind.CONSTRUCTOR, elemId, |
| 186 parameters: paramBuf.toString()); | 187 parameters: paramBuf.toString()); |
| 187 element.returnType = classDecl.name.name; | 188 element.returnType = classDecl.name.name; |
| 188 CompletionSuggestion suggestion = new CompletionSuggestion( | 189 CompletionSuggestion suggestion = new CompletionSuggestion( |
| 189 CompletionSuggestionKind.INVOCATION, | 190 CompletionSuggestionKind.INVOCATION, |
| 190 deprecated ? DART_RELEVANCE_LOW : DART_RELEVANCE_DEFAULT, completion, | 191 deprecated ? DART_RELEVANCE_LOW : DART_RELEVANCE_DEFAULT, completion, |
| 191 completion.length, 0, deprecated, false, | 192 completion.length, 0, deprecated, false, |
| 192 declaringType: classDecl.name.name, | 193 declaringType: classDecl.name.name, |
| 193 element: element, | 194 element: element, |
| 194 parameterNames: parameterNames, | 195 parameterNames: parameterNames, |
| 195 parameterTypes: parameterTypes, | 196 parameterTypes: parameterTypes, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 @override | 271 @override |
| 271 void declaredFunctionTypeAlias(FunctionTypeAlias declaration) { | 272 void declaredFunctionTypeAlias(FunctionTypeAlias declaration) { |
| 272 // ignored | 273 // ignored |
| 273 } | 274 } |
| 274 | 275 |
| 275 @override | 276 @override |
| 276 void declaredLabel(Label label, bool isCaseLabel) { | 277 void declaredLabel(Label label, bool isCaseLabel) { |
| 277 if (isCaseLabel ? includeCaseLabels : includeStatementLabels) { | 278 if (isCaseLabel ? includeCaseLabels : includeStatementLabels) { |
| 278 CompletionSuggestion suggestion = _addSuggestion(label.label); | 279 CompletionSuggestion suggestion = _addSuggestion(label.label); |
| 279 if (suggestion != null) { | 280 if (suggestion != null) { |
| 280 suggestion.element = | 281 suggestion.element = createElement( |
| 281 _createElement(protocol.ElementKind.LABEL, label.label); | 282 request.source, protocol.ElementKind.LABEL, label.label, |
| 283 returnType: NO_RETURN_TYPE); |
| 282 } | 284 } |
| 283 } | 285 } |
| 284 } | 286 } |
| 285 | 287 |
| 286 @override | 288 @override |
| 287 void declaredLocalVar(SimpleIdentifier name, TypeName type) { | 289 void declaredLocalVar(SimpleIdentifier name, TypeName type) { |
| 288 // ignored | 290 // ignored |
| 289 } | 291 } |
| 290 | 292 |
| 291 @override | 293 @override |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 if (completion != null && completion.length > 0 && completion != '_') { | 326 if (completion != null && completion.length > 0 && completion != '_') { |
| 325 CompletionSuggestion suggestion = new CompletionSuggestion( | 327 CompletionSuggestion suggestion = new CompletionSuggestion( |
| 326 CompletionSuggestionKind.IDENTIFIER, DART_RELEVANCE_DEFAULT, | 328 CompletionSuggestionKind.IDENTIFIER, DART_RELEVANCE_DEFAULT, |
| 327 completion, completion.length, 0, false, false); | 329 completion, completion.length, 0, false, false); |
| 328 request.addSuggestion(suggestion); | 330 request.addSuggestion(suggestion); |
| 329 return suggestion; | 331 return suggestion; |
| 330 } | 332 } |
| 331 } | 333 } |
| 332 return null; | 334 return null; |
| 333 } | 335 } |
| 334 | |
| 335 /** | |
| 336 * Create a new protocol Element for inclusion in a completion suggestion. | |
| 337 */ | |
| 338 protocol.Element _createElement( | |
| 339 protocol.ElementKind kind, SimpleIdentifier id) { | |
| 340 String name = id.name; | |
| 341 int flags = | |
| 342 protocol.Element.makeFlags(isPrivate: Identifier.isPrivateName(name)); | |
| 343 return new protocol.Element(kind, name, flags); | |
| 344 } | |
| 345 } | 336 } |
| 346 | 337 |
| 347 /** | 338 /** |
| 348 * A visitor for collecting suggestions from the most specific child [AstNode] | 339 * A visitor for collecting suggestions from the most specific child [AstNode] |
| 349 * that contains the completion offset to the [CompilationUnit]. | 340 * that contains the completion offset to the [CompilationUnit]. |
| 350 */ | 341 */ |
| 351 class _LocalVisitor extends LocalDeclarationVisitor { | 342 class _LocalVisitor extends LocalDeclarationVisitor { |
| 352 final DartCompletionRequest request; | 343 final DartCompletionRequest request; |
| 353 final OpType optype; | 344 final OpType optype; |
| 354 | 345 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 379 _addSuggestion( | 370 _addSuggestion( |
| 380 declaration.name, NO_RETURN_TYPE, protocol.ElementKind.ENUM, | 371 declaration.name, NO_RETURN_TYPE, protocol.ElementKind.ENUM, |
| 381 isDeprecated: isDeprecated(declaration)); | 372 isDeprecated: isDeprecated(declaration)); |
| 382 } | 373 } |
| 383 } | 374 } |
| 384 | 375 |
| 385 @override | 376 @override |
| 386 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) { | 377 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) { |
| 387 if (optype.includeReturnValueSuggestions) { | 378 if (optype.includeReturnValueSuggestions) { |
| 388 CompletionSuggestion suggestion = | 379 CompletionSuggestion suggestion = |
| 389 createFieldSuggestion(fieldDecl, varDecl); | 380 createFieldSuggestion(request.source, fieldDecl, varDecl); |
| 390 if (suggestion != null) { | 381 if (suggestion != null) { |
| 391 request.addSuggestion(suggestion); | 382 request.addSuggestion(suggestion); |
| 392 } | 383 } |
| 393 } | 384 } |
| 394 } | 385 } |
| 395 | 386 |
| 396 @override | 387 @override |
| 397 void declaredFunction(FunctionDeclaration declaration) { | 388 void declaredFunction(FunctionDeclaration declaration) { |
| 398 if (optype.includeReturnValueSuggestions || | 389 if (optype.includeReturnValueSuggestions || |
| 399 optype.includeVoidReturnSuggestions) { | 390 optype.includeVoidReturnSuggestions) { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 | 531 |
| 541 void _addSuggestion( | 532 void _addSuggestion( |
| 542 SimpleIdentifier id, TypeName typeName, protocol.ElementKind elemKind, | 533 SimpleIdentifier id, TypeName typeName, protocol.ElementKind elemKind, |
| 543 {bool isAbstract: false, bool isDeprecated: false, | 534 {bool isAbstract: false, bool isDeprecated: false, |
| 544 ClassDeclaration classDecl, FormalParameterList param, | 535 ClassDeclaration classDecl, FormalParameterList param, |
| 545 int relevance: DART_RELEVANCE_DEFAULT}) { | 536 int relevance: DART_RELEVANCE_DEFAULT}) { |
| 546 CompletionSuggestion suggestion = createSuggestion( | 537 CompletionSuggestion suggestion = createSuggestion( |
| 547 id, isDeprecated, relevance, typeName, classDecl: classDecl); | 538 id, isDeprecated, relevance, typeName, classDecl: classDecl); |
| 548 if (suggestion != null) { | 539 if (suggestion != null) { |
| 549 request.addSuggestion(suggestion); | 540 request.addSuggestion(suggestion); |
| 550 suggestion.element = createElement(elemKind, id, | 541 suggestion.element = createElement(request.source, elemKind, id, |
| 551 isAbstract: isAbstract, | 542 isAbstract: isAbstract, |
| 552 isDeprecated: isDeprecated, | 543 isDeprecated: isDeprecated, |
| 553 parameters: param != null ? param.toSource() : null, | 544 parameters: param != null ? param.toSource() : null, |
| 554 returnType: typeName); | 545 returnType: typeName); |
| 555 if ((elemKind == protocol.ElementKind.METHOD || | 546 if ((elemKind == protocol.ElementKind.METHOD || |
| 556 elemKind == protocol.ElementKind.FUNCTION) && | 547 elemKind == protocol.ElementKind.FUNCTION) && |
| 557 param != null) { | 548 param != null) { |
| 558 _addParameterInfo(suggestion, param); | 549 _addParameterInfo(suggestion, param); |
| 559 } | 550 } |
| 560 } | 551 } |
| 561 } | 552 } |
| 562 | 553 |
| 563 bool _isVoid(TypeName returnType) { | 554 bool _isVoid(TypeName returnType) { |
| 564 if (returnType != null) { | 555 if (returnType != null) { |
| 565 Identifier id = returnType.name; | 556 Identifier id = returnType.name; |
| 566 if (id != null && id.name == 'void') { | 557 if (id != null && id.name == 'void') { |
| 567 return true; | 558 return true; |
| 568 } | 559 } |
| 569 } | 560 } |
| 570 return false; | 561 return false; |
| 571 } | 562 } |
| 572 } | 563 } |
| OLD | NEW |