Skip to content

Commit d17bb78

Browse files
committed
[AST] Add shouldHideFromEditor() method
This replaces shouldHideDeclFromCompletionResults() in IDE.
1 parent 867c28e commit d17bb78

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

include/swift/AST/Decl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,6 +2412,10 @@ class ValueDecl : public Decl {
24122412

24132413
bool isUsableFromInline() const;
24142414

2415+
/// Returns \c true if this declaration is *not* intended to be used directly
2416+
/// by application developers despite of the visibility.
2417+
bool shouldHideFromEditor() const;
2418+
24152419
bool hasAccess() const {
24162420
return TypeAndAccess.getInt().hasValue();
24172421
}

lib/AST/Decl.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,6 +2550,34 @@ bool ValueDecl::isUsableFromInline() const {
25502550
return false;
25512551
}
25522552

2553+
/// Returns \c true if this declaration is *not* intended to be used directly
2554+
/// by application developers despite of the visibility.
2555+
bool ValueDecl::shouldHideFromEditor() const {
2556+
// Hide private stdlib declarations.
2557+
if (isPrivateStdlibDecl(/*treatNonBuiltinProtocolsAsPublic*/ false) ||
2558+
// ShowInInterfaceAttr is for decls to show in interface as exception but
2559+
// they are not intended to be used directly.
2560+
getAttrs().hasAttribute<ShowInInterfaceAttr>())
2561+
return true;
2562+
2563+
if (AvailableAttr::isUnavailable(this))
2564+
return true;
2565+
2566+
if (auto *ClangD = getClangDecl()) {
2567+
if (ClangD->hasAttr<clang::SwiftPrivateAttr>())
2568+
return true;
2569+
}
2570+
2571+
if (!isUserAccessible())
2572+
return true;
2573+
2574+
// Hide editor placeholders.
2575+
if (getBaseName().isEditorPlaceholder())
2576+
return true;
2577+
2578+
return false;
2579+
}
2580+
25532581
/// Return the access level of an internal or public declaration
25542582
/// that's been testably imported.
25552583
static AccessLevel getTestableOrPrivateImportsAccess(const ValueDecl *decl) {

lib/IDE/CodeCompletion.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,7 +2116,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
21162116
void addVarDeclRef(const VarDecl *VD, DeclVisibilityKind Reason) {
21172117
if (!VD->hasName() ||
21182118
!VD->isAccessibleFrom(CurrDeclContext) ||
2119-
shouldHideDeclFromCompletionResults(VD))
2119+
VD->shouldHideFromEditor())
21202120
return;
21212121

21222122
StringRef Name = VD->getName().get();
@@ -2637,7 +2637,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
26372637
NL_QualifiedDefault,
26382638
TypeResolver, initializers)) {
26392639
for (auto *init : initializers) {
2640-
if (shouldHideDeclFromCompletionResults(init))
2640+
if (init->shouldHideFromEditor())
26412641
continue;
26422642
if (IsUnresolvedMember &&
26432643
cast<ConstructorDecl>(init)->getFailability() == OTK_Optional) {
@@ -2782,7 +2782,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
27822782
bool HasTypeContext) {
27832783
if (!EED->hasName() ||
27842784
!EED->isAccessibleFrom(CurrDeclContext) ||
2785-
shouldHideDeclFromCompletionResults(EED))
2785+
EED->shouldHideFromEditor())
27862786
return;
27872787

27882788
CommandWordsPairs Pairs;
@@ -2895,7 +2895,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
28952895

28962896
// Implement swift::VisibleDeclConsumer.
28972897
void foundDecl(ValueDecl *D, DeclVisibilityKind Reason) override {
2898-
if (shouldHideDeclFromCompletionResults(D))
2898+
if (D->shouldHideFromEditor())
28992899
return;
29002900

29012901
if (IsKeyPathExpr && !KeyPathFilter(D, Reason))
@@ -4152,7 +4152,7 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
41524152
if (Reason == DeclVisibilityKind::MemberOfCurrentNominal)
41534153
return;
41544154

4155-
if (shouldHideDeclFromCompletionResults(D))
4155+
if (D->shouldHideFromEditor())
41564156
return;
41574157

41584158
if (D->getAttrs().hasAttribute<FinalAttr>())
@@ -4993,7 +4993,7 @@ void collectPossibleCalleesByQualifiedLookup(
49934993

49944994
for (auto *VD : decls) {
49954995
if ((!isa<AbstractFunctionDecl>(VD) && !isa<SubscriptDecl>(VD)) ||
4996-
shouldHideDeclFromCompletionResults(VD))
4996+
VD->shouldHideFromEditor())
49974997
continue;
49984998
resolver->resolveDeclSignature(VD);
49994999
if (!VD->hasInterfaceType())

0 commit comments

Comments
 (0)