| 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.computer.dart.local; | 5 library services.completion.computer.dart.local; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; |
| 8 | 9 |
| 9 import 'package:analysis_server/src/protocol.dart' as protocol | 10 import 'package:analysis_server/src/protocol.dart' as protocol |
| 10 show Element, ElementKind; | 11 show Element, ElementKind; |
| 11 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind; | 12 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind; |
| 12 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; | 13 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
| 13 import 'package:analysis_server/src/services/completion/local_declaration_visito
r.dart'; | 14 import 'package:analysis_server/src/services/completion/local_declaration_visito
r.dart'; |
| 14 import 'package:analysis_server/src/services/completion/optype.dart'; | 15 import 'package:analysis_server/src/services/completion/optype.dart'; |
| 15 import 'package:analyzer/src/generated/ast.dart'; | 16 import 'package:analyzer/src/generated/ast.dart'; |
| 16 import 'package:analyzer/src/generated/scanner.dart'; | 17 import 'package:analyzer/src/generated/scanner.dart'; |
| 17 import 'package:analyzer/src/generated/utilities_dart.dart'; | 18 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 } | 422 } |
| 422 } | 423 } |
| 423 | 424 |
| 424 /** | 425 /** |
| 425 * A visitor for collecting suggestions from the most specific child [AstNode] | 426 * A visitor for collecting suggestions from the most specific child [AstNode] |
| 426 * that contains the completion offset to the [CompilationUnit]. | 427 * that contains the completion offset to the [CompilationUnit]. |
| 427 */ | 428 */ |
| 428 class _LocalVisitor extends LocalDeclarationVisitor { | 429 class _LocalVisitor extends LocalDeclarationVisitor { |
| 429 final DartCompletionRequest request; | 430 final DartCompletionRequest request; |
| 430 final OpType optype; | 431 final OpType optype; |
| 432 HashSet<String> completions = new HashSet(); |
| 431 | 433 |
| 432 _LocalVisitor(this.request, int offset, this.optype) : super(offset); | 434 _LocalVisitor(this.request, int offset, this.optype) : super(offset); |
| 433 | 435 |
| 434 @override | 436 @override |
| 435 void declaredClass(ClassDeclaration declaration) { | 437 void declaredClass(ClassDeclaration declaration) { |
| 436 if (optype.includeTypeNameSuggestions) { | 438 if (optype.includeTypeNameSuggestions) { |
| 437 bool isDeprecated = _isDeprecated(declaration); | 439 bool isDeprecated = _isDeprecated(declaration); |
| 438 CompletionSuggestion suggestion = _addSuggestion(declaration.name, | 440 CompletionSuggestion suggestion = _addSuggestion(declaration.name, |
| 439 _NO_RETURN_TYPE, isDeprecated, DART_RELEVANCE_DEFAULT); | 441 _NO_RETURN_TYPE, isDeprecated, DART_RELEVANCE_DEFAULT); |
| 440 if (suggestion != null) { | 442 if (suggestion != null) { |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 suggestion.requiredParameterCount = paramList.where( | 661 suggestion.requiredParameterCount = paramList.where( |
| 660 (FormalParameter param) => param is! DefaultFormalParameter).length; | 662 (FormalParameter param) => param is! DefaultFormalParameter).length; |
| 661 suggestion.hasNamedParameters = paramList | 663 suggestion.hasNamedParameters = paramList |
| 662 .any((FormalParameter param) => param.kind == ParameterKind.NAMED); | 664 .any((FormalParameter param) => param.kind == ParameterKind.NAMED); |
| 663 } | 665 } |
| 664 | 666 |
| 665 CompletionSuggestion _addSuggestion(SimpleIdentifier id, TypeName returnType, | 667 CompletionSuggestion _addSuggestion(SimpleIdentifier id, TypeName returnType, |
| 666 bool isDeprecated, int defaultRelevance, {ClassDeclaration classDecl}) { | 668 bool isDeprecated, int defaultRelevance, {ClassDeclaration classDecl}) { |
| 667 if (id != null) { | 669 if (id != null) { |
| 668 String completion = id.name; | 670 String completion = id.name; |
| 669 if (completion != null && completion.length > 0 && completion != '_') { | 671 if (completion != null && |
| 672 completion.length > 0 && |
| 673 completion != '_' && |
| 674 completions.add(completion)) { |
| 670 CompletionSuggestion suggestion = new CompletionSuggestion( | 675 CompletionSuggestion suggestion = new CompletionSuggestion( |
| 671 CompletionSuggestionKind.INVOCATION, | 676 CompletionSuggestionKind.INVOCATION, |
| 672 isDeprecated ? DART_RELEVANCE_LOW : defaultRelevance, completion, | 677 isDeprecated ? DART_RELEVANCE_LOW : defaultRelevance, completion, |
| 673 completion.length, 0, isDeprecated, false, | 678 completion.length, 0, isDeprecated, false, |
| 674 returnType: _nameForType(returnType)); | 679 returnType: _nameForType(returnType)); |
| 675 if (classDecl != null) { | 680 if (classDecl != null) { |
| 676 SimpleIdentifier identifier = classDecl.name; | 681 SimpleIdentifier identifier = classDecl.name; |
| 677 if (identifier != null) { | 682 if (identifier != null) { |
| 678 String name = identifier.name; | 683 String name = identifier.name; |
| 679 if (name != null && name.length > 0) { | 684 if (name != null && name.length > 0) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 691 bool _isVoid(TypeName returnType) { | 696 bool _isVoid(TypeName returnType) { |
| 692 if (returnType != null) { | 697 if (returnType != null) { |
| 693 Identifier id = returnType.name; | 698 Identifier id = returnType.name; |
| 694 if (id != null && id.name == 'void') { | 699 if (id != null && id.name == 'void') { |
| 695 return true; | 700 return true; |
| 696 } | 701 } |
| 697 } | 702 } |
| 698 return false; | 703 return false; |
| 699 } | 704 } |
| 700 } | 705 } |
| OLD | NEW |