diff options
| author | Quan Zhuo <zhuo.quan@outlook.com> | 2025-11-01 00:26:47 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-31 12:26:47 -0400 |
| commit | 9f28c59d69ab1bb56a4a74dfa144bbbb2d5d14da (patch) | |
| tree | a13cf3038b4e6614e85c09f05c533480f5ea4979 | |
| parent | 2837a4bdd7c48874b8ae874423b0a3d0907bc32b (diff) | |
| download | llvm-9f28c59d69ab1bb56a4a74dfa144bbbb2d5d14da.zip llvm-9f28c59d69ab1bb56a4a74dfa144bbbb2d5d14da.tar.gz llvm-9f28c59d69ab1bb56a4a74dfa144bbbb2d5d14da.tar.bz2 | |
[clang][CodeComplete] Add completion for #embed directive in C23 mode (#165550)
Fixes https://github.com/clangd/clangd/issues/2535
| -rw-r--r-- | clang/lib/Sema/SemaCodeComplete.cpp | 18 | ||||
| -rw-r--r-- | clang/test/Index/complete-preprocessor.m | 5 |
2 files changed, 23 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index 0514d10..aa93507 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -10208,6 +10208,24 @@ void SemaCodeCompletion::CodeCompletePreprocessorDirective(bool InConditional) { Builder.AddPlaceholderChunk("message"); Results.AddResult(Builder.TakeString()); + if (getLangOpts().C23) { + // #embed "file" + Builder.AddTypedTextChunk("embed"); + Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); + Builder.AddTextChunk("\""); + Builder.AddPlaceholderChunk("file"); + Builder.AddTextChunk("\""); + Results.AddResult(Builder.TakeString()); + + // #embed <file> + Builder.AddTypedTextChunk("embed"); + Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); + Builder.AddTextChunk("<"); + Builder.AddPlaceholderChunk("file"); + Builder.AddTextChunk(">"); + Results.AddResult(Builder.TakeString()); + } + // Note: #ident and #sccs are such crazy anachronisms that we don't provide // completions for them. And __include_macros is a Clang-internal extension // that we don't want to encourage anyone to use. diff --git a/clang/test/Index/complete-preprocessor.m b/clang/test/Index/complete-preprocessor.m index 1cc2f32b..bd90a79 100644 --- a/clang/test/Index/complete-preprocessor.m +++ b/clang/test/Index/complete-preprocessor.m @@ -80,3 +80,8 @@ FOO(in,t) value; // RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test -code-completion-at=%s:9:8 %s | FileCheck -check-prefix=CHECK-CC3 %s // RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test -code-completion-at=%s:11:5 %s | FileCheck -check-prefix=CHECK-CC4 %s // RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test -code-completion-at=%s:14:5 %s | FileCheck -check-prefix=CHECK-CC5 %s + +// Test #embed completion in C23 mode +// RUN: c-index-test -code-completion-at=%s:4:2 %s -std=c23 | FileCheck -check-prefix=CHECK-EMBED %s +// CHECK-EMBED: NotImplemented:{TypedText embed}{HorizontalSpace }{Text "}{Placeholder file}{Text "} (40) +// CHECK-EMBED: NotImplemented:{TypedText embed}{HorizontalSpace }{Text <}{Placeholder file}{Text >} (40) |
