[clang] d18c3c7 - [CodeComplete] Add ranged for loops code pattern.
Nathan James via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 22 15:40:44 PST 2021
Author: Nathan James
Date: 2021-01-22T23:40:35Z
New Revision: d18c3c7b18e9e78145d701c4687682848071ab98
URL: https://github.com/llvm/llvm-project/commit/d18c3c7b18e9e78145d701c4687682848071ab98
DIFF: https://github.com/llvm/llvm-project/commit/d18c3c7b18e9e78145d701c4687682848071ab98.diff
LOG: [CodeComplete] Add ranged for loops code pattern.
Add code pattersn for c++ `range for` loops and objective c `for...in` loops.
Reviewed By: kadircet
Differential Revision: https://reviews.llvm.org/D95131
Added:
Modified:
clang/lib/Sema/SemaCodeComplete.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index 243f68d16462..d77c9e43a9bd 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -2294,6 +2294,29 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Scope *S,
Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddChunk(CodeCompletionString::CK_RightBrace);
Results.AddResult(Result(Builder.TakeString()));
+
+ if (SemaRef.getLangOpts().CPlusPlus11 || SemaRef.getLangOpts().ObjC) {
+ // for ( range_declaration (:|in) range_expression ) { statements }
+ Builder.AddTypedTextChunk("for");
+ Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+ Builder.AddChunk(CodeCompletionString::CK_LeftParen);
+ Builder.AddPlaceholderChunk("range-declaration");
+ Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+ if (SemaRef.getLangOpts().ObjC)
+ Builder.AddTextChunk("in");
+ else
+ Builder.AddChunk(CodeCompletionString::CK_Colon);
+ Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+ Builder.AddPlaceholderChunk("range-expression");
+ Builder.AddChunk(CodeCompletionString::CK_RightParen);
+ Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+ Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
+ Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
+ Builder.AddPlaceholderChunk("statements");
+ Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
+ Builder.AddChunk(CodeCompletionString::CK_RightBrace);
+ Results.AddResult(Result(Builder.TakeString()));
+ }
}
if (S->getContinueParent()) {
More information about the cfe-commits
mailing list