Skip to content

[5.7][CodeCompletion] Suggest 'actor' decl introducer keyword #58873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,6 @@ static void addDeclKeywords(CodeCompletionResultSink &Sink, DeclContext *DC,
case CodeCompletionKeywordKind::kw_enum:
case CodeCompletionKeywordKind::kw_extension:
return true;
case CodeCompletionKeywordKind::None:
if (DAK && *DAK == DeclAttrKind::DAK_Actor) {
return true;
}
break;
default:
break;
}
Expand Down Expand Up @@ -782,12 +777,20 @@ static void addDeclKeywords(CodeCompletionResultSink &Sink, DeclContext *DC,
DeclAttribute::isConcurrencyOnly(*DAK))
return;

addKeyword(Sink, Name, Kind, /*TypeAnnotation=*/"", getFlair(Kind, DAK));
CodeCompletionFlair flair = getFlair(Kind, DAK);

// Special case for 'actor'. Get the same flair with 'kw_class'.
if (Kind == CodeCompletionKeywordKind::None && Name == "actor")
flair = getFlair(CodeCompletionKeywordKind::kw_class, None);

addKeyword(Sink, Name, Kind, /*TypeAnnotation=*/"", flair);
};

#define DECL_KEYWORD(kw) \
AddDeclKeyword(#kw, CodeCompletionKeywordKind::kw_##kw, None);
#include "swift/Syntax/TokenKinds.def"
// Manually add "actor" because it's a contextual keyword.
AddDeclKeyword("actor", CodeCompletionKeywordKind::None, None);

// Context-sensitive keywords.
auto AddCSKeyword = [&](StringRef Name, DeclAttrKind Kind) {
Expand Down
4 changes: 4 additions & 0 deletions test/IDE/complete_keywords.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

// KW_DECL: Begin completions
// KW_DECL-DAG: Keyword[class]/None: class{{; name=.+$}}
// KW_DECL-DAG: Keyword/None: actor{{; name=.+$}}
// KW_DECL-DAG: Keyword/None: convenience{{; name=.+$}}
// KW_DECL-DAG: Keyword[deinit]/None: deinit{{; name=.+$}}
// KW_DECL-DAG: Keyword/None: dynamic{{; name=.+$}}
Expand Down Expand Up @@ -42,6 +43,7 @@

// KW_DECL_PROTOCOL: Begin completions
// KW_DECL_PROTOCOL-DAG: Keyword[class]/None/Flair[RareKeyword]: class{{; name=.+$}}
// KW_DECL_PROTOCOL-DAG: Keyword/None/Flair[RareKeyword]: actor{{; name=.+$}}
// KW_DECL_PROTOCOL-DAG: Keyword/None: convenience{{; name=.+$}}
// KW_DECL_PROTOCOL-DAG: Keyword[deinit]/None: deinit{{; name=.+$}}
// KW_DECL_PROTOCOL-DAG: Keyword/None: dynamic{{; name=.+$}}
Expand Down Expand Up @@ -78,6 +80,7 @@

// KW_DECL_TYPECONTEXT: Begin completions
// KW_DECL_TYPECONTEXT-DAG: Keyword[class]/None: class{{; name=.+$}}
// KW_DECL_TYPECONTEXT-DAG: Keyword/None: actor{{; name=.+$}}
// KW_DECL_TYPECONTEXT-DAG: Keyword/None: convenience{{; name=.+$}}
// KW_DECL_TYPECONTEXT-DAG: Keyword[deinit]/None: deinit{{; name=.+$}}
// KW_DECL_TYPECONTEXT-DAG: Keyword/None: dynamic{{; name=.+$}}
Expand Down Expand Up @@ -118,6 +121,7 @@
// Declaration keywords.
//
// KW_DECL_STMT_TOPLEVEL-DAG: Keyword[class]/None: class{{; name=.+$}}
// KW_DECL_STMT_TOPLEVEL-DAG: Keyword/None: actor{{; name=.+$}}
// KW_DECL_STMT_TOPLEVEL-DAG: Keyword/None: convenience{{; name=.+$}}
// KW_DECL_STMT_TOPLEVEL-DAG: Keyword[deinit]/None: deinit{{; name=.+$}}
// KW_DECL_STMT_TOPLEVEL-DAG: Keyword/None: dynamic{{; name=.+$}}
Expand Down
10 changes: 10 additions & 0 deletions test/SourceKit/CodeComplete/complete_override.swift.response
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
key.typerelation: source.codecompletion.typerelation.notapplicable,
key.num_bytes_to_erase: 0
},
{
key.kind: source.lang.swift.keyword,
key.name: "actor",
key.sourcetext: "actor",
key.description: "actor",
key.typename: "",
key.context: source.codecompletion.context.none,
key.typerelation: source.codecompletion.typerelation.notapplicable,
key.num_bytes_to_erase: 0
},
{
key.kind: source.lang.swift.keyword,
key.name: "associatedtype",
Expand Down