@@ -4869,8 +4869,20 @@ static bool isClangSubModule(ModuleDecl *TheModule) {
4869
4869
return false ;
4870
4870
}
4871
4871
4872
+ static void addKeyword (CodeCompletionResultSink &Sink, StringRef Name,
4873
+ CodeCompletionKeywordKind Kind,
4874
+ StringRef TypeAnnotation = " " ) {
4875
+ CodeCompletionResultBuilder Builder (
4876
+ Sink, CodeCompletionResult::ResultKind::Keyword,
4877
+ SemanticContextKind::None, {});
4878
+ Builder.setKeywordKind (Kind);
4879
+ Builder.addTextChunk (Name);
4880
+ if (!TypeAnnotation.empty ())
4881
+ Builder.addTypeAnnotation (TypeAnnotation);
4882
+ }
4883
+
4872
4884
static void addDeclKeywords (CodeCompletionResultSink &Sink) {
4873
- auto AddKeyword = [&](StringRef Name, CodeCompletionKeywordKind Kind,
4885
+ auto AddDeclKeyword = [&](StringRef Name, CodeCompletionKeywordKind Kind,
4874
4886
Optional<DeclAttrKind> DAK) {
4875
4887
if (Name == " let" || Name == " var" ) {
4876
4888
// Treat keywords that could be the start of a pattern specially.
@@ -4880,19 +4892,15 @@ static void addDeclKeywords(CodeCompletionResultSink &Sink) {
4880
4892
// Remove user inaccessible keywords.
4881
4893
if (DAK.hasValue () && DeclAttribute::isUserInaccessible (*DAK)) return ;
4882
4894
4883
- CodeCompletionResultBuilder Builder (
4884
- Sink, CodeCompletionResult::ResultKind::Keyword,
4885
- SemanticContextKind::None, {});
4886
- Builder.setKeywordKind (Kind);
4887
- Builder.addTextChunk (Name);
4895
+ addKeyword (Sink, Name, Kind);
4888
4896
};
4889
4897
4890
- #define DECL_KEYWORD (kw ) AddKeyword (#kw, CodeCompletionKeywordKind::kw_##kw, None);
4898
+ #define DECL_KEYWORD (kw ) AddDeclKeyword (#kw, CodeCompletionKeywordKind::kw_##kw, None);
4891
4899
#include " swift/Syntax/TokenKinds.def"
4892
4900
4893
4901
// Context-sensitive keywords.
4894
4902
auto AddCSKeyword = [&](StringRef Name, DeclAttrKind Kind) {
4895
- AddKeyword (Name, CodeCompletionKeywordKind::None, Kind);
4903
+ AddDeclKeyword (Name, CodeCompletionKeywordKind::None, Kind);
4896
4904
};
4897
4905
4898
4906
#define CONTEXTUAL_CASE (KW, CLASS ) AddCSKeyword(#KW, DAK_##CLASS);
@@ -4905,68 +4913,40 @@ static void addDeclKeywords(CodeCompletionResultSink &Sink) {
4905
4913
}
4906
4914
4907
4915
static void addStmtKeywords (CodeCompletionResultSink &Sink, bool MaybeFuncBody) {
4908
- auto AddKeyword = [&](StringRef Name, CodeCompletionKeywordKind Kind) {
4916
+ auto AddStmtKeyword = [&](StringRef Name, CodeCompletionKeywordKind Kind) {
4909
4917
if (!MaybeFuncBody && Kind == CodeCompletionKeywordKind::kw_return)
4910
4918
return ;
4911
-
4912
- CodeCompletionResultBuilder Builder (
4913
- Sink, CodeCompletionResult::ResultKind::Keyword,
4914
- SemanticContextKind::None, {});
4915
- Builder.setKeywordKind (Kind);
4916
- Builder.addTextChunk (Name);
4919
+ addKeyword (Sink, Name, Kind);
4917
4920
};
4918
- #define STMT_KEYWORD (kw ) AddKeyword (#kw, CodeCompletionKeywordKind::kw_##kw);
4921
+ #define STMT_KEYWORD (kw ) AddStmtKeyword (#kw, CodeCompletionKeywordKind::kw_##kw);
4919
4922
#include " swift/Syntax/TokenKinds.def"
4920
4923
4921
4924
// Throw is not marked as a STMT_KEYWORD.
4922
- AddKeyword (" throw" , CodeCompletionKeywordKind::kw_throw);
4925
+ AddStmtKeyword (" throw" , CodeCompletionKeywordKind::kw_throw);
4923
4926
}
4924
4927
4925
4928
static void addLetVarKeywords (CodeCompletionResultSink &Sink) {
4926
- auto AddKeyword = [&](StringRef Name, CodeCompletionKeywordKind Kind) {
4927
- CodeCompletionResultBuilder Builder (
4928
- Sink, CodeCompletionResult::ResultKind::Keyword,
4929
- SemanticContextKind::None, {});
4930
- Builder.setKeywordKind (Kind);
4931
- Builder.addTextChunk (Name);
4932
- };
4933
-
4934
- AddKeyword (" let" , CodeCompletionKeywordKind::kw_let);
4935
- AddKeyword (" var" , CodeCompletionKeywordKind::kw_var);
4929
+ addKeyword (Sink, " let" , CodeCompletionKeywordKind::kw_let);
4930
+ addKeyword (Sink, " var" , CodeCompletionKeywordKind::kw_var);
4936
4931
}
4937
4932
4938
4933
static void addExprKeywords (CodeCompletionResultSink &Sink) {
4939
- auto AddKeyword = [&](StringRef Name, StringRef TypeAnnotation, CodeCompletionKeywordKind Kind) {
4940
- CodeCompletionResultBuilder Builder (
4941
- Sink, CodeCompletionResult::ResultKind::Keyword,
4942
- SemanticContextKind::None, {});
4943
- Builder.setKeywordKind (Kind);
4944
- Builder.addTextChunk (Name);
4945
- if (!TypeAnnotation.empty ())
4946
- Builder.addTypeAnnotation (TypeAnnotation);
4947
- };
4948
-
4949
4934
// Expr keywords.
4950
- AddKeyword ( " try" , StringRef () , CodeCompletionKeywordKind::kw_try);
4951
- AddKeyword ( " try!" , StringRef () , CodeCompletionKeywordKind::kw_try);
4952
- AddKeyword ( " try?" , StringRef () , CodeCompletionKeywordKind::kw_try);
4935
+ addKeyword (Sink, " try" , CodeCompletionKeywordKind::kw_try);
4936
+ addKeyword (Sink, " try!" , CodeCompletionKeywordKind::kw_try);
4937
+ addKeyword (Sink, " try?" , CodeCompletionKeywordKind::kw_try);
4953
4938
// FIXME: The pedantically correct way to find the type is to resolve the
4954
4939
// Swift.StringLiteralType type.
4955
- AddKeyword ( " #function" , " String " , CodeCompletionKeywordKind::pound_function);
4956
- AddKeyword ( " #file" , " String " , CodeCompletionKeywordKind::pound_file);
4940
+ addKeyword (Sink, " #function" , CodeCompletionKeywordKind::pound_function, " String " );
4941
+ addKeyword (Sink, " #file" , CodeCompletionKeywordKind::pound_file, " String " );
4957
4942
// Same: Swift.IntegerLiteralType.
4958
- AddKeyword ( " #line" , " Int " , CodeCompletionKeywordKind::pound_line);
4959
- AddKeyword ( " #column" , " Int " , CodeCompletionKeywordKind::pound_column);
4960
- AddKeyword ( " #dsohandle" , " UnsafeMutableRawPointer " , CodeCompletionKeywordKind::pound_dsohandle);
4943
+ addKeyword (Sink, " #line" , CodeCompletionKeywordKind::pound_line, " Int " );
4944
+ addKeyword (Sink, " #column" , CodeCompletionKeywordKind::pound_column, " Int " );
4945
+ addKeyword (Sink, " #dsohandle" , CodeCompletionKeywordKind::pound_dsohandle, " UnsafeMutableRawPointer " );
4961
4946
}
4962
4947
4963
4948
static void addAnyTypeKeyword (CodeCompletionResultSink &Sink) {
4964
- CodeCompletionResultBuilder Builder (
4965
- Sink, CodeCompletionResult::ResultKind::Keyword,
4966
- SemanticContextKind::None, {});
4967
- Builder.setKeywordKind (CodeCompletionKeywordKind::None);
4968
- Builder.addTextChunk (" Any" );
4969
- Builder.addTypeAnnotation (" Any" );
4949
+ addKeyword (Sink, " Any" , CodeCompletionKeywordKind::None, " Any" );
4970
4950
}
4971
4951
4972
4952
0 commit comments