Skip to content

Commit 58d60e2

Browse files
committed
[Code completion] Delete redundant code handling declarations.
A significant chunk of the handling for LookupKind::ValueExpr was duplicated in the handling for the ValueInDeclContext and ImportFromModule cases. Use a fall through to unify the code paths here.
1 parent 0a26e33 commit 58d60e2

File tree

1 file changed

+8
-60
lines changed

1 file changed

+8
-60
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 8 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,6 +2909,10 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
29092909
if (HaveLParen)
29102910
return;
29112911

2912+
LLVM_FALLTHROUGH;
2913+
2914+
case LookupKind::ValueInDeclContext:
2915+
case LookupKind::ImportFromModule:
29122916
if (auto *VD = dyn_cast<VarDecl>(D)) {
29132917
addVarDeclRef(VD, Reason);
29142918
return;
@@ -2943,7 +2947,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
29432947

29442948
if (auto *TAD = dyn_cast<TypeAliasDecl>(D)) {
29452949
addTypeAliasRef(TAD, Reason);
2946-
auto type = TAD->mapTypeIntoContext(TAD->getUnderlyingTypeLoc().getType());
2950+
auto type = TAD->mapTypeIntoContext(TAD->getDeclaredInterfaceType());
29472951
if (type->mayHaveMembers())
29482952
addConstructorCallsForType(type, TAD->getName(), Reason);
29492953
return;
@@ -2964,73 +2968,17 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
29642968

29652969
if (auto *EED = dyn_cast<EnumElementDecl>(D)) {
29662970
addEnumElementRef(EED, Reason, /*HasTypeContext=*/false);
2971+
return;
29672972
}
29682973

29692974
// Swift key path allows .[0]
29702975
if (shouldAddSubscriptCall()) {
29712976
if (auto *SD = dyn_cast<SubscriptDecl>(D)) {
2972-
if (ExprType->is<AnyMetatypeType>())
2973-
return;
2974-
addSubscriptCall(SD, Reason);
2975-
}
2976-
}
2977-
return;
2978-
2979-
case LookupKind::ValueInDeclContext:
2980-
case LookupKind::ImportFromModule:
2981-
if (auto *VD = dyn_cast<VarDecl>(D)) {
2982-
addVarDeclRef(VD, Reason);
2983-
return;
2984-
}
2985-
2986-
if (auto *FD = dyn_cast<FuncDecl>(D)) {
2987-
// We cannot call operators with a postfix parenthesis syntax.
2988-
if (FD->isBinaryOperator() || FD->isUnaryOperator())
2989-
return;
2990-
2991-
// We cannot call accessors. We use VarDecls and SubscriptDecls to
2992-
// produce completions that refer to getters and setters.
2993-
if (isa<AccessorDecl>(FD))
2994-
return;
2995-
2996-
// Do we want compound function names here?
2997-
if (shouldUseFunctionReference(FD)) {
2998-
addCompoundFunctionName(FD, Reason);
2977+
if (ExprType && !ExprType->is<AnyMetatypeType>())
2978+
addSubscriptCall(SD, Reason);
29992979
return;
30002980
}
3001-
3002-
addMethodCall(FD, Reason);
3003-
return;
3004-
}
3005-
3006-
if (auto *NTD = dyn_cast<NominalTypeDecl>(D)) {
3007-
addNominalTypeRef(NTD, Reason);
3008-
addConstructorCallsForType(NTD->getDeclaredInterfaceType(),
3009-
NTD->getName(), Reason);
3010-
return;
30112981
}
3012-
3013-
if (auto *TAD = dyn_cast<TypeAliasDecl>(D)) {
3014-
addTypeAliasRef(TAD, Reason);
3015-
auto type = TAD->mapTypeIntoContext(TAD->getDeclaredInterfaceType());
3016-
if (type->mayHaveMembers())
3017-
addConstructorCallsForType(type, TAD->getName(), Reason);
3018-
return;
3019-
}
3020-
3021-
if (auto *GP = dyn_cast<GenericTypeParamDecl>(D)) {
3022-
addGenericTypeParamRef(GP, Reason);
3023-
for (auto *protocol : GP->getConformingProtocols())
3024-
addConstructorCallsForType(protocol->getDeclaredInterfaceType(),
3025-
GP->getName(), Reason);
3026-
return;
3027-
}
3028-
3029-
if (auto *AT = dyn_cast<AssociatedTypeDecl>(D)) {
3030-
addAssociatedTypeRef(AT, Reason);
3031-
return;
3032-
}
3033-
30342982
return;
30352983

30362984
case LookupKind::EnumElement:

0 commit comments

Comments
 (0)