-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][CodeComplete] Add code completion for if constexpr and consteval #124315
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
HighCommander4
merged 16 commits into
llvm:main
from
FantasqueX:code-complete-if-constexpr
Mar 17, 2025
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e3f118c
[Sema] Add code completion for if constexpr
FantasqueX 5b3a919
Add test for if constexpr completion
FantasqueX 4e0d4a7
rename function
FantasqueX 932ab1e
use CCC_Other instead
FantasqueX 2955dc9
Add consteval
FantasqueX 2319614
support code snippet completion
FantasqueX bdec8c2
format code
FantasqueX 19f5516
Add if not test
FantasqueX d1abbf2
format code
FantasqueX e308919
Add pattern tests
FantasqueX f49496e
remove unused argument
FantasqueX f67da43
add more tests
FantasqueX ecbd115
rename code complete method
FantasqueX bb62505
move code complete in else block
FantasqueX 490554f
remove a new scope
FantasqueX 89c4ae7
format code
FantasqueX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
template <bool Flag> | ||
void test() { | ||
if constexpr (Flag) { | ||
return; | ||
} | ||
// RUN: %clang_cc1 -fsyntax-only -std=c++17 -code-completion-at=%s:3:7 %s | FileCheck -check-prefix=CHECK-CXX17 %s | ||
// RUN: %clang_cc1 -fsyntax-only -std=c++17 -code-completion-patterns -code-completion-at=%s:3:7 %s | FileCheck -check-prefix=CHECK-PATTERN-CXX17 %s | ||
// RUN: %clang_cc1 -fsyntax-only -std=c++23 -code-completion-at=%s:3:7 %s | FileCheck -check-prefix=CHECK-CXX23 %s | ||
// RUN: %clang_cc1 -fsyntax-only -std=c++23 -code-completion-patterns -code-completion-at=%s:3:7 %s | FileCheck -check-prefix=CHECK-PATTERN-CXX23 %s | ||
// CHECK-CXX17: COMPLETION: constexpr | ||
// CHECK-PATTERN-CXX17: COMPLETION: Pattern : constexpr (<#condition#>) { | ||
// CHECK-PATTERN-CXX17: <#statements#> | ||
// CHECK-PATTERN-CXX17: } | ||
// CHECK-CXX23: COMPLETION: consteval | ||
FantasqueX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// CHECK-CXX23: COMPLETION: constexpr | ||
// CHECK-PATTERN-CXX23: COMPLETION: Pattern : consteval { | ||
// CHECK-PATTERN-CXX23: <#statements#> | ||
// CHECK-PATTERN-CXX23: } | ||
FantasqueX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// CHECK-PATTERN-CXX23: COMPLETION: Pattern : constexpr (<#condition#>) { | ||
// CHECK-PATTERN-CXX23: <#statements#> | ||
// CHECK-PATTERN-CXX23: } | ||
if !c | ||
// RUN: %clang_cc1 -fsyntax-only -std=c++23 -code-completion-at=%s:22:8 %s -o - | FileCheck -check-prefix=CHECK-CXX23-EXCLAIM %s | ||
// RUN: %clang_cc1 -fsyntax-only -std=c++23 -code-completion-patterns -code-completion-at=%s:22:8 %s -o - | FileCheck -check-prefix=CHECK-PATTERN-CXX23-EXCLAIM %s | ||
// CHECK-CXX23-EXCLAIM: COMPLETION: consteval | ||
// CHECK-CXX23-EXCLAIM-NOT: constexpr | ||
// CHECK-PATTERN-CXX23-EXCLAIM: COMPLETION: Pattern : consteval { | ||
// CHECK-PATTERN-CXX23-EXCLAIM: <#statements#> | ||
// CHECK-PATTERN-CXX23-EXCLAIM: } | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the similar function
CodeCompleteAfterIf
, I thinkmapCodeCompletionContext(SemaRef, PCC_Statement)
would be more appropriate here thanCodeCompletionContext::CCC_Other
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they are different. In
CodeCompleteAfterIf
, it's valid to provide a statement. While in the new addedCodeCompleteKeywordAfterIf
only two keywords are appropriate.