Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 4cdbc99

Browse files
committed
Set completion priority of destructors and operators to CCP_Unlikely.
Summary: It will move destructors and operators to the end of completion list. Destructors and operators are currently very high on the completion list, as they have the same priority as member functions. However, they are clearly not something users usually choose in completion lists. Reviewers: arphaman, erikjv, bkramer, krasimir Reviewed By: arphaman Subscribers: eraman, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D38081 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314019 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 44655e1 commit 4cdbc99

5 files changed

+30
-19
lines changed

Diff for: lib/Sema/SemaCodeComplete.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// This file defines the code-completion semantic actions.
1111
//
1212
//===----------------------------------------------------------------------===//
13-
#include "clang/Sema/SemaInternal.h"
13+
#include "clang/AST/DeclCXX.h"
1414
#include "clang/AST/DeclObjC.h"
1515
#include "clang/AST/ExprCXX.h"
1616
#include "clang/AST/ExprObjC.h"
@@ -23,6 +23,7 @@
2323
#include "clang/Sema/Overload.h"
2424
#include "clang/Sema/Scope.h"
2525
#include "clang/Sema/ScopeInfo.h"
26+
#include "clang/Sema/SemaInternal.h"
2627
#include "llvm/ADT/DenseSet.h"
2728
#include "llvm/ADT/SmallBitVector.h"
2829
#include "llvm/ADT/SmallPtrSet.h"
@@ -741,8 +742,18 @@ unsigned ResultBuilder::getBasePriority(const NamedDecl *ND) {
741742
}
742743

743744
const DeclContext *DC = ND->getDeclContext()->getRedeclContext();
744-
if (DC->isRecord() || isa<ObjCContainerDecl>(DC))
745+
if (DC->isRecord() || isa<ObjCContainerDecl>(DC)) {
746+
// Explicit destructor calls are very rare.
747+
if (isa<CXXDestructorDecl>(ND))
748+
return CCP_Unlikely;
749+
// Explicit operator and conversion function calls are also very rare.
750+
auto DeclNameKind = ND->getDeclName().getNameKind();
751+
if (DeclNameKind == DeclarationName::CXXOperatorName ||
752+
DeclNameKind == DeclarationName::CXXLiteralOperatorName ||
753+
DeclNameKind == DeclarationName::CXXConversionFunctionName)
754+
return CCP_Unlikely;
745755
return CCP_MemberDeclaration;
756+
}
746757

747758
// Content-based decisions.
748759
if (isa<EnumConstantDecl>(ND))

