@@ -4770,8 +4770,20 @@ static bool isClangSubModule(ModuleDecl *TheModule) {
4770
4770
return false ;
4771
4771
}
4772
4772
4773
+ static void addKeyword (CodeCompletionResultSink &Sink, StringRef Name,
4774
+ CodeCompletionKeywordKind Kind,
4775
+ StringRef TypeAnnotation = " " ) {
4776
+ CodeCompletionResultBuilder Builder (
4777
+ Sink, CodeCompletionResult::ResultKind::Keyword,
4778
+ SemanticContextKind::None, {});
4779
+ Builder.setKeywordKind (Kind);
4780
+ Builder.addTextChunk (Name);
4781
+ if (!TypeAnnotation.empty ())
4782
+ Builder.addTypeAnnotation (TypeAnnotation);
4783
+ }
4784
+
4773
4785
static void addDeclKeywords (CodeCompletionResultSink &Sink) {
4774
- auto AddKeyword = [&](StringRef Name, CodeCompletionKeywordKind Kind,
4786
+ auto AddDeclKeyword = [&](StringRef Name, CodeCompletionKeywordKind Kind,
4775
4787
Optional<DeclAttrKind> DAK) {
4776
4788
if (Name == " let" || Name == " var" ) {
4777
4789
// Treat keywords that could be the start of a pattern specially.
@@ -4781,19 +4793,15 @@ static void addDeclKeywords(CodeCompletionResultSink &Sink) {
4781
4793
// Remove user inaccessible keywords.
4782
4794
if (DAK.hasValue () && DeclAttribute::isUserInaccessible (*DAK)) return ;
4783
4795
4784
- CodeCompletionResultBuilder Builder (
4785
- Sink, CodeCompletionResult::ResultKind::Keyword,
4786
- SemanticContextKind::None, {});
4787
- Builder.setKeywordKind (Kind);
4788
- Builder.addTextChunk (Name);
4796
+ addKeyword (Sink, Name, Kind);
4789
4797
};
4790
4798
4791
- #define DECL_KEYWORD (kw ) AddKeyword (#kw, CodeCompletionKeywordKind::kw_##kw, None);
4799
+ #define DECL_KEYWORD (kw ) AddDeclKeyword (#kw, CodeCompletionKeywordKind::kw_##kw, None);
4792
4800
#include " swift/Syntax/TokenKinds.def"
4793
4801
4794
4802
// Context-sensitive keywords.
4795
4803
auto AddCSKeyword = [&](StringRef Name, DeclAttrKind Kind) {
4796
- AddKeyword (Name, CodeCompletionKeywordKind::None, Kind);
4804
+ AddDeclKeyword (Name, CodeCompletionKeywordKind::None, Kind);
4797
4805
};
4798
4806
4799
4807
#define CONTEXTUAL_CASE (KW, CLASS ) AddCSKeyword(#KW, DAK_##CLASS);
@@ -4806,65 +4814,37 @@ static void addDeclKeywords(CodeCompletionResultSink &Sink) {
4806
4814
}
4807
4815
4808
4816
static void addStmtKeywords (CodeCompletionResultSink &Sink, bool MaybeFuncBody) {
4809
- auto AddKeyword = [&](StringRef Name, CodeCompletionKeywordKind Kind) {
4817
+ auto AddStmtKeyword = [&](StringRef Name, CodeCompletionKeywordKind Kind) {
4810
4818
if (!MaybeFuncBody && Kind == CodeCompletionKeywordKind::kw_return)
4811
4819
return ;
4812
-
4813
- CodeCompletionResultBuilder Builder (
4814
- Sink, CodeCompletionResult::ResultKind::Keyword,
4815
- SemanticContextKind::None, {});
4816
- Builder.setKeywordKind (Kind);
4817
- Builder.addTextChunk (Name);
4820
+ addKeyword (Sink, Name, Kind);
4818
4821
};
4819
- #define STMT_KEYWORD (kw ) AddKeyword (#kw, CodeCompletionKeywordKind::kw_##kw);
4822
+ #define STMT_KEYWORD (kw ) AddStmtKeyword (#kw, CodeCompletionKeywordKind::kw_##kw);
4820
4823
#include " swift/Syntax/TokenKinds.def"
4821
4824
}
4822
4825
4823
4826
static void addLetVarKeywords (CodeCompletionResultSink &Sink) {
4824
- auto AddKeyword = [&](StringRef Name, CodeCompletionKeywordKind Kind) {
4825
- CodeCompletionResultBuilder Builder (
4826
- Sink, CodeCompletionResult::ResultKind::Keyword,
4827
- SemanticContextKind::None, {});
4828
- Builder.setKeywordKind (Kind);
4829
- Builder.addTextChunk (Name);
4830
- };
4831
-
4832
- AddKeyword (" let" , CodeCompletionKeywordKind::kw_let);
4833
- AddKeyword (" var" , CodeCompletionKeywordKind::kw_var);
4827
+ addKeyword (Sink, " let" , CodeCompletionKeywordKind::kw_let);
4828
+ addKeyword (Sink, " var" , CodeCompletionKeywordKind::kw_var);
4834
4829
}
4835
4830
4836
4831
static void addExprKeywords (CodeCompletionResultSink &Sink) {
4837
- auto AddKeyword = [&](StringRef Name, StringRef TypeAnnotation, CodeCompletionKeywordKind Kind) {
4838
- CodeCompletionResultBuilder Builder (
4839
- Sink, CodeCompletionResult::ResultKind::Keyword,
4840
- SemanticContextKind::None, {});
4841
- Builder.setKeywordKind (Kind);
4842
- Builder.addTextChunk (Name);
4843
- if (!TypeAnnotation.empty ())
4844
- Builder.addTypeAnnotation (TypeAnnotation);
4845
- };
4846
-
4847
4832
// Expr keywords.
4848
- AddKeyword ( " try" , StringRef () , CodeCompletionKeywordKind::kw_try);
4849
- AddKeyword ( " try!" , StringRef () , CodeCompletionKeywordKind::kw_try);
4850
- AddKeyword ( " try?" , StringRef () , CodeCompletionKeywordKind::kw_try);
4833
+ addKeyword (Sink, " try" , CodeCompletionKeywordKind::kw_try);
4834
+ addKeyword (Sink, " try!" , CodeCompletionKeywordKind::kw_try);
4835
+ addKeyword (Sink, " try?" , CodeCompletionKeywordKind::kw_try);
4851
4836
// FIXME: The pedantically correct way to find the type is to resolve the
4852
4837
// Swift.StringLiteralType type.
4853
- AddKeyword ( " #function" , " String " , CodeCompletionKeywordKind::pound_function);
4854
- AddKeyword ( " #file" , " String " , CodeCompletionKeywordKind::pound_file);
4838
+ addKeyword (Sink, " #function" , CodeCompletionKeywordKind::pound_function, " String " );
4839
+ addKeyword (Sink, " #file" , CodeCompletionKeywordKind::pound_file, " String " );
4855
4840
// Same: Swift.IntegerLiteralType.
4856
- AddKeyword ( " #line" , " Int " , CodeCompletionKeywordKind::pound_line);
4857
- AddKeyword ( " #column" , " Int " , CodeCompletionKeywordKind::pound_column);
4858
- AddKeyword ( " #dsohandle" , " UnsafeMutableRawPointer " , CodeCompletionKeywordKind::pound_dsohandle);
4841
+ addKeyword (Sink, " #line" , CodeCompletionKeywordKind::pound_line, " Int " );
4842
+ addKeyword (Sink, " #column" , CodeCompletionKeywordKind::pound_column, " Int " );
4843
+ addKeyword (Sink, " #dsohandle" , CodeCompletionKeywordKind::pound_dsohandle, " UnsafeMutableRawPointer " );
4859
4844
}
4860
4845
4861
4846
static void addAnyTypeKeyword (CodeCompletionResultSink &Sink) {
4862
- CodeCompletionResultBuilder Builder (
4863
- Sink, CodeCompletionResult::ResultKind::Keyword,
4864
- SemanticContextKind::None, {});
4865
- Builder.setKeywordKind (CodeCompletionKeywordKind::None);
4866
- Builder.addTextChunk (" Any" );
4867
- Builder.addTypeAnnotation (" Any" );
4847
+ addKeyword (Sink, " Any" , CodeCompletionKeywordKind::None, " Any" );
4868
4848
}
4869
4849
4870
4850
0 commit comments