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

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

Issue 1027693007: exclude identifier being completed from list of suggestions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 5 years, 9 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/test/services/completion/local_computer_test.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 9 import 'package:analysis_server/src/protocol.dart' as protocol
10 show Element, ElementKind; 10 show Element, ElementKind;
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 } 422 }
423 423
424 /** 424 /**
425 * A visitor for collecting suggestions from the most specific child [AstNode] 425 * A visitor for collecting suggestions from the most specific child [AstNode]
426 * that contains the completion offset to the [CompilationUnit]. 426 * that contains the completion offset to the [CompilationUnit].
427 */ 427 */
428 class _LocalVisitor extends LocalDeclarationVisitor { 428 class _LocalVisitor extends LocalDeclarationVisitor {
429 final DartCompletionRequest request; 429 final DartCompletionRequest request;
430 final OpType optype; 430 final OpType optype;
431 431
432 /**
433 * The simple identifier that is being completed, or `null` if none.
434 */
435 SimpleIdentifier targetId;
436
432 _LocalVisitor(this.request, int offset, this.optype) : super(offset); 437 _LocalVisitor(this.request, int offset, this.optype) : super(offset);
433 438
434 @override 439 @override
435 void declaredClass(ClassDeclaration declaration) { 440 void declaredClass(ClassDeclaration declaration) {
436 if (optype.includeTypeNameSuggestions) { 441 if (optype.includeTypeNameSuggestions) {
437 bool isDeprecated = _isDeprecated(declaration); 442 bool isDeprecated = _isDeprecated(declaration);
438 CompletionSuggestion suggestion = _addSuggestion(declaration.name, 443 CompletionSuggestion suggestion = _addSuggestion(declaration.name,
439 _NO_RETURN_TYPE, isDeprecated, DART_RELEVANCE_DEFAULT); 444 _NO_RETURN_TYPE, isDeprecated, DART_RELEVANCE_DEFAULT);
440 if (suggestion != null) { 445 if (suggestion != null) {
441 suggestion.element = _createElement( 446 suggestion.element = _createElement(
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 CompletionSuggestion suggestion = _addSuggestion(varDecl.name, 624 CompletionSuggestion suggestion = _addSuggestion(varDecl.name,
620 varList.type, isDeprecated, DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE); 625 varList.type, isDeprecated, DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE);
621 if (suggestion != null) { 626 if (suggestion != null) {
622 suggestion.element = _createElement( 627 suggestion.element = _createElement(
623 protocol.ElementKind.TOP_LEVEL_VARIABLE, varDecl.name, 628 protocol.ElementKind.TOP_LEVEL_VARIABLE, varDecl.name,
624 returnType: varList.type, isDeprecated: isDeprecated); 629 returnType: varList.type, isDeprecated: isDeprecated);
625 } 630 }
626 } 631 }
627 } 632 }
628 633
634 @override
635 void visitSimpleIdentifier(SimpleIdentifier node) {
636 // Record the visited identifier so as not to suggest it
637 targetId = node;
638 return super.visitSimpleIdentifier(node);
639 }
640
629 void _addParameterInfo( 641 void _addParameterInfo(
630 CompletionSuggestion suggestion, FormalParameterList parameters) { 642 CompletionSuggestion suggestion, FormalParameterList parameters) {
631 var paramList = parameters.parameters; 643 var paramList = parameters.parameters;
632 suggestion.parameterNames = paramList 644 suggestion.parameterNames = paramList
633 .map((FormalParameter param) => param.identifier.name) 645 .map((FormalParameter param) => param.identifier.name)
634 .toList(); 646 .toList();
635 suggestion.parameterTypes = paramList.map((FormalParameter param) { 647 suggestion.parameterTypes = paramList.map((FormalParameter param) {
636 TypeName type = null; 648 TypeName type = null;
637 if (param is DefaultFormalParameter) { 649 if (param is DefaultFormalParameter) {
638 NormalFormalParameter child = param.parameter; 650 NormalFormalParameter child = param.parameter;
(...skipping 18 matching lines...) Expand all
657 return typeId.name; 669 return typeId.name;
658 }).toList(); 670 }).toList();
659 suggestion.requiredParameterCount = paramList.where( 671 suggestion.requiredParameterCount = paramList.where(
660 (FormalParameter param) => param is! DefaultFormalParameter).length; 672 (FormalParameter param) => param is! DefaultFormalParameter).length;
661 suggestion.hasNamedParameters = paramList 673 suggestion.hasNamedParameters = paramList
662 .any((FormalParameter param) => param.kind == ParameterKind.NAMED); 674 .any((FormalParameter param) => param.kind == ParameterKind.NAMED);
663 } 675 }
664 676
665 CompletionSuggestion _addSuggestion(SimpleIdentifier id, TypeName returnType, 677 CompletionSuggestion _addSuggestion(SimpleIdentifier id, TypeName returnType,
666 bool isDeprecated, int defaultRelevance, {ClassDeclaration classDecl}) { 678 bool isDeprecated, int defaultRelevance, {ClassDeclaration classDecl}) {
667 if (id != null) { 679 if (id != null && !identical(id, targetId)) {
668 String completion = id.name; 680 String completion = id.name;
669 if (completion != null && completion.length > 0 && completion != '_') { 681 if (completion != null && completion.length > 0 && completion != '_') {
670 CompletionSuggestion suggestion = new CompletionSuggestion( 682 CompletionSuggestion suggestion = new CompletionSuggestion(
671 CompletionSuggestionKind.INVOCATION, 683 CompletionSuggestionKind.INVOCATION,
672 isDeprecated ? DART_RELEVANCE_LOW : defaultRelevance, completion, 684 isDeprecated ? DART_RELEVANCE_LOW : defaultRelevance, completion,
673 completion.length, 0, isDeprecated, false, 685 completion.length, 0, isDeprecated, false,
674 returnType: _nameForType(returnType)); 686 returnType: _nameForType(returnType));
675 if (classDecl != null) { 687 if (classDecl != null) {
676 SimpleIdentifier identifier = classDecl.name; 688 SimpleIdentifier identifier = classDecl.name;
677 if (identifier != null) { 689 if (identifier != null) {
(...skipping 13 matching lines...) Expand all
691 bool _isVoid(TypeName returnType) { 703 bool _isVoid(TypeName returnType) {
692 if (returnType != null) { 704 if (returnType != null) {
693 Identifier id = returnType.name; 705 Identifier id = returnType.name;
694 if (id != null && id.name == 'void') { 706 if (id != null && id.name == 'void') {
695 return true; 707 return true;
696 } 708 }
697 } 709 }
698 return false; 710 return false;
699 } 711 }
700 } 712 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/completion/local_computer_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698