Skip to content

Commit 8f765d0

Browse files
authored
Merge pull request #17179 from CodaFi/just-out-of-reach
[4.2][CodeCompletion] Remove UserInaccessible DeclKeywords
2 parents 5add051 + 4924322 commit 8f765d0

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

include/swift/AST/Attr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ DECL_ATTR(_specialize, Specialize,
207207
SIMPLE_DECL_ATTR(objcMembers, ObjCMembers, OnClass, 34)
208208

209209
CONTEXTUAL_SIMPLE_DECL_ATTR(__consuming, Consuming, DeclModifier |
210-
OnFunc |
210+
OnFunc | UserInaccessible |
211211
NotSerialized, 40)
212212

213213
CONTEXTUAL_SIMPLE_DECL_ATTR(mutating, Mutating, DeclModifier |

lib/IDE/CodeCompletion.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4849,30 +4849,35 @@ static bool isClangSubModule(ModuleDecl *TheModule) {
48494849
}
48504850

48514851
static void addDeclKeywords(CodeCompletionResultSink &Sink) {
4852-
auto AddKeyword = [&](StringRef Name, CodeCompletionKeywordKind Kind) {
4852+
auto AddKeyword = [&](StringRef Name, CodeCompletionKeywordKind Kind,
4853+
Optional<DeclAttrKind> DAK) {
48534854
if (Name == "let" || Name == "var") {
48544855
// Treat keywords that could be the start of a pattern specially.
48554856
return;
48564857
}
4858+
4859+
// Remove user inaccessible keywords.
4860+
if (DAK.hasValue() && DeclAttribute::isUserInaccessible(*DAK)) return;
4861+
48574862
CodeCompletionResultBuilder Builder(
48584863
Sink, CodeCompletionResult::ResultKind::Keyword,
48594864
SemanticContextKind::None, {});
48604865
Builder.setKeywordKind(Kind);
48614866
Builder.addTextChunk(Name);
48624867
};
48634868

4864-
#define DECL_KEYWORD(kw) AddKeyword(#kw, CodeCompletionKeywordKind::kw_##kw);
4869+
#define DECL_KEYWORD(kw) AddKeyword(#kw, CodeCompletionKeywordKind::kw_##kw, None);
48654870
#include "swift/Syntax/TokenKinds.def"
48664871

48674872
// Context-sensitive keywords.
4868-
auto AddCSKeyword = [&](StringRef Name) {
4869-
AddKeyword(Name, CodeCompletionKeywordKind::None);
4873+
auto AddCSKeyword = [&](StringRef Name, DeclAttrKind Kind) {
4874+
AddKeyword(Name, CodeCompletionKeywordKind::None, Kind);
48704875
};
48714876

4872-
#define CONTEXTUAL_CASE(KW) AddCSKeyword(#KW);
4873-
#define CONTEXTUAL_DECL_ATTR(KW, ...) CONTEXTUAL_CASE(KW)
4874-
#define CONTEXTUAL_DECL_ATTR_ALIAS(KW, ...) CONTEXTUAL_CASE(KW)
4875-
#define CONTEXTUAL_SIMPLE_DECL_ATTR(KW, ...) CONTEXTUAL_CASE(KW)
4877+
#define CONTEXTUAL_CASE(KW, CLASS) AddCSKeyword(#KW, DAK_##CLASS);
4878+
#define CONTEXTUAL_DECL_ATTR(KW, CLASS, ...) CONTEXTUAL_CASE(KW, CLASS)
4879+
#define CONTEXTUAL_DECL_ATTR_ALIAS(KW, CLASS) CONTEXTUAL_CASE(KW, CLASS)
4880+
#define CONTEXTUAL_SIMPLE_DECL_ATTR(KW, CLASS, ...) CONTEXTUAL_CASE(KW, CLASS)
48764881
#include <swift/AST/Attr.def>
48774882
#undef CONTEXTUAL_CASE
48784883

test/SourceKit/CodeComplete/complete_override.swift.response

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
{
22
key.results: [
3-
{
4-
key.kind: source.lang.swift.keyword,
5-
key.name: "__consuming",
6-
key.sourcetext: "__consuming",
7-
key.description: "__consuming",
8-
key.typename: "",
9-
key.context: source.codecompletion.context.none,
10-
key.num_bytes_to_erase: 0
11-
},
123
{
134
key.kind: source.lang.swift.keyword,
145
key.name: "associatedtype",

0 commit comments

Comments
 (0)