Diff for: test/Index/complete-access-checks.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,22 @@ void Y::doSomething() {
4141
// CHECK-SUPER-ACCESS: FieldDecl:{ResultType int}{Informative X::}{TypedText member1} (37)
4242
// CHECK-SUPER-ACCESS: FieldDecl:{ResultType int}{Informative X::}{TypedText member2} (37) (inaccessible)
4343
// CHECK-SUPER-ACCESS: FieldDecl:{ResultType int}{Informative X::}{TypedText member3} (37) (inaccessible)
44-
// CHECK-SUPER-ACCESS: CXXMethod:{ResultType Y &}{TypedText operator=}{LeftParen (}{Placeholder const Y &}{RightParen )} (34)
45-
// CHECK-SUPER-ACCESS: CXXMethod:{ResultType X &}{Text X::}{TypedText operator=}{LeftParen (}{Placeholder const X &}{RightParen )} (36)
44+
// CHECK-SUPER-ACCESS: CXXMethod:{ResultType Y &}{TypedText operator=}{LeftParen (}{Placeholder const Y &}{RightParen )} (79)
45+
// CHECK-SUPER-ACCESS: CXXMethod:{ResultType X &}{Text X::}{TypedText operator=}{LeftParen (}{Placeholder const X &}{RightParen )} (81)
4646
// CHECK-SUPER-ACCESS: StructDecl:{TypedText X}{Text ::} (77)
4747
// CHECK-SUPER-ACCESS: StructDecl:{TypedText Y}{Text ::} (75)
48-
// CHECK-SUPER-ACCESS: CXXDestructor:{ResultType void}{Informative X::}{TypedText ~X}{LeftParen (}{RightParen )} (36)
49-
// CHECK-SUPER-ACCESS: CXXDestructor:{ResultType void}{TypedText ~Y}{LeftParen (}{RightParen )} (34)
48+
// CHECK-SUPER-ACCESS: CXXDestructor:{ResultType void}{Informative X::}{TypedText ~X}{LeftParen (}{RightParen )} (81)
49+
// CHECK-SUPER-ACCESS: CXXDestructor:{ResultType void}{TypedText ~Y}{LeftParen (}{RightParen )} (79)
5050

5151
// CHECK-ACCESS: CXXMethod:{ResultType void}{TypedText func1}{LeftParen (}{RightParen )} (34)
5252
// CHECK-ACCESS: CXXMethod:{ResultType void}{TypedText func2}{LeftParen (}{RightParen )} (34) (inaccessible)
5353
// CHECK-ACCESS: CXXMethod:{ResultType void}{TypedText func3}{LeftParen (}{RightParen )} (34) (inaccessible)
5454
// CHECK-ACCESS: FieldDecl:{ResultType int}{TypedText member1} (35)
5555
// CHECK-ACCESS: FieldDecl:{ResultType int}{TypedText member2} (35) (inaccessible)
5656
// CHECK-ACCESS: FieldDecl:{ResultType int}{TypedText member3} (35) (inaccessible)
57-
// CHECK-ACCESS: CXXMethod:{ResultType Z &}{TypedText operator=}{LeftParen (}{Placeholder const Z &}{RightParen )} (34)
57+
// CHECK-ACCESS: CXXMethod:{ResultType Z &}{TypedText operator=}{LeftParen (}{Placeholder const Z &}{RightParen )} (79)
5858
// CHECK-ACCESS: ClassDecl:{TypedText Z}{Text ::} (75)
59-
// CHECK-ACCESS: CXXDestructor:{ResultType void}{TypedText ~Z}{LeftParen (}{RightParen )} (34)
59+
// CHECK-ACCESS: CXXDestructor:{ResultType void}{TypedText ~Z}{LeftParen (}{RightParen )} (79)
6060

6161
class P {
6262
protected:
@@ -76,14 +76,14 @@ void f(P x, Q y) {
7676
}
7777

7878
// CHECK-USING-INACCESSIBLE: FieldDecl:{ResultType int}{TypedText member} (35) (inaccessible)
79-
// CHECK-USING-INACCESSIBLE: CXXMethod:{ResultType P &}{TypedText operator=}{LeftParen (}{Placeholder const P &}{RightParen )} (34)
79+
// CHECK-USING-INACCESSIBLE: CXXMethod:{ResultType P &}{TypedText operator=}{LeftParen (}{Placeholder const P &}{RightParen )} (79)
8080
// CHECK-USING-INACCESSIBLE: ClassDecl:{TypedText P}{Text ::} (75)
81-
// CHECK-USING-INACCESSIBLE: CXXDestructor:{ResultType void}{TypedText ~P}{LeftParen (}{RightParen )} (34)
81+
// CHECK-USING-INACCESSIBLE: CXXDestructor:{ResultType void}{TypedText ~P}{LeftParen (}{RightParen )} (79)
8282

8383
// CHECK-USING-ACCESSIBLE: FieldDecl:{ResultType int}{TypedText member} (35)
84-
// CHECK-USING-ACCESSIBLE: CXXMethod:{ResultType Q &}{TypedText operator=}{LeftParen (}{Placeholder const Q &}{RightParen )} (34)
85-
// CHECK-USING-ACCESSIBLE: CXXMethod:{ResultType P &}{Text P::}{TypedText operator=}{LeftParen (}{Placeholder const P &}{RightParen )} (36)
84+
// CHECK-USING-ACCESSIBLE: CXXMethod:{ResultType Q &}{TypedText operator=}{LeftParen (}{Placeholder const Q &}{RightParen )} (79)
85+
// CHECK-USING-ACCESSIBLE: CXXMethod:{ResultType P &}{Text P::}{TypedText operator=}{LeftParen (}{Placeholder const P &}{RightParen )} (81)
8686
// CHECK-USING-ACCESSIBLE: ClassDecl:{TypedText P}{Text ::} (77)
8787
// CHECK-USING-ACCESSIBLE: ClassDecl:{TypedText Q}{Text ::} (75)
88-
// CHECK-USING-ACCESSIBLE: CXXDestructor:{ResultType void}{Informative P::}{TypedText ~P}{LeftParen (}{RightParen )} (36)
89-
// CHECK-USING-ACCESSIBLE: CXXDestructor:{ResultType void}{TypedText ~Q}{LeftParen (}{RightParen )} (34)
88+
// CHECK-USING-ACCESSIBLE: CXXDestructor:{ResultType void}{Informative P::}{TypedText ~P}{LeftParen (}{RightParen )} (81)
89+
// CHECK-USING-ACCESSIBLE: CXXDestructor:{ResultType void}{TypedText ~Q}{LeftParen (}{RightParen )} (79)

Diff for: test/Index/complete-cxx-inline-methods.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ class OtherClass : public MyCls {
2525

2626
// RUN: c-index-test -code-completion-at=%s:4:9 -std=c++98 %s | FileCheck %s
2727
// RUN: c-index-test -code-completion-at=%s:13:7 -std=c++98 %s | FileCheck %s
28-
// CHECK: CXXMethod:{ResultType MyCls::Vec &}{TypedText operator=}{LeftParen (}{Placeholder const MyCls::Vec &}{RightParen )} (34)
28+
// CHECK: CXXMethod:{ResultType MyCls::Vec &}{TypedText operator=}{LeftParen (}{Placeholder const MyCls::Vec &}{RightParen )} (79)
2929
// CHECK-NEXT: StructDecl:{TypedText Vec}{Text ::} (75)
3030
// CHECK-NEXT: FieldDecl:{ResultType int}{TypedText x} (35)
3131
// CHECK-NEXT: FieldDecl:{ResultType int}{TypedText y} (35)
32-
// CHECK-NEXT: CXXDestructor:{ResultType void}{TypedText ~Vec}{LeftParen (}{RightParen )} (34)
32+
// CHECK-NEXT: CXXDestructor:{ResultType void}{TypedText ~Vec}{LeftParen (}{RightParen )} (79)
3333
// CHECK-NEXT: Completion contexts:
3434
// CHECK-NEXT: Dot member access
3535
// CHECK-NEXT: Container Kind: StructDecl

Diff for: test/Index/complete-qualified.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ void foo()
1717
// CHECK-CC1: FieldDecl:{ResultType C<Foo, class Bar>}{TypedText c} (35)
1818
// CHECK-CC1: ClassDecl:{TypedText Foo} (35)
1919
// CHECK-CC1: CXXMethod:{ResultType Foo &}{TypedText operator=}{LeftParen (}{Placeholder const Foo &}{RightParen )}
20-
// CHECK-CC1: CXXDestructor:{ResultType void}{TypedText ~Foo}{LeftParen (}{RightParen )} (35)
20+
// CHECK-CC1: CXXDestructor:{ResultType void}{TypedText ~Foo}{LeftParen (}{RightParen )} (80)

Diff for: test/Index/complete-with-annotations.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void X::doSomething() {
1717
// CHECK: FieldDecl:{ResultType int}{TypedText field} (35) ("three", "two", "one")
1818
// CHECK: CXXMethod:{ResultType void}{TypedText func2}{LeftParen (}{RightParen )} (34) ("some annotation")
1919
// CHECK: FieldDecl:{ResultType int}{TypedText member2} (35) ("another annotation", "some annotation")
20-
// CHECK: CXXMethod:{ResultType X &}{TypedText operator=}{LeftParen (}{Placeholder const X &}{RightParen )} (34)
20+
// CHECK: CXXMethod:{ResultType X &}{TypedText operator=}{LeftParen (}{Placeholder const X &}{RightParen )} (79)
2121
// CHECK: ClassDecl:{TypedText X}{Text ::} (75)
22-
// CHECK: CXXDestructor:{ResultType void}{TypedText ~X}{LeftParen (}{RightParen )} (34)
22+
// CHECK: CXXDestructor:{ResultType void}{TypedText ~X}{LeftParen (}{RightParen )} (79)
2323

0 commit comments

Comments
 (0)