@@ -278,6 +278,29 @@ void getSwiftDocKeyword(const Decl* D, CommandWordsPairs &Words) {
278
278
} // end namespace markup
279
279
} // end namespace swift
280
280
281
+ static bool shouldHideDeclFromCompletionResults (const ValueDecl *D) {
282
+ // Hide private stdlib declarations.
283
+ if (D->isPrivateStdlibDecl (/* whitelistProtocols*/ false ) ||
284
+ // ShowInInterfaceAttr is for decls to show in interface as exception but
285
+ // they are not intended to be used directly.
286
+ D->getAttrs ().hasAttribute <ShowInInterfaceAttr>())
287
+ return true ;
288
+
289
+ if (AvailableAttr::isUnavailable (D))
290
+ return true ;
291
+
292
+ if (auto *ClangD = D->getClangDecl ()) {
293
+ if (ClangD->hasAttr <clang::SwiftPrivateAttr>())
294
+ return true ;
295
+ }
296
+
297
+ // Hide editor placeholders.
298
+ if (D->getName ().isEditorPlaceholder ())
299
+ return true ;
300
+
301
+ return false ;
302
+ }
303
+
281
304
typedef llvm::function_ref<bool (ValueDecl*, DeclVisibilityKind)> DeclFilter;
282
305
DeclFilter DefaultFilter = [] (ValueDecl* VD, DeclVisibilityKind Kind) {return true ;};
283
306
DeclFilter KeyPathFilter = [](ValueDecl* decl, DeclVisibilityKind) -> bool {
@@ -1938,7 +1961,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
1938
1961
if (!VD->hasName () ||
1939
1962
!VD->isUserAccessible () ||
1940
1963
(VD->hasAccessibility () && !VD->isAccessibleFrom (CurrDeclContext)) ||
1941
- AvailableAttr::isUnavailable (VD))
1964
+ shouldHideDeclFromCompletionResults (VD))
1942
1965
return ;
1943
1966
1944
1967
StringRef Name = VD->getName ().get ();
@@ -2430,8 +2453,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2430
2453
if (CurrDeclContext->lookupQualified (type, Ctx.Id_init , NL_QualifiedDefault,
2431
2454
TypeResolver.get (), initializers)) {
2432
2455
for (auto *init : initializers) {
2433
- if (init->isPrivateStdlibDecl (/* whitelistProtocols*/ false ) ||
2434
- AvailableAttr::isUnavailable (init))
2456
+ if (shouldHideDeclFromCompletionResults (init))
2435
2457
continue ;
2436
2458
addConstructorCall (cast<ConstructorDecl>(init), Reason, None, name);
2437
2459
}
@@ -2526,7 +2548,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2526
2548
bool HasTypeContext) {
2527
2549
if (!EED->hasName () ||
2528
2550
(EED->hasAccessibility () && !EED->isAccessibleFrom (CurrDeclContext)) ||
2529
- AvailableAttr::isUnavailable (EED))
2551
+ shouldHideDeclFromCompletionResults (EED))
2530
2552
return ;
2531
2553
CommandWordsPairs Pairs;
2532
2554
CodeCompletionResultBuilder Builder (
@@ -2628,15 +2650,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2628
2650
2629
2651
// Implement swift::VisibleDeclConsumer.
2630
2652
void foundDecl (ValueDecl *D, DeclVisibilityKind Reason) override {
2631
- // Hide private stdlib declarations.
2632
- if (D->isPrivateStdlibDecl (/* whitelistProtocols*/ false ) ||
2633
- D->getAttrs ().hasAttribute <ShowInInterfaceAttr>())
2634
- return ;
2635
- if (AvailableAttr::isUnavailable (D))
2636
- return ;
2637
-
2638
- // Hide editor placeholders.
2639
- if (D->getName ().isEditorPlaceholder ())
2653
+ if (shouldHideDeclFromCompletionResults (D))
2640
2654
return ;
2641
2655
2642
2656
if (IsKeyPathExpr && !KeyPathFilter (D, Reason))
@@ -4008,7 +4022,7 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
4008
4022
return ;
4009
4023
}
4010
4024
4011
- if (AvailableAttr::isUnavailable (D))
4025
+ if (shouldHideDeclFromCompletionResults (D))
4012
4026
return ;
4013
4027
4014
4028
if (D->getAttrs ().hasAttribute <FinalAttr>())
0 commit comments