mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CodeComplete] In where clauses, suggest Self and the current type
Fixes rdar://70058225
This commit is contained in:
@@ -4610,7 +4610,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void getGenericRequirementCompletions(DeclContext *DC) {
|
||||
void getGenericRequirementCompletions(DeclContext *DC,
|
||||
SourceLoc CodeCompletionLoc) {
|
||||
auto genericSig = DC->getGenericSignatureOfContext();
|
||||
if (!genericSig)
|
||||
return;
|
||||
@@ -4637,6 +4638,18 @@ public:
|
||||
CurrDeclContext, IncludeInstanceMembers,
|
||||
/*includeDerivedRequirements*/false,
|
||||
/*includeProtocolExtensionMembers*/true);
|
||||
// We not only allow referencing nested types/typealiases directly, but also
|
||||
// qualified by the current type. Thus also suggest current self type so the
|
||||
// user can do a memberwise lookup on it.
|
||||
if (auto SelfType = typeContext->getSelfNominalTypeDecl()) {
|
||||
addNominalTypeRef(SelfType, DeclVisibilityKind::LocalVariable,
|
||||
DynamicLookupInfo());
|
||||
}
|
||||
|
||||
// Self is also valid in all cases in which it can be used in function
|
||||
// bodies. Suggest it if applicable.
|
||||
getSelfTypeCompletionInDeclContext(CodeCompletionLoc,
|
||||
/*isForResultType=*/false);
|
||||
}
|
||||
|
||||
static bool canUseAttributeOnDecl(DeclAttrKind DAK, bool IsInSil,
|
||||
@@ -4758,6 +4771,9 @@ public:
|
||||
getAttributeDeclParamCompletions(DAK_Available, 0);
|
||||
}
|
||||
|
||||
/// \p Loc is the location of the code completin token.
|
||||
/// \p isForDeclResult determines if were are spelling out the result type
|
||||
/// of a declaration.
|
||||
void getSelfTypeCompletionInDeclContext(SourceLoc Loc, bool isForDeclResult) {
|
||||
const DeclContext *typeDC = CurrDeclContext->getInnermostTypeContext();
|
||||
if (!typeDC)
|
||||
@@ -6925,9 +6941,11 @@ void CodeCompletionCallbacksImpl::doneParsing() {
|
||||
break;
|
||||
}
|
||||
|
||||
case CompletionKind::GenericRequirement:
|
||||
Lookup.getGenericRequirementCompletions(CurDeclContext);
|
||||
case CompletionKind::GenericRequirement: {
|
||||
auto Loc = Context.SourceMgr.getCodeCompletionLoc();
|
||||
Lookup.getGenericRequirementCompletions(CurDeclContext, Loc);
|
||||
break;
|
||||
}
|
||||
case CompletionKind::PrecedenceGroup:
|
||||
Lookup.getPrecedenceGroupCompletions(SyntxKind);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user