-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Add code completion for C++20 keywords. #107982
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
Changes from 12 commits
fedea9e
36a0db2
9a1a85c
326892a
c8e555f
0375e52
d9c6413
3764782
08dc216
585bc0a
e802aec
2d7f476
d489327
5cc6a8f
74b7c74
687ab4c
cc758c5
15f6982
b6218b6
75bb471
68cd292
cf991be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1836,6 +1836,10 @@ static void AddTypeSpecifierResults(const LangOptions &LangOpts, | |
| Builder.AddChunk(CodeCompletionString::CK_RightParen); | ||
| Results.AddResult(Result(Builder.TakeString())); | ||
| } | ||
|
|
||
| if (LangOpts.Char8 || LangOpts.CPlusPlus20) { | ||
| Results.AddResult(Result("char8_t", CCP_Type)); | ||
| } | ||
| } else | ||
| Results.AddResult(Result("__auto_type", CCP_Type)); | ||
|
|
||
|
|
@@ -1888,6 +1892,10 @@ AddStorageSpecifiers(SemaCodeCompletion::ParserCompletionContext CCC, | |
| Results.AddResult(Result("constexpr")); | ||
| Results.AddResult(Result("thread_local")); | ||
| } | ||
|
|
||
| if (LangOpts.CPlusPlus20) { | ||
| Results.AddResult(Result("constinit")); | ||
| } | ||
16bit-ykiko marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| static void | ||
|
|
@@ -1911,6 +1919,9 @@ AddFunctionSpecifiers(SemaCodeCompletion::ParserCompletionContext CCC, | |
| case SemaCodeCompletion::PCC_Template: | ||
| if (LangOpts.CPlusPlus || LangOpts.C99) | ||
| Results.AddResult(Result("inline")); | ||
|
|
||
| if (LangOpts.CPlusPlus20) | ||
| Results.AddResult(Result("consteval")); | ||
| break; | ||
|
|
||
| case SemaCodeCompletion::PCC_ObjCInstanceVariableList: | ||
|
|
@@ -2186,6 +2197,45 @@ AddOrdinaryNameResults(SemaCodeCompletion::ParserCompletionContext CCC, | |
| } else { | ||
| Results.AddResult(Result("template", CodeCompletionResult::RK_Keyword)); | ||
| } | ||
|
|
||
| if (SemaRef.getLangOpts().CPlusPlus20 && | ||
| SemaRef.getLangOpts().CPlusPlusModules) { | ||
| // export | ||
| Results.AddResult(Result("export", CodeCompletionResult::RK_Keyword)); | ||
|
|
||
| if (SemaRef.CurContext->isTranslationUnit()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we restrict that using
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we can't do it here. Since we don't the kind of the current module before we see module declarations.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, exactly.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I push a new commit and try to make completion for module related keywords more context-sensitive. And found something strange: https://godbolt.org/z/YM9dhEKKe module;
export module M;
^If I try to run code completion at The error shouldn't occur, right?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It only happens during completion so there is probably a bug with that https://godbolt.org/z/7M8EPodoP
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made some modification to |
||
| // module; | ||
| Builder.AddTypedTextChunk("module"); | ||
| Builder.AddChunk(CodeCompletionString::CK_SemiColon); | ||
| Builder.AddChunk(CodeCompletionString::CK_VerticalSpace); | ||
| Results.AddResult(Result(Builder.TakeString())); | ||
|
|
||
| // module: private; | ||
| Builder.AddTypedTextChunk("module"); | ||
| Builder.AddChunk(CodeCompletionString::CK_Colon); | ||
| Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); | ||
| Builder.AddTypedTextChunk("private"); | ||
| Builder.AddChunk(CodeCompletionString::CK_SemiColon); | ||
| Builder.AddChunk(CodeCompletionString::CK_VerticalSpace); | ||
| Results.AddResult(Result(Builder.TakeString())); | ||
|
|
||
| // module name; | ||
| Builder.AddTypedTextChunk("module"); | ||
| Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); | ||
| Builder.AddPlaceholderChunk("name"); | ||
| Builder.AddChunk(CodeCompletionString::CK_SemiColon); | ||
| Builder.AddChunk(CodeCompletionString::CK_VerticalSpace); | ||
| Results.AddResult(Result(Builder.TakeString())); | ||
|
|
||
| // import module; | ||
| Builder.AddTypedTextChunk("import"); | ||
| Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); | ||
| Builder.AddPlaceholderChunk("module"); | ||
| Builder.AddChunk(CodeCompletionString::CK_SemiColon); | ||
| Builder.AddChunk(CodeCompletionString::CK_VerticalSpace); | ||
| Results.AddResult(Result(Builder.TakeString())); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (SemaRef.getLangOpts().ObjC) | ||
|
|
@@ -2253,6 +2303,11 @@ AddOrdinaryNameResults(SemaCodeCompletion::ParserCompletionContext CCC, | |
| [[fallthrough]]; | ||
|
|
||
| case SemaCodeCompletion::PCC_Template: | ||
| if (SemaRef.getLangOpts().CPlusPlus20 && | ||
| CCC == SemaCodeCompletion::PCC_Template) | ||
| Results.AddResult(Result("concept", CCP_Keyword)); | ||
| [[fallthrough]]; | ||
|
|
||
| case SemaCodeCompletion::PCC_MemberTemplate: | ||
| if (SemaRef.getLangOpts().CPlusPlus && Results.includeCodePatterns()) { | ||
| // template < parameters > | ||
|
|
@@ -2265,6 +2320,12 @@ AddOrdinaryNameResults(SemaCodeCompletion::ParserCompletionContext CCC, | |
| Results.AddResult(Result("template", CodeCompletionResult::RK_Keyword)); | ||
| } | ||
|
|
||
| if (SemaRef.getLangOpts().CPlusPlus20 && | ||
| (CCC == SemaCodeCompletion::PCC_Template || | ||
| CCC == SemaCodeCompletion::PCC_MemberTemplate)) { | ||
| Results.AddResult(Result("requires", CCP_Keyword)); | ||
| } | ||
16bit-ykiko marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| AddStorageSpecifiers(CCC, SemaRef.getLangOpts(), Results); | ||
| AddFunctionSpecifiers(CCC, SemaRef.getLangOpts(), Results); | ||
| break; | ||
|
|
@@ -2486,6 +2547,14 @@ AddOrdinaryNameResults(SemaCodeCompletion::ParserCompletionContext CCC, | |
| Builder.AddPlaceholderChunk("expression"); | ||
| Builder.AddChunk(CodeCompletionString::CK_SemiColon); | ||
| Results.AddResult(Result(Builder.TakeString())); | ||
| // "co_return expression ;" for coroutines(C++20). | ||
| if (SemaRef.getLangOpts().CPlusPlus20) { | ||
| Builder.AddTypedTextChunk("co_return"); | ||
| Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); | ||
| Builder.AddPlaceholderChunk("expression"); | ||
| Builder.AddChunk(CodeCompletionString::CK_SemiColon); | ||
| Results.AddResult(Result(Builder.TakeString())); | ||
| } | ||
| // When boolean, also add 'return true;' and 'return false;'. | ||
| if (ReturnType->isBooleanType()) { | ||
| Builder.AddTypedTextChunk("return true"); | ||
|
|
@@ -2706,6 +2775,44 @@ AddOrdinaryNameResults(SemaCodeCompletion::ParserCompletionContext CCC, | |
| Builder.AddChunk(CodeCompletionString::CK_RightParen); | ||
| Results.AddResult(Result(Builder.TakeString())); | ||
| } | ||
|
|
||
| if (SemaRef.getLangOpts().CPlusPlus20) { | ||
| // co_await expression | ||
| Builder.AddTypedTextChunk("co_await"); | ||
| Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); | ||
| Builder.AddPlaceholderChunk("expression"); | ||
| Results.AddResult(Result(Builder.TakeString())); | ||
|
|
||
| // co_yield expression | ||
| Builder.AddTypedTextChunk("co_yield"); | ||
| Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); | ||
| Builder.AddPlaceholderChunk("expression"); | ||
| Results.AddResult(Result(Builder.TakeString())); | ||
|
|
||
| // requires (parameters) { requirements } | ||
| Builder.AddResultTypeChunk("bool"); | ||
| Builder.AddTypedTextChunk("requires"); | ||
| Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); | ||
| Builder.AddChunk(CodeCompletionString::CK_LeftParen); | ||
| Builder.AddPlaceholderChunk("parameters"); | ||
| Builder.AddChunk(CodeCompletionString::CK_RightParen); | ||
| Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); | ||
| Builder.AddChunk(CodeCompletionString::CK_LeftBrace); | ||
| Builder.AddChunk(CodeCompletionString::CK_VerticalSpace); | ||
| Builder.AddPlaceholderChunk("requirements"); | ||
| Builder.AddChunk(CodeCompletionString::CK_VerticalSpace); | ||
| Builder.AddChunk(CodeCompletionString::CK_RightBrace); | ||
| Results.AddResult(Result(Builder.TakeString())); | ||
|
|
||
| if (SemaRef.CurContext->isRequiresExprBody()) { | ||
| // requires expression ; | ||
| Builder.AddTypedTextChunk("requires"); | ||
| Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); | ||
| Builder.AddPlaceholderChunk("expression"); | ||
| Builder.AddChunk(CodeCompletionString::CK_SemiColon); | ||
| Results.AddResult(Result(Builder.TakeString())); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (SemaRef.getLangOpts().ObjC) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| const char8_t x = 1; | ||
|
|
||
| template<typename T> requires true | ||
| const int y = requires { typename T::type; requires T::value; }; | ||
|
|
||
| int f(){ co_await 1; } | ||
|
|
||
| // RUN: %clang_cc1 -std=c++20 -code-completion-at=%s:1:3 %s | FileCheck --check-prefix=CHECK-TOP-LEVEL %s | ||
| // CHECK-TOP-LEVEL: const | ||
| // CHECK-TOP-LEVEL: consteval | ||
| // CHECK-TOP-LEVEL: constexpr | ||
| // CHECK-TOP-LEVEL: constinit | ||
|
|
||
| // RUN: %clang_cc1 -std=c++20 -code-completion-at=%s:1:12 %s | FileCheck --check-prefix=CHECK-TOP-LEVEL %s | ||
| // CHECK-TOP-LEVEL: char8_t | ||
|
|
||
| // RUN: %clang-cc1 -std=c++20 -code-completion-at=%s:4:3 %s | FileCheck --check-prefix=CHECK-REQUIRES %s | ||
| // CHECK-REQUIRES: concept | ||
| // CHECK-REQUIRES: const | ||
| // CHECK-REQUIRES: consteval | ||
| // CHECK-REQUIRES: constexpr | ||
| // CHECK-REQUIRES: constinit | ||
|
|
||
| // RUN: %clang-cc1 -std=c++20 -code-completion-at=%s:3:27 %s | FileCheck --check-prefix=CHECK-REQUIRES %s | ||
| // CHECK-REQUIRES: requires | ||
|
|
||
| // RUN: %clang-cc1 -std=c++20 -code-completion-at=%s:4:20 %s | FileCheck -check-prefix=CHECK-CC1 %s | ||
| // CHECK-CC1-NEXT: COMPLETION: Pattern: [#bool#]requires (<#parameters#>) { | ||
| // CHECK-CC1-NEXT: <#requirements#> | ||
| // CHECK-CC1-NEXT: } | ||
|
|
||
| // RUN: %clang-cc1 -std=c++20 -code-completion-at=%s:6:13 %s | FileCheck --check-prefix=CHECK-COAWAIT %s | ||
| // CHECK-COAWAIT: Pattern : co_await <#expression#> | ||
| // CHECK-COAWAIT: Pattern : co_return <#expression#>; | ||
| // CHECK-COAWAIT: Pattern : co_yield <#expression#> |
Uh oh!
There was an error while loading. Please reload this page.