forked from OSchip/llvm-project
When code-completing inside an Objective-C method, give a slight
priority boost to methods with the same selector. llvm-svn: 112268
This commit is contained in:
parent
2706567c5c
commit
c2cb2e23bc
|
@ -69,7 +69,11 @@ enum {
|
|||
CCD_VoidMatch = -5,
|
||||
/// \brief The result is a C++ non-static member function whose qualifiers
|
||||
/// exactly match the object type on which the member function can be called.
|
||||
CCD_ObjectQualifierMatch = -1
|
||||
CCD_ObjectQualifierMatch = -1,
|
||||
/// \brief The selector of the given message exactly matches the selector
|
||||
/// of the current method, which might imply that some kind of delegation
|
||||
/// is occurring.
|
||||
CCD_SelectorMatch = -3
|
||||
};
|
||||
|
||||
/// \brief Priority value factors by which we will divide or multiply the
|
||||
|
|
|
@ -143,6 +143,9 @@ namespace {
|
|||
/// \brief Whether the \p ObjectTypeQualifiers field is active.
|
||||
bool HasObjectTypeQualifiers;
|
||||
|
||||
/// \brief The selector that we prefer.
|
||||
Selector PreferredSelector;
|
||||
|
||||
void AdjustResultPriorityForPreferredType(Result &R);
|
||||
|
||||
public:
|
||||
|
@ -187,6 +190,15 @@ namespace {
|
|||
HasObjectTypeQualifiers = true;
|
||||
}
|
||||
|
||||
/// \brief Set the preferred selector.
|
||||
///
|
||||
/// When an Objective-C method declaration result is added, and that
|
||||
/// method's selector matches this preferred selector, we give that method
|
||||
/// a slight priority boost.
|
||||
void setPreferredSelector(Selector Sel) {
|
||||
PreferredSelector = Sel;
|
||||
}
|
||||
|
||||
/// \brief Specify whether nested-name-specifiers are allowed.
|
||||
void allowNestedNameSpecifiers(bool Allow = true) {
|
||||
AllowNestedNameSpecifiers = Allow;
|
||||
|
@ -707,6 +719,13 @@ void ResultBuilder::MaybeAddResult(Result R, DeclContext *CurContext) {
|
|||
if (!AllDeclsFound.insert(CanonDecl))
|
||||
return;
|
||||
|
||||
// If this is an Objective-C method declaration whose selector matches our
|
||||
// preferred selector, give it a priority boost.
|
||||
if (!PreferredSelector.isNull())
|
||||
if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(R.Declaration))
|
||||
if (PreferredSelector == Method->getSelector())
|
||||
R.Priority += CCD_SelectorMatch;
|
||||
|
||||
// If the filter is for nested-name-specifiers, then this result starts a
|
||||
// nested-name-specifier.
|
||||
if (AsNestedNameSpecifier) {
|
||||
|
@ -787,6 +806,13 @@ void ResultBuilder::AddResult(Result R, DeclContext *CurContext,
|
|||
if (InBaseClass)
|
||||
R.Priority += CCD_InBaseClass;
|
||||
|
||||
// If this is an Objective-C method declaration whose selector matches our
|
||||
// preferred selector, give it a priority boost.
|
||||
if (!PreferredSelector.isNull())
|
||||
if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(R.Declaration))
|
||||
if (PreferredSelector == Method->getSelector())
|
||||
R.Priority += CCD_SelectorMatch;
|
||||
|
||||
if (!PreferredType.isNull())
|
||||
AdjustResultPriorityForPreferredType(R);
|
||||
|
||||
|
@ -3996,6 +4022,11 @@ void Sema::CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver,
|
|||
Results.Ignore(SuperMethod);
|
||||
}
|
||||
|
||||
// If we're inside an Objective-C method definition, prefer its selector to
|
||||
// others.
|
||||
if (ObjCMethodDecl *CurMethod = getCurMethodDecl())
|
||||
Results.setPreferredSelector(CurMethod->getSelector());
|
||||
|
||||
if (CDecl)
|
||||
AddObjCMethods(CDecl, false, MK_Any, SelIdents, NumSelIdents, CurContext,
|
||||
Results);
|
||||
|
@ -4071,6 +4102,11 @@ void Sema::CodeCompleteObjCInstanceMessage(Scope *S, ExprTy *Receiver,
|
|||
Results.Ignore(SuperMethod);
|
||||
}
|
||||
|
||||
// If we're inside an Objective-C method definition, prefer its selector to
|
||||
// others.
|
||||
if (ObjCMethodDecl *CurMethod = getCurMethodDecl())
|
||||
Results.setPreferredSelector(CurMethod->getSelector());
|
||||
|
||||
// If we're messaging an expression with type "id" or "Class", check
|
||||
// whether we know something special about the receiver that allows
|
||||
// us to assume a more-specific receiver type.
|
||||
|
|
|
@ -26,6 +26,11 @@ void message_id(B *b) {
|
|||
[[b superclass] B_method];
|
||||
}
|
||||
|
||||
@implementation Unrelated
|
||||
+ (id)alloc {
|
||||
return [A alloc];
|
||||
}
|
||||
@end
|
||||
// RUN: c-index-test -code-completion-at=%s:24:14 %s | FileCheck -check-prefix=CHECK-CC1 %s
|
||||
// CHECK-CC1: ObjCInstanceMethodDecl:{ResultType id}{TypedText autorelease}
|
||||
// CHECK-CC1-NOT: B_method
|
||||
|
@ -40,3 +45,10 @@ void message_id(B *b) {
|
|||
// CHECK-CC3: ObjCInstanceMethodDecl:{ResultType id}{TypedText retain}
|
||||
|
||||
|
||||
// RUN: c-index-test -code-completion-at=%s:31:13 %s | FileCheck -check-prefix=CHECK-SELECTOR-PREF %s
|
||||
// CHECK-SELECTOR-PREF: ObjCClassMethodDecl:{ResultType id}{TypedText alloc} (17)
|
||||
// CHECK-SELECTOR-PREF: ObjCClassMethodDecl:{ResultType Class}{TypedText class} (20)
|
||||
// CHECK-SELECTOR-PREF: ObjCClassMethodDecl:{ResultType id}{TypedText init} (20)
|
||||
// CHECK-SELECTOR-PREF: ObjCClassMethodDecl:{ResultType id}{TypedText new} (20)
|
||||
// CHECK-SELECTOR-PREF: ObjCClassMethodDecl:{ResultType Class}{TypedText superclass} (20)
|
||||
|
||||
|
|
Loading…
Reference in New Issue