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

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

Issue 982983003: remove type suggestion when interpolation completion (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
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 * A computer for calculating `completion.getSuggestions` request results 80 * A computer for calculating `completion.getSuggestions` request results
81 * for the local library in which the completion is requested. 81 * for the local library in which the completion is requested.
82 */ 82 */
83 class LocalComputer extends DartCompletionComputer { 83 class LocalComputer extends DartCompletionComputer {
84 @override 84 @override
85 bool computeFast(DartCompletionRequest request) { 85 bool computeFast(DartCompletionRequest request) {
86 OpType optype = request.optype; 86 OpType optype = request.optype;
87 87
88 // Collect suggestions from the specific child [AstNode] that contains 88 // Collect suggestions from the specific child [AstNode] that contains
89 // the completion offset and all of its parents recursively. 89 // the completion offset and all of its parents recursively.
90 if (optype.includeTopLevelSuggestions) { 90 if (optype.includeReturnValueSuggestions ||
91 _LocalVisitor localVisitor = new _LocalVisitor(request, request.offset, 91 optype.includeTypeNameSuggestions ||
92 optype.includeOnlyTypeNameSuggestions, 92 optype.includeVoidReturnSuggestions) {
93 !optype.includeVoidReturnSuggestions); 93 _LocalVisitor localVisitor =
94 new _LocalVisitor(request, request.offset, optype);
94 localVisitor.visit(request.node); 95 localVisitor.visit(request.node);
95 } 96 }
96 if (optype.includeStatementLabelSuggestions || 97 if (optype.includeStatementLabelSuggestions ||
97 optype.includeCaseLabelSuggestions) { 98 optype.includeCaseLabelSuggestions) {
98 _LabelVisitor labelVisitor = new _LabelVisitor(request, 99 _LabelVisitor labelVisitor = new _LabelVisitor(request,
99 optype.includeStatementLabelSuggestions, 100 optype.includeStatementLabelSuggestions,
100 optype.includeCaseLabelSuggestions); 101 optype.includeCaseLabelSuggestions);
101 labelVisitor.visit(request.node); 102 labelVisitor.visit(request.node);
102 } 103 }
103 if (optype.includeConstructorSuggestions) { 104 if (optype.includeConstructorSuggestions) {
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 return new protocol.Element(kind, name, flags); 420 return new protocol.Element(kind, name, flags);
420 } 421 }
421 } 422 }
422 423
423 /** 424 /**
424 * A visitor for collecting suggestions from the most specific child [AstNode] 425 * A visitor for collecting suggestions from the most specific child [AstNode]
425 * that contains the completion offset to the [CompilationUnit]. 426 * that contains the completion offset to the [CompilationUnit].
426 */ 427 */
427 class _LocalVisitor extends LocalDeclarationVisitor { 428 class _LocalVisitor extends LocalDeclarationVisitor {
428 final DartCompletionRequest request; 429 final DartCompletionRequest request;
429 final bool typesOnly; 430 final OpType optype;
430 final bool excludeVoidReturn;
431 431
432 _LocalVisitor( 432 _LocalVisitor(this.request, int offset, this.optype) : super(offset);
433 this.request, int offset, this.typesOnly, this.excludeVoidReturn)
434 : super(offset);
435 433
436 @override 434 @override
437 void declaredClass(ClassDeclaration declaration) { 435 void declaredClass(ClassDeclaration declaration) {
438 bool isDeprecated = _isDeprecated(declaration); 436 if (optype.includeTypeNameSuggestions) {
439 CompletionSuggestion suggestion = _addSuggestion(declaration.name, 437 bool isDeprecated = _isDeprecated(declaration);
440 _NO_RETURN_TYPE, isDeprecated, DART_RELEVANCE_DEFAULT); 438 CompletionSuggestion suggestion = _addSuggestion(declaration.name,
441 if (suggestion != null) { 439 _NO_RETURN_TYPE, isDeprecated, DART_RELEVANCE_DEFAULT);
442 suggestion.element = _createElement( 440 if (suggestion != null) {
443 protocol.ElementKind.CLASS, declaration.name, 441 suggestion.element = _createElement(
444 returnType: _NO_RETURN_TYPE, 442 protocol.ElementKind.CLASS, declaration.name,
445 isAbstract: declaration.isAbstract, 443 returnType: _NO_RETURN_TYPE,
446 isDeprecated: isDeprecated); 444 isAbstract: declaration.isAbstract,
445 isDeprecated: isDeprecated);
446 }
447 } 447 }
448 } 448 }
449 449
450 @override 450 @override
451 void declaredClassTypeAlias(ClassTypeAlias declaration) { 451 void declaredClassTypeAlias(ClassTypeAlias declaration) {
452 bool isDeprecated = _isDeprecated(declaration); 452 if (optype.includeTypeNameSuggestions) {
453 CompletionSuggestion suggestion = _addSuggestion(declaration.name, 453 bool isDeprecated = _isDeprecated(declaration);
454 _NO_RETURN_TYPE, isDeprecated, DART_RELEVANCE_DEFAULT); 454 CompletionSuggestion suggestion = _addSuggestion(declaration.name,
455 if (suggestion != null) { 455 _NO_RETURN_TYPE, isDeprecated, DART_RELEVANCE_DEFAULT);
456 suggestion.element = _createElement( 456 if (suggestion != null) {
457 protocol.ElementKind.CLASS_TYPE_ALIAS, declaration.name, 457 suggestion.element = _createElement(
458 returnType: _NO_RETURN_TYPE, 458 protocol.ElementKind.CLASS_TYPE_ALIAS, declaration.name,
459 isAbstract: true, 459 returnType: _NO_RETURN_TYPE,
460 isDeprecated: isDeprecated); 460 isAbstract: true,
461 isDeprecated: isDeprecated);
462 }
461 } 463 }
462 } 464 }
463 465
464 @override 466 @override
465 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) { 467 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) {
466 if (typesOnly) { 468 if (optype.includeReturnValueSuggestions) {
467 return; 469 bool isDeprecated = _isDeprecated(fieldDecl) || _isDeprecated(varDecl);
468 } 470 TypeName type = fieldDecl.fields.type;
469 bool isDeprecated = _isDeprecated(fieldDecl) || _isDeprecated(varDecl); 471 CompletionSuggestion suggestion = _addSuggestion(
470 TypeName type = fieldDecl.fields.type; 472 varDecl.name, type, isDeprecated, DART_RELEVANCE_LOCAL_FIELD,
471 CompletionSuggestion suggestion = _addSuggestion( 473 classDecl: fieldDecl.parent);
472 varDecl.name, type, isDeprecated, DART_RELEVANCE_LOCAL_FIELD, 474 if (suggestion != null) {
473 classDecl: fieldDecl.parent); 475 suggestion.element = _createElement(
474 if (suggestion != null) { 476 protocol.ElementKind.FIELD, varDecl.name,
475 suggestion.element = _createElement( 477 returnType: type, isDeprecated: isDeprecated);
476 protocol.ElementKind.FIELD, varDecl.name, 478 }
477 returnType: type, isDeprecated: isDeprecated);
478 } 479 }
479 } 480 }
480 481
481 @override 482 @override
482 void declaredFunction(FunctionDeclaration declaration) { 483 void declaredFunction(FunctionDeclaration declaration) {
483 if (typesOnly) { 484 if (optype.includeReturnValueSuggestions ||
484 return; 485 optype.includeVoidReturnSuggestions) {
485 } 486 TypeName returnType = declaration.returnType;
486 TypeName returnType = declaration.returnType; 487 bool isDeprecated = _isDeprecated(declaration);
487 bool isDeprecated = _isDeprecated(declaration); 488 protocol.ElementKind kind;
488 protocol.ElementKind kind; 489 int defaultRelevance = DART_RELEVANCE_DEFAULT;
489 int defaultRelevance = DART_RELEVANCE_DEFAULT; 490 if (declaration.isGetter) {
490 if (declaration.isGetter) { 491 kind = protocol.ElementKind.GETTER;
491 kind = protocol.ElementKind.GETTER; 492 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR;
492 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR; 493 } else if (declaration.isSetter) {
493 } else if (declaration.isSetter) { 494 if (!optype.includeVoidReturnSuggestions) {
494 if (excludeVoidReturn) { 495 return;
495 return; 496 }
497 kind = protocol.ElementKind.SETTER;
498 returnType = _NO_RETURN_TYPE;
499 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR;
500 } else {
501 if (!optype.includeVoidReturnSuggestions && _isVoid(returnType)) {
502 return;
503 }
504 kind = protocol.ElementKind.FUNCTION;
505 defaultRelevance = DART_RELEVANCE_LOCAL_FUNCTION;
496 } 506 }
497 kind = protocol.ElementKind.SETTER; 507 CompletionSuggestion suggestion = _addSuggestion(
498 returnType = _NO_RETURN_TYPE; 508 declaration.name, returnType, isDeprecated, defaultRelevance);
499 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR; 509 if (suggestion != null) {
500 } else { 510 FormalParameterList param = declaration.functionExpression.parameters;
501 if (excludeVoidReturn && _isVoid(returnType)) { 511 suggestion.element = _createElement(kind, declaration.name,
502 return; 512 parameters: param != null ? param.toSource() : null,
503 } 513 returnType: returnType,
504 kind = protocol.ElementKind.FUNCTION; 514 isDeprecated: isDeprecated);
505 defaultRelevance = DART_RELEVANCE_LOCAL_FUNCTION; 515 if (kind == protocol.ElementKind.FUNCTION) {
506 } 516 _addParameterInfo(
507 CompletionSuggestion suggestion = _addSuggestion( 517 suggestion, declaration.functionExpression.parameters);
508 declaration.name, returnType, isDeprecated, defaultRelevance); 518 }
509 if (suggestion != null) {
510 FormalParameterList param = declaration.functionExpression.parameters;
511 suggestion.element = _createElement(kind, declaration.name,
512 parameters: param != null ? param.toSource() : null,
513 returnType: returnType,
514 isDeprecated: isDeprecated);
515 if (kind == protocol.ElementKind.FUNCTION) {
516 _addParameterInfo(
517 suggestion, declaration.functionExpression.parameters);
518 } 519 }
519 } 520 }
520 } 521 }
521 522
522 @override 523 @override
523 void declaredFunctionTypeAlias(FunctionTypeAlias declaration) { 524 void declaredFunctionTypeAlias(FunctionTypeAlias declaration) {
524 bool isDeprecated = _isDeprecated(declaration); 525 if (optype.includeTypeNameSuggestions) {
525 TypeName returnType = declaration.returnType; 526 bool isDeprecated = _isDeprecated(declaration);
526 CompletionSuggestion suggestion = _addSuggestion( 527 TypeName returnType = declaration.returnType;
527 declaration.name, returnType, isDeprecated, DART_RELEVANCE_DEFAULT); 528 CompletionSuggestion suggestion = _addSuggestion(
528 if (suggestion != null) { 529 declaration.name, returnType, isDeprecated, DART_RELEVANCE_DEFAULT);
529 // TODO (danrubel) determine parameters and return type 530 if (suggestion != null) {
530 suggestion.element = _createElement( 531 // TODO (danrubel) determine parameters and return type
531 protocol.ElementKind.FUNCTION_TYPE_ALIAS, declaration.name, 532 suggestion.element = _createElement(
532 returnType: returnType, isAbstract: true, isDeprecated: isDeprecated); 533 protocol.ElementKind.FUNCTION_TYPE_ALIAS, declaration.name,
534 returnType: returnType,
535 isAbstract: true,
536 isDeprecated: isDeprecated);
537 }
533 } 538 }
534 } 539 }
535 540
536 @override 541 @override
537 void declaredLabel(Label label, bool isCaseLabel) { 542 void declaredLabel(Label label, bool isCaseLabel) {
538 // ignored 543 // ignored
539 } 544 }
540 545
541 @override 546 @override
542 void declaredLocalVar(SimpleIdentifier name, TypeName type) { 547 void declaredLocalVar(SimpleIdentifier name, TypeName type) {
543 if (typesOnly) { 548 if (optype.includeReturnValueSuggestions) {
544 return; 549 CompletionSuggestion suggestion =
545 } 550 _addSuggestion(name, type, false, DART_RELEVANCE_LOCAL_VARIABLE);
546 CompletionSuggestion suggestion = 551 if (suggestion != null) {
547 _addSuggestion(name, type, false, DART_RELEVANCE_LOCAL_VARIABLE); 552 suggestion.element = _createElement(
548 if (suggestion != null) { 553 protocol.ElementKind.LOCAL_VARIABLE, name, returnType: type);
549 suggestion.element = _createElement( 554 }
550 protocol.ElementKind.LOCAL_VARIABLE, name, returnType: type);
551 } 555 }
552 } 556 }
553 557
554 @override 558 @override
555 void declaredMethod(MethodDeclaration declaration) { 559 void declaredMethod(MethodDeclaration declaration) {
556 if (typesOnly) { 560 if (optype.includeReturnValueSuggestions ||
557 return; 561 optype.includeVoidReturnSuggestions) {
558 } 562 protocol.ElementKind kind;
559 protocol.ElementKind kind; 563 String parameters;
560 String parameters; 564 TypeName returnType = declaration.returnType;
561 TypeName returnType = declaration.returnType; 565 int defaultRelevance = DART_RELEVANCE_DEFAULT;
562 int defaultRelevance = DART_RELEVANCE_DEFAULT; 566 if (declaration.isGetter) {
563 if (declaration.isGetter) { 567 kind = protocol.ElementKind.GETTER;
564 kind = protocol.ElementKind.GETTER; 568 parameters = null;
565 parameters = null; 569 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR;
566 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR; 570 } else if (declaration.isSetter) {
567 } else if (declaration.isSetter) { 571 if (!optype.includeVoidReturnSuggestions) {
568 if (excludeVoidReturn) { 572 return;
569 return; 573 }
574 kind = protocol.ElementKind.SETTER;
575 returnType = _NO_RETURN_TYPE;
576 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR;
577 } else {
578 if (!optype.includeVoidReturnSuggestions && _isVoid(returnType)) {
579 return;
580 }
581 kind = protocol.ElementKind.METHOD;
582 parameters = declaration.parameters.toSource();
583 defaultRelevance = DART_RELEVANCE_LOCAL_METHOD;
570 } 584 }
571 kind = protocol.ElementKind.SETTER; 585 bool isDeprecated = _isDeprecated(declaration);
572 returnType = _NO_RETURN_TYPE; 586 CompletionSuggestion suggestion = _addSuggestion(
573 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR; 587 declaration.name, returnType, isDeprecated, defaultRelevance,
574 } else { 588 classDecl: declaration.parent);
575 if (excludeVoidReturn && _isVoid(returnType)) { 589 if (suggestion != null) {
576 return; 590 suggestion.element = _createElement(kind, declaration.name,
577 } 591 parameters: parameters,
578 kind = protocol.ElementKind.METHOD; 592 returnType: returnType,
579 parameters = declaration.parameters.toSource(); 593 isAbstract: declaration.isAbstract,
580 defaultRelevance = DART_RELEVANCE_LOCAL_METHOD; 594 isDeprecated: isDeprecated);
581 } 595 if (kind == protocol.ElementKind.METHOD) {
582 bool isDeprecated = _isDeprecated(declaration); 596 _addParameterInfo(suggestion, declaration.parameters);
583 CompletionSuggestion suggestion = _addSuggestion( 597 }
584 declaration.name, returnType, isDeprecated, defaultRelevance,
585 classDecl: declaration.parent);
586 if (suggestion != null) {
587 suggestion.element = _createElement(kind, declaration.name,
588 parameters: parameters,
589 returnType: returnType,
590 isAbstract: declaration.isAbstract,
591 isDeprecated: isDeprecated);
592 if (kind == protocol.ElementKind.METHOD) {
593 _addParameterInfo(suggestion, declaration.parameters);
594 } 598 }
595 } 599 }
596 } 600 }
597 601
598 @override 602 @override
599 void declaredParam(SimpleIdentifier name, TypeName type) { 603 void declaredParam(SimpleIdentifier name, TypeName type) {
600 if (typesOnly) { 604 if (optype.includeReturnValueSuggestions) {
601 return; 605 CompletionSuggestion suggestion =
602 } 606 _addSuggestion(name, type, false, DART_RELEVANCE_PARAMETER);
603 CompletionSuggestion suggestion = 607 if (suggestion != null) {
604 _addSuggestion(name, type, false, DART_RELEVANCE_PARAMETER); 608 suggestion.element = _createElement(
605 if (suggestion != null) { 609 protocol.ElementKind.PARAMETER, name, returnType: type);
606 suggestion.element = _createElement(protocol.ElementKind.PARAMETER, name, 610 }
607 returnType: type);
608 } 611 }
609 } 612 }
610 613
611 @override 614 @override
612 void declaredTopLevelVar( 615 void declaredTopLevelVar(
613 VariableDeclarationList varList, VariableDeclaration varDecl) { 616 VariableDeclarationList varList, VariableDeclaration varDecl) {
614 if (typesOnly) { 617 if (optype.includeReturnValueSuggestions) {
615 return; 618 bool isDeprecated = _isDeprecated(varList) || _isDeprecated(varDecl);
616 } 619 CompletionSuggestion suggestion = _addSuggestion(varDecl.name,
617 bool isDeprecated = _isDeprecated(varList) || _isDeprecated(varDecl); 620 varList.type, isDeprecated, DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE);
618 CompletionSuggestion suggestion = _addSuggestion(varDecl.name, varList.type, 621 if (suggestion != null) {
619 isDeprecated, DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE); 622 suggestion.element = _createElement(
620 if (suggestion != null) { 623 protocol.ElementKind.TOP_LEVEL_VARIABLE, varDecl.name,
621 suggestion.element = _createElement( 624 returnType: varList.type, isDeprecated: isDeprecated);
622 protocol.ElementKind.TOP_LEVEL_VARIABLE, varDecl.name, 625 }
623 returnType: varList.type, isDeprecated: isDeprecated);
624 } 626 }
625 } 627 }
626 628
627 void _addParameterInfo( 629 void _addParameterInfo(
628 CompletionSuggestion suggestion, FormalParameterList parameters) { 630 CompletionSuggestion suggestion, FormalParameterList parameters) {
629 var paramList = parameters.parameters; 631 var paramList = parameters.parameters;
630 suggestion.parameterNames = paramList 632 suggestion.parameterNames = paramList
631 .map((FormalParameter param) => param.identifier.name) 633 .map((FormalParameter param) => param.identifier.name)
632 .toList(); 634 .toList();
633 suggestion.parameterTypes = paramList.map((FormalParameter param) { 635 suggestion.parameterTypes = paramList.map((FormalParameter param) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 bool _isVoid(TypeName returnType) { 691 bool _isVoid(TypeName returnType) {
690 if (returnType != null) { 692 if (returnType != null) {
691 Identifier id = returnType.name; 693 Identifier id = returnType.name;
692 if (id != null && id.name == 'void') { 694 if (id != null && id.name == 'void') {
693 return true; 695 return true;
694 } 696 }
695 } 697 }
696 return false; 698 return false;
697 } 699 }
698 } 700 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698